Skip to content

Commit 1002e5d

Browse files
committed
#432 Publish SNAPSHOTs to GH Packages from CI
Add a publish-gh-packages job to gradle-build.yml that runs after build-artifacts succeeds and pushes all four artifacts plus the plugin marker to GitHub Packages. Triggers only on push events to feature/* or bugfix/* branches — those are the refs git-versioning rewrites to <slug>-SNAPSHOT coordinates. develop and main fall through to gradle.properties' static 2.0.0-rcN and would conflict with already-published release versions, so we skip them here. The job uses the auto-injected secrets.GITHUB_TOKEN (no PAT needed for in-repo publishing) and github.actor as the username. The conditional credential block in build.gradle picks them up; without the env vars set (e.g. on PRs from forks) the GitHubPackages repo isn't registered and the job's gradle invocation would be a no-op, but the 'if:' gate prevents that path from running at all.
1 parent 7bcd19f commit 1002e5d

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

.github/workflows/build-artifacts.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ jobs:
2525
steps:
2626
- name: Check out
2727
uses: actions/checkout@v5
28+
with:
29+
# git-versioning derives the project version from the current branch;
30+
# the default fetch-depth: 1 leaves HEAD detached without a branch ref
31+
# and the plugin falls back to gradle.properties' static version.
32+
fetch-depth: 0
2833

2934
- name: Setup Java
3035
uses: actions/setup-java@v5

.github/workflows/gradle-build.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,42 @@ jobs:
1818
secrets:
1919
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
2020

21+
publish-gh-packages:
22+
# Publish per-branch SNAPSHOTs to GitHub Packages so downstream consumers
23+
# can pull a feature/bugfix branch before it merges. Only runs on push
24+
# events to feature/bugfix branches (git-versioning's SNAPSHOT regex);
25+
# develop and main fall through to the static gradle.properties version
26+
# and would conflict with already-published releases.
27+
needs: build-artifacts
28+
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/heads/feature/') || startsWith(github.ref, 'refs/heads/bugfix/'))
29+
runs-on: ubuntu-latest
30+
permissions:
31+
packages: write
32+
contents: read
33+
steps:
34+
- name: Check out
35+
uses: actions/checkout@v5
36+
with:
37+
# Needed for git-versioning to derive the branch-slug-SNAPSHOT version.
38+
fetch-depth: 0
39+
40+
- name: Setup Java
41+
uses: actions/setup-java@v5
42+
with:
43+
distribution: temurin
44+
java-version: '17'
45+
46+
- name: Setup Gradle
47+
uses: gradle/actions/setup-gradle@v4
48+
with:
49+
cache-read-only: true
50+
51+
- name: Publish SNAPSHOT to GitHub Packages
52+
env:
53+
GITHUB_USER: ${{ github.actor }}
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
run: ./gradlew publishAllPublicationsToGitHubPackagesRepository --no-daemon
56+
2157
post-build:
2258
needs: build-artifacts
2359
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)