Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[skip publish] Simplify release process #61

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/workflows/job-check-new-version.yml

This file was deleted.

41 changes: 0 additions & 41 deletions .github/workflows/job-publish.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/job-test.yml

This file was deleted.

63 changes: 52 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,62 @@
name: Main

on:
push:
pull_request:
types:
- closed
branches:
- 'main'
- 'beta'
- main

jobs:
unit-test:
uses: ./.github/workflows/job-test.yml
name: Run tests
if: ${{ github.event.pull_request.merged == true }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew

check-new-version:
needs: unit-test
uses: ./.github/workflows/job-check-new-version.yml
- name: Test
run: ./gradlew clean allTests

publish:
needs: check-new-version
if: ${{ needs.check-new-version.outputs.isNewVersion == 'true' }}
uses: ./.github/workflows/job-publish.yml
secrets: inherit
name: Publish
needs: unit-test
if: ${{ github.event.pull_request.merged == true && !contains(github.event.pull_request.title, '[skip publish]') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew

- uses: actions/setup-node@v4
with:
node-version: 14.x

- name: Publish Maven
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshotSuffix
env:
OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
SIGNING_PRIVATE_KEY: ${{ secrets.PGP_PRIVATE_KEY }}
SIGNING_PASSWORD: ${{ secrets.PGP_PASSPHRASE }}

- name: Publish NPMJS
run: ./.github/workflows/scripts/publish-npm-prod.sh
env:
NPMJS_TOKEN: ${{ secrets.DHIS2_BOT_NPM_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/publish_npm_beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish NPM beta

on:
workflow_dispatch

jobs:
publish:
name: Publish NPM beta
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew

- uses: actions/setup-node@v4
with:
node-version: 14.x

- name: Publish NPMJS
run: ./.github/workflows/scripts/publish-npm-beta.sh
env:
NPMJS_TOKEN: ${{ secrets.DHIS2_BOT_NPM_TOKEN }}
43 changes: 41 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
name: Pull request

on: [pull_request]
on:
pull_request

jobs:
unit-test:
uses: ./.github/workflows/job-test.yml
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew

- name: Test
run: ./gradlew clean allTests

publish:
name: Publish
needs: unit-test
if: ${{ !contains(github.event.pull_request.title, '[skip publish]') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew

- name: Publish Maven Snapshot
run: ./gradlew publishToSonatype
env:
OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
8 changes: 0 additions & 8 deletions .github/workflows/scripts/check-new-version.sh

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/scripts/publish-maven.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -x
branch=$(git rev-parse --abbrev-ref HEAD)

if [ "$branch" = "main" ]; then
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
elif [ "$branch" = "beta" ]; then
./gradlew publishToSonatype -PbetaToSnapshot
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshotSuffix
else
./gradlew publishToSonatype
fi
32 changes: 32 additions & 0 deletions .github/workflows/scripts/publish-npm-beta.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
set -x

./gradlew packJsPackage
./gradlew packJsPackage -PuseCommonJs

cd build/packages/js || exit

# Set authentication token for npmjs registry
npm set //registry.npmjs.org/:_authToken="$NPMJS_TOKEN"

# Set 'beta' suffix in the version starting with beta.0
sed -i -e 's/-SNAPSHOT"/-beta.0"/g' package.json

# Try to upload the beta version. If it is not available, increase the beta number and try again.
# Iterate a maximum of MAX_ITERATION times.
n=1
MAX_ITERATIONS=30
while [ $n -le $MAX_ITERATIONS ]; do
if ! output=$(npm publish --tag beta 2>&1); then
if [[ "$output" == *"ERR! code E403"* ]]; then
# This error code is likely to be thrown when the version already exists
# Increase beta version number to try again
npm version prerelease
n=$(( n + 1 ))
else
exit 1
fi
else
# If upload is successful, exit
exit 0
fi
done
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
set -x

branch=$(git rev-parse --abbrev-ref HEAD)

./gradlew packJsPackage
./gradlew packJsPackage -PuseCommonJs

Expand All @@ -10,8 +8,4 @@ cd build/packages/js || exit
# Set authentication token for npmjs registry
npm set //registry.npmjs.org/:_authToken="$NPMJS_TOKEN"

if [ "$branch" = "main" ]; then
npm publish
elif [ "$branch" = "beta" ]; then
npm publish --tag beta
fi
npm publish
57 changes: 0 additions & 57 deletions .nyx.yaml

This file was deleted.

Loading