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

feat: add semanatic release setup #46

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions .github/workflows/beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Beta branch

on:
push:
branches:
- 'beta'

jobs:
unit-test:
uses: ./.github/workflows/job-test.yml

check-new-version:
needs: unit-test
uses: ./.github/workflows/job-check-new-version.yml

publish:
needs: check-new-version
if: ${{ needs.check-new-version.outputs.isNewVersion == 'true' }}
uses: ./.github/workflows/job-publish.yml
secrets: inherit
Copy link

@kabaros kabaros Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two suggestions:

  • beta and main workflows can be merged? I don't see a difference
  • I don't think you need to manage the check for newVersion manually. You can just rely on the status code of running the script and if it's a success (zero), continue. Otherwise, abort.

I think these changes could make the scripts easier to follow.

Suggested change
name: Beta branch
on:
push:
branches:
- 'beta'
jobs:
unit-test:
uses: ./.github/workflows/job-test.yml
check-new-version:
needs: unit-test
uses: ./.github/workflows/job-check-new-version.yml
publish:
needs: check-new-version
if: ${{ needs.check-new-version.outputs.isNewVersion == 'true' }}
uses: ./.github/workflows/job-publish.yml
secrets: inherit
name: publish
on:
push:
branches:
- 'beta'
- 'main'
jobs:
unit-test:
uses: ./.github/workflows/job-test.yml
check-new-version:
id: checkNewVersion
needs: unit-test
run: sh ./.github/workflows/check-new-version.sh
publish:
needs: check-new-version
if: steps.checkNewVersion.outputs.status == 'success'
uses: ./.github/workflows/job-publish.yml
secrets: inherit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment @kabaros.

  • Totally agree on the first point. Those workflows were different at the beginning; they ended up with the same structure and I forgot to remove one of them.
  • About the second point, it would be easier just to check for a failure as you suggested. The only reason why I preferred to check the output was to make the step not fail when the version has not change. The overall result would be the same (the version won't be published), but the "check-new-version" step will be colored in red, which could be considered a false positive because it is not an error, it is a valid. What do you think? I am not a pro with Github actions, maybe there is another way to deal with it

8 changes: 8 additions & 0 deletions .github/workflows/check-new-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 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
28 changes: 28 additions & 0 deletions .github/workflows/job-check-new-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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@v3
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
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/check-new-version.sh
37 changes: 37 additions & 0 deletions .github/workflows/job-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on:
workflow_call

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

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

- name: Create version tag
run: ./gradlew :nyxMark

- name: Publish Maven
run: ./.github/workflows/publish-maven.sh
env:
OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}

- name: Publish NPMJS
run: ./.github/workflows/publish-npm.sh
env:
NPMJS_TOKEN: ${{ secrets.DHIS2_BOT_NPM_TOKEN }}
19 changes: 19 additions & 0 deletions .github/workflows/job-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
workflow_call

jobs:
unit-test:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Test
run: ./gradlew clean allTests
43 changes: 11 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run tests
name: Main branch

on:
push:
Expand All @@ -7,35 +7,14 @@ on:

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
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 - Nexus
runs-on: ubuntu-latest
uses: ./.github/workflows/job-test.yml

check-new-version:
needs: unit-test
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Release Maven package
run: ./gradlew publishAllPublicationsToSonatypeRepository
env:
OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
uses: ./.github/workflows/job-check-new-version.yml

publish:
needs: check-new-version
if: ${{ needs.check-new-version.outputs.isNewVersion == 'true' }}
uses: ./.github/workflows/job-publish.yml
secrets: inherit
9 changes: 9 additions & 0 deletions .github/workflows/publish-maven.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -x

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

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

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

./gradlew packJsPackage
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
14 changes: 1 addition & 13 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,4 @@ on: [pull_request]

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Test
run: ./gradlew clean allTests
uses: ./.github/workflows/job-test.yml
20 changes: 16 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.mooltiverse.oss.nyx.gradle.CoreTask

plugins {
kotlin("multiplatform")
id("maven-publish-conventions")
Expand All @@ -9,11 +11,21 @@ repositories {
}

group = "org.hisp.dhis.lib.expression"
version = "1.1.0-SNAPSHOT"

val isReleaseVersion = project.hasProperty("removeSnapshot")
if (isReleaseVersion) {
version = (version as String).replace("-SNAPSHOT", "")
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")
}
}

kotlin {
Expand Down
5 changes: 5 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ pluginManagement {

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
id("com.mooltiverse.oss.nyx") version "2.5.2"
}

configure<com.mooltiverse.oss.nyx.gradle.NyxExtension> {
preset.set("extended")
}

rootProject.name = "expression-parser"
Loading