diff --git a/.github/workflows/github-packages-publish.yml b/.github/workflows/github-packages-publish.yml index 28c409e..a1918e7 100644 --- a/.github/workflows/github-packages-publish.yml +++ b/.github/workflows/github-packages-publish.yml @@ -1,11 +1,12 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle +# This workflow publishes one or all modules to Maven Central when a GitHub Release is published. +# +# Supported release tag formats: +# /v — publish a single module (e.g. tuple/v3.3.1) +# v — publish all modules (e.g. v3.3.0, backward compat) +# +# Valid module names: common-toolbox, tuple, identity-generator, crypto-toolbox, math-toolbox, version-catalogue -name: Publish Packages to GitHub Packages with Gradle +name: Publish Packages to Maven Central on: release: @@ -13,7 +14,7 @@ on: - published jobs: - build: + publish: name: Build and Publish runs-on: ubuntu-latest permissions: @@ -24,6 +25,47 @@ jobs: - name: Checkout uses: actions/checkout@v4.2.2 + - name: Parse Release Tag + id: parse-tag + run: | + TAG="${{ github.event.release.tag_name }}" + echo "Release tag: ${TAG}" + + # /v — single module + if [[ "${TAG}" =~ ^([a-z][a-z0-9-]*)/v?([0-9]+\.[0-9]+\.[0-9]+.*)$ ]]; then + MODULE="${BASH_REMATCH[1]}" + VERSION="${BASH_REMATCH[2]}" + + case "${MODULE}" in + common-toolbox) PROP="commonToolboxVersion" ;; + tuple) PROP="tupleVersion" ;; + identity-generator) PROP="identityGeneratorVersion" ;; + crypto-toolbox) PROP="cryptoToolboxVersion" ;; + math-toolbox) PROP="mathToolboxVersion" ;; + version-catalogue) PROP="versionCatalogueVersion" ;; + *) + echo "::error::Unknown module: ${MODULE}" + echo "Valid modules: common-toolbox, tuple, identity-generator, crypto-toolbox, math-toolbox, version-catalogue" + exit 1 + ;; + esac + + echo "module=${MODULE}" >> $GITHUB_OUTPUT + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "gradle_property=${PROP}" >> $GITHUB_OUTPUT + echo "gradle_project=:${MODULE}" >> $GITHUB_OUTPUT + echo "single_module=true" >> $GITHUB_OUTPUT + + echo "→ Publishing single module: ${MODULE} @ ${VERSION}" + + # v — all modules (backward compat) + else + VERSION="${TAG#v}" + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "single_module=false" >> $GITHUB_OUTPUT + echo "→ Publishing all modules @ ${VERSION}" + fi + - name: Setup GPG TTY run: export GPG_TTY=$(tty) @@ -61,19 +103,50 @@ jobs: run: chmod +x ./gradlew - name: Build with Gradle - # Overwrite artefactVersion with tag name - run: ./gradlew build -PartefactVersion=${{ github.event.release.tag_name }} + env: + SINGLE: ${{ steps.parse-tag.outputs.single_module }} + PROJECT: ${{ steps.parse-tag.outputs.gradle_project }} + PROPERTY: ${{ steps.parse-tag.outputs.gradle_property }} + VERSION: ${{ steps.parse-tag.outputs.version }} + run: | + if [ "${SINGLE}" = "true" ]; then + ./gradlew "${PROJECT}:build" "-P${PROPERTY}=${VERSION}" + else + ./gradlew build \ + -PcommonToolboxVersion="${VERSION}" \ + -PtupleVersion="${VERSION}" \ + -PidentityGeneratorVersion="${VERSION}" \ + -PcryptoToolboxVersion="${VERSION}" \ + -PmathToolboxVersion="${VERSION}" \ + -PversionCatalogueVersion="${VERSION}" + fi - name: List Output Items run: ls -l ./**/build/libs - name: Publish to Maven Central - run: ./gradlew publish + env: + SINGLE: ${{ steps.parse-tag.outputs.single_module }} + PROJECT: ${{ steps.parse-tag.outputs.gradle_project }} + PROPERTY: ${{ steps.parse-tag.outputs.gradle_property }} + VERSION: ${{ steps.parse-tag.outputs.version }} + run: | + if [ "${SINGLE}" = "true" ]; then + ./gradlew "${PROJECT}:publish" "-P${PROPERTY}=${VERSION}" + else + ./gradlew publish \ + -PcommonToolboxVersion="${VERSION}" \ + -PtupleVersion="${VERSION}" \ + -PidentityGeneratorVersion="${VERSION}" \ + -PcryptoToolboxVersion="${VERSION}" \ + -PmathToolboxVersion="${VERSION}" \ + -PversionCatalogueVersion="${VERSION}" + fi - name: Create Deployment on Central Publisher Portal run: | curl --fail -X 'POST' \ - 'https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/com.onixbyte?publishing_type=user_managed' \ - -H 'accept: */*' \ - -H 'Authorization: Bearer ${{ secrets.MAVEN_PORTAL_TOKEN }}' \ - -d '' + 'https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/com.onixbyte?publishing_type=user_managed' \ + -H 'accept: */*' \ + -H 'Authorization: Bearer ${{ secrets.MAVEN_PORTAL_TOKEN }}' \ + -d '' diff --git a/build.gradle.kts b/build.gradle.kts index a60c427..6449daa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,9 +20,6 @@ * SOFTWARE. */ -val artefactVersion: String by project - subprojects { group = "com.onixbyte" - version = artefactVersion } diff --git a/common-toolbox/build.gradle.kts b/common-toolbox/build.gradle.kts index 7866663..542f580 100644 --- a/common-toolbox/build.gradle.kts +++ b/common-toolbox/build.gradle.kts @@ -29,7 +29,9 @@ plugins { id("signing") } -val artefactVersion: String by project +val commonToolboxVersion: String by project + +version = commonToolboxVersion val projectUrl: String by project val projectGithubUrl: String by project val licenseName: String by project @@ -70,7 +72,7 @@ publishing { create("commonToolbox") { groupId = group.toString() artifactId = "common-toolbox" - version = artefactVersion + version = commonToolboxVersion pom { name = "OnixByte Common Toolbox" diff --git a/crypto-toolbox/build.gradle.kts b/crypto-toolbox/build.gradle.kts index 1be5763..ed4b40b 100644 --- a/crypto-toolbox/build.gradle.kts +++ b/crypto-toolbox/build.gradle.kts @@ -29,7 +29,9 @@ plugins { id("signing") } -val artefactVersion: String by project +val cryptoToolboxVersion: String by project + +version = cryptoToolboxVersion val projectUrl: String by project val projectGithubUrl: String by project val licenseName: String by project @@ -73,7 +75,7 @@ publishing { create("cryptoToolbox") { groupId = group.toString() artifactId = "crypto-toolbox" - version = artefactVersion + version = cryptoToolboxVersion pom { name = "OnixByte Crypto Toolbox" diff --git a/gradle.properties b/gradle.properties index 6dcdc54..5209411 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,6 +21,12 @@ # artefactVersion=3.3.0 +commonToolboxVersion=3.3.0 +tupleVersion=3.3.0 +identityGeneratorVersion=3.3.0 +cryptoToolboxVersion=3.3.0 +mathToolboxVersion=3.3.0 +versionCatalogueVersion=3.3.0 projectUrl=https://onixbyte.com/projects/onixbyte-toolbox projectGithubUrl=https://github.com/onixbyte/onixbyte-toolbox licenseName=MIT diff --git a/identity-generator/build.gradle.kts b/identity-generator/build.gradle.kts index c53908d..d076fc5 100644 --- a/identity-generator/build.gradle.kts +++ b/identity-generator/build.gradle.kts @@ -29,7 +29,9 @@ plugins { id("signing") } -val artefactVersion: String by project +val identityGeneratorVersion: String by project + +version = identityGeneratorVersion val projectUrl: String by project val projectGithubUrl: String by project val licenseName: String by project @@ -70,7 +72,7 @@ publishing { create("identityGenerator") { groupId = group.toString() artifactId = "identity-generator" - version = artefactVersion + version = identityGeneratorVersion pom { name = "OnixByte Identity Generator" diff --git a/math-toolbox/build.gradle.kts b/math-toolbox/build.gradle.kts index db75ca6..3a44116 100644 --- a/math-toolbox/build.gradle.kts +++ b/math-toolbox/build.gradle.kts @@ -29,7 +29,9 @@ plugins { id("signing") } -val artefactVersion: String by project +val mathToolboxVersion: String by project + +version = mathToolboxVersion val projectUrl: String by project val projectGithubUrl: String by project val licenseName: String by project @@ -70,7 +72,7 @@ publishing { create("mathToolbox") { groupId = group.toString() artifactId = "math-toolbox" - version = artefactVersion + version = mathToolboxVersion pom { name = "OnixByte Math Toolbox" diff --git a/tuple/build.gradle.kts b/tuple/build.gradle.kts index 5f01dcd..870bd1a 100644 --- a/tuple/build.gradle.kts +++ b/tuple/build.gradle.kts @@ -29,7 +29,9 @@ plugins { id("signing") } -val artefactVersion: String by project +val tupleVersion: String by project + +version = tupleVersion val projectUrl: String by project val projectGithubUrl: String by project val licenseName: String by project @@ -70,7 +72,7 @@ publishing { create("tuple") { groupId = group.toString() artifactId = "tuple" - version = artefactVersion + version = tupleVersion pom { name = "OnixByte Tuple" diff --git a/version-catalogue/build.gradle.kts b/version-catalogue/build.gradle.kts index c74df5e..90f945b 100644 --- a/version-catalogue/build.gradle.kts +++ b/version-catalogue/build.gradle.kts @@ -28,7 +28,14 @@ plugins { id("signing") } -val artefactVersion: String by project +val commonToolboxVersion: String by project +val identityGeneratorVersion: String by project +val cryptoToolboxVersion: String by project +val mathToolboxVersion: String by project +val tupleVersion: String by project +val versionCatalogueVersion: String by project + +version = versionCatalogueVersion val projectUrl: String by project val projectGithubUrl: String by project val licenseName: String by project @@ -40,11 +47,11 @@ repositories { dependencies { constraints { - api("com.onixbyte:common-toolbox:$artefactVersion") - api("com.onixbyte:identity-generator:$artefactVersion") - api("com.onixbyte:crypto-toolbox:$artefactVersion") - api("com.onixbyte:math-toolbox:$artefactVersion") - api("com.onixbyte:tuple:$artefactVersion") + api("com.onixbyte:common-toolbox:$commonToolboxVersion") + api("com.onixbyte:identity-generator:$identityGeneratorVersion") + api("com.onixbyte:crypto-toolbox:$cryptoToolboxVersion") + api("com.onixbyte:math-toolbox:$mathToolboxVersion") + api("com.onixbyte:tuple:$tupleVersion") } } @@ -53,7 +60,7 @@ publishing { create("versionCatalogue") { groupId = group.toString() artifactId = "version-catalogue" - version = artefactVersion + version = versionCatalogueVersion pom { name = "OnixByte Version Catalogue"