From 4bc923e3aad12137484c419fd73f1a380dea7ce9 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Tue, 25 Jun 2024 11:52:01 +0200 Subject: [PATCH 1/3] Simplify release process --- .github/workflows/job-check-new-version.yml | 28 --------- .github/workflows/job-publish.yml | 41 ------------ .github/workflows/job-test.yml | 19 ------ .github/workflows/main.yml | 62 +++++++++++++++---- .github/workflows/publish_npm_beta.yml | 30 +++++++++ .github/workflows/pull_request.yml | 42 ++++++++++++- .../workflows/scripts/check-new-version.sh | 8 --- .github/workflows/scripts/publish-maven.sh | 6 +- .github/workflows/scripts/publish-npm-beta.sh | 32 ++++++++++ .../{publish-npm.sh => publish-npm-prod.sh} | 8 +-- .nyx.yaml | 57 ----------------- README.md | 30 ++++----- build.gradle.kts | 22 ++----- settings.gradle.kts | 1 - 14 files changed, 177 insertions(+), 209 deletions(-) delete mode 100644 .github/workflows/job-check-new-version.yml delete mode 100644 .github/workflows/job-publish.yml delete mode 100644 .github/workflows/job-test.yml create mode 100644 .github/workflows/publish_npm_beta.yml delete mode 100755 .github/workflows/scripts/check-new-version.sh create mode 100644 .github/workflows/scripts/publish-npm-beta.sh rename .github/workflows/scripts/{publish-npm.sh => publish-npm-prod.sh} (57%) delete mode 100644 .nyx.yaml diff --git a/.github/workflows/job-check-new-version.yml b/.github/workflows/job-check-new-version.yml deleted file mode 100644 index e48e41a..0000000 --- a/.github/workflows/job-check-new-version.yml +++ /dev/null @@ -1,28 +0,0 @@ -on: - workflow_call: - outputs: - isNewVersion: - description: "Indicates if this build generates a new version" - value: ${{ jobs.check-new-version.outputs.isNewVersion }} - -jobs: - check-new-version: - name: Check new version - runs-on: ubuntu-latest - outputs: - isNewVersion: ${{ steps.newVersion.outputs.isNewVersion }} - 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 - - id: newVersion - name: Check new version - run: ./.github/workflows/scripts/check-new-version.sh \ No newline at end of file diff --git a/.github/workflows/job-publish.yml b/.github/workflows/job-publish.yml deleted file mode 100644 index bce2865..0000000 --- a/.github/workflows/job-publish.yml +++ /dev/null @@ -1,41 +0,0 @@ -on: - workflow_call - -jobs: - publish: - name: 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: Create tag and publish Github release - run: ./gradlew :nyxPublish - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Publish Maven - run: ./.github/workflows/scripts/publish-maven.sh - 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.sh - env: - NPMJS_TOKEN: ${{ secrets.DHIS2_BOT_NPM_TOKEN }} diff --git a/.github/workflows/job-test.yml b/.github/workflows/job-test.yml deleted file mode 100644 index 4d6e58a..0000000 --- a/.github/workflows/job-test.yml +++ /dev/null @@ -1,19 +0,0 @@ -on: - workflow_call - -jobs: - unit-test: - 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 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 745cb6a..5ffa0f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,21 +1,61 @@ 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 \ No newline at end of file + name: Publish + 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 }} diff --git a/.github/workflows/publish_npm_beta.yml b/.github/workflows/publish_npm_beta.yml new file mode 100644 index 0000000..ff5e131 --- /dev/null +++ b/.github/workflows/publish_npm_beta.yml @@ -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 }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 424092b..a21ac92 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -1,7 +1,45 @@ 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 + 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 }} diff --git a/.github/workflows/scripts/check-new-version.sh b/.github/workflows/scripts/check-new-version.sh deleted file mode 100755 index 1d80e58..0000000 --- a/.github/workflows/scripts/check-new-version.sh +++ /dev/null @@ -1,8 +0,0 @@ -# Check if new version -./gradlew checkIsNewVersion -q; newVersion=$? - -if [ $newVersion -ne 0 ]; then - echo "isNewVersion=false" >> "$GITHUB_OUTPUT" -else - echo "isNewVersion=true" >> "$GITHUB_OUTPUT" -fi \ No newline at end of file diff --git a/.github/workflows/scripts/publish-maven.sh b/.github/workflows/scripts/publish-maven.sh index aecb3a5..0efa1c7 100755 --- a/.github/workflows/scripts/publish-maven.sh +++ b/.github/workflows/scripts/publish-maven.sh @@ -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 diff --git a/.github/workflows/scripts/publish-npm-beta.sh b/.github/workflows/scripts/publish-npm-beta.sh new file mode 100644 index 0000000..17f62dd --- /dev/null +++ b/.github/workflows/scripts/publish-npm-beta.sh @@ -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 diff --git a/.github/workflows/scripts/publish-npm.sh b/.github/workflows/scripts/publish-npm-prod.sh similarity index 57% rename from .github/workflows/scripts/publish-npm.sh rename to .github/workflows/scripts/publish-npm-prod.sh index cbee095..60d732e 100755 --- a/.github/workflows/scripts/publish-npm.sh +++ b/.github/workflows/scripts/publish-npm-prod.sh @@ -1,7 +1,5 @@ set -x -branch=$(git rev-parse --abbrev-ref HEAD) - ./gradlew packJsPackage ./gradlew packJsPackage -PuseCommonJs @@ -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 diff --git a/.nyx.yaml b/.nyx.yaml deleted file mode 100644 index f98391d..0000000 --- a/.nyx.yaml +++ /dev/null @@ -1,57 +0,0 @@ ---- -# starting from the "simple" preset gives us: -# - the Conventional Commits convention -preset: "simple" -changelog: - path: "CHANGELOG.md" - sections: - "Added": "^feat$" - "Fixed": "^fix$" -releaseTypes: - enabled: - - mainline - - maturity - - internal - publicationServices: - - github - items: - mainline: - description: "{{#fileContent}}CHANGELOG.md{{/fileContent}}" - filterTags: "^({{configuration.releasePrefix}})?([0-9]\\d*)\\.([0-9]\\d*)\\.([0-9]\\d*)$" - gitPush: "true" - gitTag: "true" - matchBranches: "^(master|main)$" - matchEnvironmentVariables: - CI: "^true$" - matchWorkspaceStatus: "CLEAN" - publish: "true" - maturity: - description: "{{#fileContent}}CHANGELOG.md{{/fileContent}}" - collapseVersions: true - collapsedVersionQualifier: "{{#sanitizeLower}}{{branch}}{{/sanitizeLower}}" - filterTags: "^({{configuration.releasePrefix}})?([0-9]\\d*)\\.([0-9]\\d*)\\.([0-9]\\d*)(-(alpha|beta)(\\.([0-9]\\d*))?)?$" - gitPush: "true" - gitTag: "true" - matchBranches: "^(alpha|beta)$" - matchEnvironmentVariables: - CI: "^true$" - matchWorkspaceStatus: "CLEAN" - publish: "true" - publishPreRelease: "true" - internal: - collapseVersions: true - collapsedVersionQualifier: "internal" - gitPush: "false" - gitTag: "false" - identifiers: - - - qualifier: "{{#timestampYYYYMMDDHHMMSS}}{{timestamp}}{{/timestampYYYYMMDDHHMMSS}}" - position: "BUILD" - publish: "false" -services: - github: - type: "GITHUB" - options: - AUTHENTICATION_TOKEN: "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}" - REPOSITORY_NAME: "expression-parser" - REPOSITORY_OWNER: "dhis2" \ No newline at end of file diff --git a/README.md b/README.md index d74adf2..1bab651 100644 --- a/README.md +++ b/README.md @@ -48,22 +48,22 @@ To select which expression is used the `Expression` is parameterized with a `Mod * `RULE_ENGINE_ACTION`: Computes a boolean, string, number or date from a rule ## Development -This library implements the semantic release setup, which means that version numbers are not manually maintained but -derived from the commit/PR history. -Branches: -- `main`: a push to `main` branch will trigger a new production release (both Maven and NPMJS). -- `beta`: a push to `beta` branch will trigger a SNAPSHOT release in Maven and a new beta release in NPMJS. +### Version +Library version is defined in the file `build.gradle.kts`. The version must be manually increased +and include the `-SNAPSHOT` suffix. Please make sure the version is updated before opening the PR. -Version number are determined by the presence of commits with these suffixes: -- `fix:`: it will increase the patch number. -- `feat:`: it will increase the minor version number. -- `feat!:`: it will increase the major version number. +### Publications -If there is not any commit with any of this tags between the previous version and the current commit, nothing will be published. +On merged pull request to `main`: +- Production release to Maven. +- Production release to NPMJS. -Typical workflow: -1. Do work in a feature branch. There is no need to add tags to the commits. -2. Create a PR to `beta` branch including a tag in the PR title depending on the kind of changes. -3. Merge the PR using **Squash and merge**. It will publish a SNAPSHOT/BETA release if there is a version change. -4. Create a PR to `main` branch. Once merged, it will publish a production release. +On pull request creation/update: +- Snapshot release to Maven. + +On demand: +- Beta releases to NPMJS can be triggered on demand by using the action "Publish NPM beta". +Please make sure you select the right branch in the selector. + +Publication can be skipped by adding `[skip publish]` to the pull request title. diff --git a/build.gradle.kts b/build.gradle.kts index 0f3330b..0963752 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,3 @@ -import com.mooltiverse.oss.nyx.gradle.CoreTask - plugins { kotlin("multiplatform") id("maven-publish-conventions") @@ -10,22 +8,12 @@ repositories { mavenCentral() } +version = "1.1.0-SNAPSHOT" group = "org.hisp.dhis.lib.expression" -if (project.hasProperty("betaToSnapshot")) { - val mainVersion = (version as String).split("-beta")[0] - version = "$mainVersion-SNAPSHOT" -} - -tasks.register("checkIsNewVersion") { - val state = project.properties[CoreTask.NYX_STATE_PROPERTY] as com.mooltiverse.oss.nyx.state.State - - if (state.newVersion) { - println("This build generates a new version ${state.version}") - } else { - println("This build does not generate a new version ${state.version}") - throw StopExecutionException("There is no new version") - } +if (project.hasProperty("removeSnapshotSuffix")) { + val mainVersion = (version as String).split("-SNAPSHOT")[0] + version = mainVersion } kotlin { @@ -60,7 +48,7 @@ kotlin { else -> throw GradleException("Host OS is not supported in Kotlin/Native.") } - + sourceSets { all { languageSettings.apply { diff --git a/settings.gradle.kts b/settings.gradle.kts index 31a0554..c82b298 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,7 +7,6 @@ pluginManagement { plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" - id("com.mooltiverse.oss.nyx") version "2.5.2" } rootProject.name = "expression-parser" From 26e5d4a3f50268d6bb78a474b1d8d2c133c9b903 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Tue, 25 Jun 2024 12:04:54 +0200 Subject: [PATCH 2/3] Fix 'if' syntax in github workflows --- .github/workflows/main.yml | 4 ++-- .github/workflows/pull_request.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5ffa0f5..1e72390 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ on: jobs: unit-test: name: Run tests - if: github.event.pull_request.merged == true + if: ${{ github.event.pull_request.merged == true }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -28,7 +28,7 @@ jobs: publish: name: Publish - if: github.event.pull_request.merged == true && !contains(github.event.pull_request.title, '[skip publish]') + if: ${{ github.event.pull_request.merged == true && !contains(github.event.pull_request.title, '[skip publish]') }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index a21ac92..f525d58 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -23,7 +23,7 @@ jobs: publish: name: Publish - if: !contains(github.event.pull_request.title, '[skip publish]') + if: ${{ !contains(github.event.pull_request.title, '[skip publish]') }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From b7d10e241a51696fdb95b2658aab9c3db1155081 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Tue, 25 Jun 2024 12:08:49 +0200 Subject: [PATCH 3/3] Add job dependencies --- .github/workflows/main.yml | 1 + .github/workflows/pull_request.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1e72390..b8e6dfd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,6 +28,7 @@ jobs: publish: 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: diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index f525d58..fd5a3fe 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -23,6 +23,7 @@ jobs: publish: name: Publish + needs: unit-test if: ${{ !contains(github.event.pull_request.title, '[skip publish]') }} runs-on: ubuntu-latest steps: