Skip to content

Commit

Permalink
Merge pull request #132 from dhis2/beta
Browse files Browse the repository at this point in the history
Rule engine version 3.0.0
  • Loading branch information
enricocolasante authored Apr 30, 2024
2 parents 317e27e + 84a66c0 commit d10578e
Show file tree
Hide file tree
Showing 53 changed files with 551 additions and 401 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
41 changes: 41 additions & 0 deletions .github/workflows/job-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 }}
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"
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### RuleEngine (WIP)
### RuleEngine (WIP)

#### Initialization
`RuleEngine` is initialized in two steps.
Expand Down Expand Up @@ -60,7 +60,28 @@ List of supported environment (contextual) variables:
- enrollment_id
- enrollment_count
- incident_date
- tei_count
- tei_count

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

If there is not any commit with any of this tags between the previous version and the current commit, nothing will be published.

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.

---
WIP
Loading

0 comments on commit d10578e

Please sign in to comment.