Skip to content

Commit

Permalink
Merge pull request #1 from vgarciabnz/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
vgarciabnz authored Feb 14, 2024
2 parents 8b33b22 + 8b42692 commit 6ecef49
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 52 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: Publish to github
run: ./gradlew :nyxPublish
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

- name: Publish NPMJS
if: ${{ false }}
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
44 changes: 12 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
name: Run tests
name: Main

on:
push:
branches:
- 'main'
- 'beta'

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
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
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" ]; then
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
elif [ "$branch" = "beta" ]; then
./gradlew publishToSonatype -PbetaToSnapshot
fi
15 changes: 15 additions & 0 deletions .github/workflows/scripts/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
63 changes: 63 additions & 0 deletions .nyx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
# 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$" # only match this release type when running on CI servers
matchWorkspaceStatus: "CLEAN" # only match this release type when the repository is 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)$"
matchWorkspaceStatus: "CLEAN" # only match this release type when the repository is clean
publish: "true"
publishPreRelease: "true"
# "internal" overrides the release type with the same name from the preset adding some qualifiers and is the global fallback for all release types
internal:
collapseVersions: true
collapsedVersionQualifier: "internal"
gitPush: "false"
gitTag: "false"
identifiers:
-
qualifier: "{{#sanitizeLower}}{{branch}}{{/sanitizeLower}}"
position: "BUILD"
-
qualifier: "{{#short5}}{{releaseScope.finalCommit}}{{/short5}}"
position: "BUILD"
-
qualifier: "{{#timestampYYYYMMDDHHMMSS}}{{timestamp}}{{/timestampYYYYMMDDHHMMSS}}"
position: "BUILD"
publish: "false"
publishPreRelease: "false"
services:
github:
type: "GITHUB"
options:
AUTHENTICATION_TOKEN: "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}"
REPOSITORY_NAME: "expression-parser"
REPOSITORY_OWNER: "vgarciabnz"
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
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 @@ -68,7 +66,7 @@ nexusPublishing {
}

signing {
isRequired = isReleaseVersion
setRequired({ !version.toString().endsWith("-SNAPSHOT") })
useInMemoryPgpKeys(signingPrivateKey, signingPassword)
sign(publishing.publications)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ project.afterEvaluate {
"publishConfig" by {
"access" by "public"
}
"private" by false
}
}
}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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"

0 comments on commit 6ecef49

Please sign in to comment.