Skip to content

Commit 6ca94cf

Browse files
committed
chore: add release workflow
1 parent 9221435 commit 6ca94cf

File tree

2 files changed

+188
-0
lines changed

2 files changed

+188
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: bump version in gradle.properties
2+
inputs:
3+
version:
4+
required: true
5+
description: new version
6+
token:
7+
required: true
8+
description: token to use when
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Update the worktree
14+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
15+
with:
16+
ref: ${{ github.ref_name }}
17+
token: ${{ inputs.token }}
18+
persist-credentials: true
19+
20+
- name: update version
21+
shell: bash
22+
# language=bash
23+
run: |
24+
# Check if version needs to be updated to ${{ inputs.version }}
25+
VERSION_LINE="current.version=${{ inputs.version }}"
26+
if grep -q "^${VERSION_LINE}$" gradle.properties; then
27+
echo "Version is already up to date"
28+
exit 0
29+
fi
30+
31+
# Update version in gradle.properties
32+
sed -i "s/^current\.version=.*$/${VERSION_LINE}/" gradle.properties
33+
34+
# Commit and push changes
35+
git add gradle.properties
36+
git commit -m "chore: bump version to ${{ inputs.version }}" -m "[ci-skip]"
37+
git push origin "${{ github.ref_name }}"
38+
39+
- name: Update the worktree, revert to the default token
40+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
41+
with:
42+
ref: ${{ github.ref_name }}
43+
token: ${{ github.token }}

.github/workflows/release.yaml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
required: false
8+
type: string
9+
default: ''
10+
description: Release version number (without v, defaults to gradle.properties)
11+
12+
jobs:
13+
publish-release:
14+
name: Publish release
15+
runs-on: ubuntu-latest
16+
permissions:
17+
# write permission is required to create a GitHub release
18+
contents: write
19+
# write permission is required for autolabeler
20+
# otherwise, read permission is required at least
21+
pull-requests: read
22+
steps:
23+
- name: Validate input parameters
24+
# language=bash
25+
run: |
26+
# Ensure we release from master or release/** branches, ensure version number follows semver
27+
BRANCH_NAME=${GITHUB_REF##refs/heads/}
28+
if [[ ! "$BRANCH_NAME" =~ ^(master|release/.+)$ ]]; then
29+
echo "Error: Release must be created from 'master' or 'release/**' branch. Current branch is '$BRANCH_NAME'"
30+
exit 1
31+
fi
32+
33+
# Validate version follows semver or is empty
34+
VERSION="${{ inputs.version }}"
35+
if [[ -n "$VERSION" && ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
36+
echo "Error: Version must be blank or follow semantic versioning format (x.y.z). Got '$VERSION'"
37+
exit 1
38+
fi
39+
40+
- name: Checkout code
41+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
42+
43+
- name: Get the release version
44+
id: release_version
45+
shell: bash
46+
# language=bash
47+
run: |
48+
if [[ -n "${{ inputs.version }}" ]]; then
49+
VERSION="${{ inputs.version }}"
50+
echo "Got release version from workflow input: $VERSION"
51+
else
52+
VERSION=$(grep "^current.version=" gradle.properties | cut -d'=' -f2)
53+
echo "Got release version from gradle.properties: $VERSION"
54+
fi
55+
echo "version=$VERSION" >> $GITHUB_OUTPUT
56+
57+
- name: Check if tag exists
58+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
59+
env:
60+
VERSION: ${{ steps.release_version.outputs.version }}
61+
with:
62+
# language=javascript
63+
script: |
64+
const tag = `v${process.env.VERSION}`;
65+
// Check if the tag exists
66+
const { data: tags } = await github.rest.git.listMatchingRefs({
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
ref: `tags/${tag}`
70+
});
71+
if (tags.length > 0) {
72+
core.setFailed(`Tag ${tag} already exists. Bump version in gradle.properties and try releasing again.`);
73+
}
74+
75+
- name: Prepare git name and email
76+
# language=bash
77+
run: |
78+
# Configure git user.name and user.email
79+
# See https://github.com/actions/checkout?tab=readme-ov-file#push-a-commit-using-the-built-in-token
80+
git config user.name "github-actions[bot]"
81+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
82+
83+
- uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2
84+
id: app_token
85+
with:
86+
app-id: ${{ vars.GH_BUMP_VERSION_APP_ID }}
87+
private-key: ${{ secrets.GH_BUMP_VERSION_APP_KEY }}
88+
89+
- name: Update version in gradle.properties to ${{ steps.release_version.outputs.version }}
90+
uses: ./.github/actions/update_version
91+
with:
92+
token: ${{ steps.app_token.outputs.token }}
93+
version: ${{ steps.release_version.outputs.version }}
94+
95+
- name: Set up JDK 21
96+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4
97+
with:
98+
distribution: zulu
99+
java-version: 21
100+
server-id: central
101+
102+
# Publish to Central before generating a tag, so we don't need to drop the tag if
103+
# Central deployment fails.
104+
- name: Publish to Central Portal
105+
uses: burrunan/gradle-cache-action@663fbad34e03c8f12b27f4999ac46e3d90f87eca # v3
106+
with:
107+
arguments: publishPlugins publishAllPublicationsToCentralPortal
108+
# language=properties
109+
properties: |
110+
release=true
111+
centralPortalPublishingType=AUTOMATIC
112+
env:
113+
CENTRAL_PORTAL_USERNAME: ${{ secrets.MAVEN_USER }}
114+
CENTRAL_PORTAL_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
115+
SIGNING_PGP_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
116+
SIGNING_PGP_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
117+
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
118+
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
119+
120+
- name: Publish GitHub release
121+
uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6
122+
id: publish_release
123+
with:
124+
disable-autolabeler: true
125+
publish: true
126+
latest: ${{ github.ref_name == github.event.repository.default_branch }}
127+
version: ${{ steps.release_version.outputs.version }}
128+
env:
129+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130+
131+
- name: Compute the next patch version
132+
id: next_version
133+
# language=bash
134+
run: |
135+
# Compute the next patch version
136+
IFS='.' read -r major minor patch <<< "${{ steps.release_version.outputs.version }}"
137+
next_version="${major}.${minor}.$((patch + 1))"
138+
echo "Next version: $next_version"
139+
echo "version=$next_version" >> "$GITHUB_OUTPUT"
140+
141+
- name: Update version in gradle.properties to ${{ steps.next_version.outputs.version }}
142+
uses: ./.github/actions/update_version
143+
with:
144+
token: ${{ steps.app_token.outputs.token }}
145+
version: ${{ steps.next_version.outputs.version }}

0 commit comments

Comments
 (0)