From f68acb221bd6b2a95e523e835ad38ffd578e38cf Mon Sep 17 00:00:00 2001 From: Mustafa Ozhan Date: Sat, 12 Sep 2026 23:00:19 +0200 Subject: [PATCH] [SubMob/ParserMob#269] Publish releases from develop on every merge --- .github/workflows/main.yml | 25 ++++++++++++++++++--- .github/workflows/publish.yml | 16 ------------- ParserMob.gradle.kts | 7 ++++++ buildSrc/src/main/kotlin/ProjectSettings.kt | 12 +++++----- 4 files changed, 35 insertions(+), 25 deletions(-) delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b61efcf..ad59aa6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,13 +5,15 @@ on: push: branches: - develop - - master jobs: ci: runs-on: macos-26 + permissions: + contents: write # create the release tag + steps: - name: Setup Gradle Repo uses: Oztechan/Global/actions/setup-gradle-repo@8610938e630b3ed86127765237fe3647b9fabd4f @@ -33,8 +35,8 @@ jobs: project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} coverage-reports: build/reports/kover/report.xml - # Publish only on a merge to develop/master, and only after the build above passes. - # develop -> X.Y-SNAPSHOT (unsigned), master -> X.Y.Z release (signed). + # develop is the release branch: every merge publishes an immutable, signed X.Y.Z to Maven + # Central, once the build above passes. Every other branch builds X.Y-SNAPSHOT and never publishes. - name: Publish if: github.event_name == 'push' # Normalize the armored GPG key: literal "\n" -> real newlines (vanniktech's @@ -48,6 +50,23 @@ jobs: GPG_KEY_RAW: ${{ secrets.GPG_KEY }} ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSWORD }} + # Read back from Gradle so the tag always matches the version just published to Maven Central. + - name: Resolve version + id: version + if: github.event_name == 'push' + run: echo "version=$(./gradlew -q printVersion | grep '^VERSION_NAME=' | cut -d= -f2)" >> $GITHUB_OUTPUT + + # Tags the released commit and cuts the matching GitHub release. Done inline rather than from a + # tag-triggered workflow, because tags pushed with GITHUB_TOKEN never trigger other workflows — + # which is also why automatic_release_tag is set: with no tag ref the action has nothing to cut. + - name: PublishRelease + if: github.event_name == 'push' + uses: marvinpinto/action-automatic-releases@v1.2.1 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + prerelease: false + automatic_release_tag: v${{ steps.version.outputs.version }} + - name: Notify slack success if: success() && github.event_name == 'push' env: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 36c2719..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Publish Release - -on: - push: - tags: - - "v*" - -jobs: - - PublishRelease: - uses: Oztechan/Global/.github/workflows/reusable-publish.yml@8610938e630b3ed86127765237fe3647b9fabd4f - with: - slack_channel: "submob" - secrets: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/ParserMob.gradle.kts b/ParserMob.gradle.kts index 5a67cff..ece99e8 100644 --- a/ParserMob.gradle.kts +++ b/ParserMob.gradle.kts @@ -33,3 +33,10 @@ allprojects { } } } + +// Resolved version, read by CI to tag the release. The VERSION_NAME= prefix keeps it parseable +// even when Gradle writes build-scan output to the same stream. +tasks.register("printVersion") { + val projectVersion = version.toString() + doLast { println("VERSION_NAME=$projectVersion") } +} diff --git a/buildSrc/src/main/kotlin/ProjectSettings.kt b/buildSrc/src/main/kotlin/ProjectSettings.kt index daeb93e..96ca84f 100644 --- a/buildSrc/src/main/kotlin/ProjectSettings.kt +++ b/buildSrc/src/main/kotlin/ProjectSettings.kt @@ -7,18 +7,18 @@ object ProjectSettings { private const val MAYOR_VERSION = 2 private const val MINOR_VERSION = 0 - // git rev-list --first-parent --count master (recalibrated at the 2.0 major bump) - private const val VERSION_DIF = 27 + // git rev-list --first-parent --count develop (recalibrated when releases moved off master) + private const val VERSION_DIF = 335 - fun getVersionName(project: Project): String = if (isMaster(project)) { - // Permanent, pinnable release: x.y.. + fun getVersionName(project: Project): String = if (isReleaseBranch(project)) { + // Permanent, pinnable release: x.y.. Every merge to develop publishes one. "$MAYOR_VERSION.$MINOR_VERSION.${gitCommitCount(project).toInt() - VERSION_DIF}" } else { - // Stable moving snapshot ("latest develop") — consumers pin x.y-SNAPSHOT and always get newest. + // Feature branches and local builds — never published, so the moving snapshot is fine. "$MAYOR_VERSION.$MINOR_VERSION-SNAPSHOT" } - private fun isMaster(project: Project): Boolean = currentBranch(project) == "master" + private fun isReleaseBranch(project: Project): Boolean = currentBranch(project) == "develop" private fun currentBranch(project: Project): String { // In GitHub Actions the checked-out branch is exposed as GITHUB_REF_NAME; fall back to git locally.