Skip to content

Commit

Permalink
Merge pull request #137 from dhis2/simplify-publish-workflow
Browse files Browse the repository at this point in the history
[skip publish] Simplify release process
  • Loading branch information
vgarciabnz authored Jun 26, 2024
2 parents c3b7fe4 + a04892a commit 1cbcee2
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 219 deletions.
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.

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

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

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
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.

9 changes: 0 additions & 9 deletions .github/workflows/scripts/publish-maven.sh

This file was deleted.

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" ] || [ "$branch" = "master" ]; 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

0 comments on commit 1cbcee2

Please sign in to comment.