Skip to content

Commit

Permalink
Merge pull request #123 from dhis2/semantic-release
Browse files Browse the repository at this point in the history
feat!: semantic release setup
  • Loading branch information
vgarciabnz authored Feb 21, 2024
2 parents 317e27e + e3f5fa7 commit 8492d59
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 106 deletions.
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@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
39 changes: 39 additions & 0 deletions .github/workflows/job-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 }}

- name: Publish NPMJS
run: ./.github/workflows/scripts/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@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
48 changes: 15 additions & 33 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
name: Run tests
name: Main

on: [pull_request]
on:
push:
branches:
- 'main'
- 'master'
- 'beta'

jobs:
unit-test:
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
uses: ./.github/workflows/job-test.yml

artifact:
name: Publish - Nexus
runs-on: ubuntu-latest
check-new-version:
needs: unit-test
uses: ./.github/workflows/job-check-new-version.yml

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: Release Maven package
run: ./gradlew publishAllPublicationsToSonatypeRepository
env:
OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
publish:
needs: check-new-version
if: ${{ needs.check-new-version.outputs.isNewVersion == 'true' }}
uses: ./.github/workflows/job-publish.yml
secrets: inherit
46 changes: 0 additions & 46 deletions .github/workflows/master.yml

This file was deleted.

7 changes: 7 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Pull request

on: [pull_request]

jobs:
unit-test:
uses: ./.github/workflows/job-test.yml
8 changes: 8 additions & 0 deletions .github/workflows/scripts/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
9 changes: 9 additions & 0 deletions .github/workflows/scripts/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" ] || [ "$branch" = "master" ]; then
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
elif [ "$branch" = "beta" ]; then
./gradlew publishToSonatype -PbetaToSnapshot
fi
17 changes: 17 additions & 0 deletions .github/workflows/scripts/publish-npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set -x

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

./gradlew packJsPackage
./gradlew packJsPackage -PuseCommonJs

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
57 changes: 57 additions & 0 deletions .nyx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
# 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: "dhis2-rule-engine"
REPOSITORY_OWNER: "dhis2"
28 changes: 22 additions & 6 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 @@ -10,11 +12,21 @@ repositories {
}

group = "org.hisp.dhis.rules"
version = "3.0.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 All @@ -29,9 +41,13 @@ kotlin {
}
js {
nodejs()
useEsModules()
if (project.hasProperty("useCommonJs")) {
useCommonJs()
} else {
useEsModules()
generateTypeScriptDefinitions()
}
binaries.library()
generateTypeScriptDefinitions()
}
val hostOs = System.getProperty("os.name")
val isArm64 = System.getProperty("os.arch") == "aarch64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ val ossrhPassword: String? = System.getenv("OSSRH_PASSWORD")
val signingPrivateKey: String? = System.getenv("SIGNING_PRIVATE_KEY")
val signingPassword: String? = System.getenv("SIGNING_PASSWORD")

val isReleaseVersion = (version as String).contains("SNAPSHOT")

val dokkaHtml = tasks.findByName("dokkaHtml")!!

val dokkaHtmlJar = tasks.register<Jar>("dokkaHtmlJar") {
Expand Down Expand Up @@ -70,7 +68,7 @@ nexusPublishing {
}

signing {
isRequired = isReleaseVersion
setRequired({ !version.toString().endsWith("-SNAPSHOT") })
useInMemoryPgpKeys(signingPrivateKey, signingPassword)
sign(publishing.publications)
}
Loading

0 comments on commit 8492d59

Please sign in to comment.