1name: Release
2
3on:
4 push:
5 tags: ['v*.*.*'] # only semver tags start a release
6
7permissions:
8 contents: write # create the GitHub Release
9 packages: write # push to ghcr.io
10
11jobs:
12 test:
13 runs-on: ubuntu-latest
14 steps:
15 - uses: actions/checkout@v7
16 - uses: actions/setup-java@v6
17 with: { distribution: temurin, java-version: '25', cache: maven }
18 - run: mvn -B verify # never release untested code
19
20 release:
21 needs: test
22 runs-on: ubuntu-latest
23 steps:
24 - uses: actions/checkout@v7
25 with: { fetch-depth: 0 } # full history for release notes
26
27 - uses: actions/setup-java@v6
28 with: { distribution: temurin, java-version: '25', cache: maven }
29
30 - name: Build with the tag version
31 run: |
32 VERSION="${GITHUB_REF_NAME#v}" # v1.4.0 -> 1.4.0
33 mvn -B versions:set -DnewVersion="$VERSION"
34 mvn -B package -DskipTests
35
36 - uses: docker/login-action@v4
37 with:
38 registry: ghcr.io
39 username: ${{ github.actor }}
40 password: ${{ secrets.GITHUB_TOKEN }}
41
42 - id: meta
43 uses: docker/metadata-action@v6
44 with:
45 images: ghcr.io/${{ github.repository }}
46 tags: |
47 type=semver,pattern={{version}}
48 type=semver,pattern={{major}}.{{minor}}
49
50 - uses: docker/setup-buildx-action@v4
51 - uses: docker/build-push-action@v7
52 with:
53 context: .
54 push: true
55 tags: ${{ steps.meta.outputs.tags }}
56 labels: ${{ steps.meta.outputs.labels }}
57 cache-from: type=gha
58 cache-to: type=gha,mode=max
59
60 - name: GitHub Release
61 env:
62 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # gh CLI is preinstalled
63 run: |
64 gh release create "$GITHUB_REF_NAME" target/*.jar \
65 --title "$GITHUB_REF_NAME" \
66 --generate-notes \
67 $([[ "$GITHUB_REF_NAME" == *-* ]] && echo --prerelease)