Skip to content

Commit 200117b

Browse files
authored
Publish the version the build job computed (#631)
Each job in the `Publish` workflow checks out again and recomputes the version from git. If a tag is added after the `build` job has run, a later job publishes a different version from the one `build` computed. Two ways this happens: - `createRelease --push` on a release branch tags the commit while its run is in progress; - someone reruns a failed publish job after tagging. Example: a push to `release/v1.3` builds `1.3.1-rc2`, so `build` reports a prerelease and `publish-maven-central` is skipped. The commit is then tagged `1.3.1`. A rerun of `publish-github-packages` sees the tag and publishes **`1.3.1`** to GitHub Packages, while Maven Central never gets it. ## Changes - `GitVersion.version()` returns `DBOS_VERSION_OVERRIDE` when it is set, and otherwise derives the version from git as before. - `publish-github-packages` and `publish-maven-central` set `DBOS_VERSION_OVERRIDE` from `needs.build.outputs.version`. They no longer compute the version, so they check out at the default depth instead of the full history. `build` still uses the full history. I checked this in a depth-1 clone: with `DBOS_VERSION_OVERRIDE=1.3.1`, the build produces `transact-1.3.1.jar` with `Implementation-Version: 1.3.1` and the correct `SCM-Revision`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent d4bd0e5 commit 200117b

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ jobs:
7373
permissions:
7474
contents: read
7575
packages: write
76+
env:
77+
# Publish the version the build job computed, not one recomputed from tags added since.
78+
DBOS_VERSION_OVERRIDE: ${{ needs.build.outputs.version }}
7679
steps:
7780
- name: Checkout code
7881
uses: actions/checkout@v6
79-
with:
80-
fetch-depth: 0 # fetch-depth 0 needed for version calculation
8182

8283
- name: Set up OpenJDK 21
8384
uses: actions/setup-java@v5
@@ -96,11 +97,12 @@ jobs:
9697
needs: [build]
9798
runs-on: ubuntu-latest
9899
if: startsWith(github.ref, 'refs/heads/release/') && needs.build.outputs.prerelease == 'false'
100+
env:
101+
# Publish the version the build job computed, not one recomputed from tags added since.
102+
DBOS_VERSION_OVERRIDE: ${{ needs.build.outputs.version }}
99103
steps:
100104
- name: Checkout code
101105
uses: actions/checkout@v6
102-
with:
103-
fetch-depth: 0 # fetch-depth 0 needed for version calculation
104106

105107
- name: Set up OpenJDK 21
106108
uses: actions/setup-java@v5

‎build-logic/src/main/kotlin/dev/dbos/build/GitVersion.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ object GitVersion {
1313
fun gitHash(root: File): String =
1414
cachedHash ?: run(root, "git", "rev-parse", "--short", "HEAD").also { cachedHash = it }
1515

16+
/**
17+
* The version from DBOS_VERSION_OVERRIDE when set, else derived from git. CI sets the override so
18+
* every publish job uses the version the build job computed, even if a tag was added since.
19+
*/
1620
fun version(root: File): String =
17-
cachedVersion ?: calcVersion(root).also { cachedVersion = it }
21+
cachedVersion
22+
?: (System.getenv("DBOS_VERSION_OVERRIDE")?.takeIf { it.isNotBlank() } ?: calcVersion(root))
23+
.also { cachedVersion = it }
1824

1925
private fun gitTag(root: File): String? =
2026
runCatching { run(root, "git", "describe", "--abbrev=0", "--tags") }.getOrNull()

0 commit comments

Comments
 (0)