From bed8c8c311c2fbea67104b47865e561898159eb0 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 19 Jul 2026 22:01:08 +0200 Subject: [PATCH 1/2] Publish snapshot for same-repo pull requests Fork PRs cannot publish (no secrets), and branches behind main would push a snapshot missing commits already on main, so both are skipped. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01159RbWmMUr4KQrDuxGBPx9 --- .github/workflows/publish.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index aacaf60..9fda554 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,6 +4,7 @@ on: push: branches: - main + pull_request: workflow_dispatch: permissions: @@ -16,11 +17,26 @@ concurrency: jobs: publish: runs-on: ubuntu-latest - if: github.repository == 'JabRef/html-to-node' + # Fork PRs get no secrets, so they can never publish - don't even start the job for them + if: github.repository == 'JabRef/html-to-node' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) steps: - uses: actions/checkout@v7 with: show-progress: 'false' + # Publish the branch as-is, not GitHub's main-merged ref, and keep enough + # history for the is-up-to-date check below + ref: ${{ github.event.pull_request.head.sha || github.sha }} + fetch-depth: 0 + - name: Skip if branch is behind main + id: uptodate + # A stale branch would publish a snapshot missing commits that are already on + # main, silently downgrading the artifact for everyone consuming it + run: | + git fetch --no-tags origin main + if [ "${{ github.event_name }}" = "pull_request" ] && ! git merge-base --is-ancestor FETCH_HEAD HEAD; then + echo "Branch is behind main - rebase/merge main before a snapshot is published." + echo "skip=true" >> "$GITHUB_OUTPUT" + fi - name: Setup JDK uses: actions/setup-java@v5 with: @@ -45,6 +61,7 @@ jobs: mavenCentralPassword=${{ secrets.KOPPOR_MAVENCENTRALPASSWORD }} EOF - name: Publish snapshot + if: steps.uptodate.outputs.skip != 'true' # Release versions are published by release.yml on tag push; this workflow only # handles the rolling snapshot run: | From 3a2399461b90430824b27f9f180deb60df06e71b Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 19 Jul 2026 22:06:00 +0200 Subject: [PATCH 2/2] Publish PR snapshots under a PR-specific version -PversionSuffix=PR17 yields 0.2.0-PR17-SNAPSHOT, so a pull request snapshot is identifiable and does not clobber the one built from main. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01159RbWmMUr4KQrDuxGBPx9 --- .github/workflows/publish.yml | 6 ++++-- .github/workflows/release.yml | 2 +- build.gradle.kts | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9fda554..3244a8d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -65,8 +65,10 @@ jobs: # Release versions are published by release.yml on tag push; this workflow only # handles the rolling snapshot run: | - if ! grep -q 'version = ".*-SNAPSHOT"' build.gradle.kts; then + if ! grep -q '^version = .*SNAPSHOT' build.gradle.kts; then echo "Version is not a SNAPSHOT - skipping (releases go through release.yml)." exit 0 fi - ./gradlew publishAllPublicationsToMavenCentralRepository + ./gradlew ${PR_NUMBER:+-PversionSuffix=PR$PR_NUMBER} publishAllPublicationsToMavenCentralRepository + env: + PR_NUMBER: ${{ github.event.pull_request.number }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e2bd4a1..ac2ce98 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,7 +45,7 @@ jobs: EOF - name: Guard against SNAPSHOT releases run: | - if grep -q 'version = ".*-SNAPSHOT"' build.gradle.kts; then + if grep -q '^version = .*SNAPSHOT' build.gradle.kts; then echo "Tagged commit still has a SNAPSHOT version - refusing to release." exit 1 fi diff --git a/build.gradle.kts b/build.gradle.kts index 1ad37e9..8964eb5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,9 @@ plugins { } group = "org.jabref" -version = "0.2.0-SNAPSHOT" +// -PversionSuffix=PR17 turns 0.2.0-SNAPSHOT into 0.2.0-PR17-SNAPSHOT, so a pull request +// snapshot is identifiable and does not clobber the one built from main +version = "0.2.0" + (findProperty("versionSuffix")?.let { "-$it" } ?: "") + "-SNAPSHOT" repositories { mavenCentral()