-
Notifications
You must be signed in to change notification settings - Fork 438
169 lines (152 loc) · 6.43 KB
/
release-generators.yml
File metadata and controls
169 lines (152 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Release Generators
on:
workflow_dispatch:
inputs:
release_version:
description: "Release version (format: 1.X.Y)"
required: false
default: ""
type: string
next_snapshot:
description: "Next snapshot version (format: 1.X.Y-SNAPSHOT)"
required: false
default: ""
type: string
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Require master branch
run: |
if [ "${GITHUB_REF_NAME}" != "master" ]; then
echo "This workflow can run only from branch master (current: ${GITHUB_REF_NAME})."
exit 1
fi
- name: Checkout master
uses: actions/checkout@v6
with:
ref: master
fetch-depth: 0
- name: Set up Java 11
uses: actions/setup-java@v5
with:
java-version: "11"
distribution: temurin
cache: maven
overwrite-settings: false
- name: Add Maven settings
uses: s4u/maven-settings-action@v4.0.0
with:
repositories: '[{"id":"central-portal-snapshots","name":"Sonatype Central Portal snapshots","url":"https://central.sonatype.com/repository/maven-snapshots/","releases":{"enabled":false},"snapshots":{"enabled":true}}]'
servers: '[{"id":"central","username":"${{ secrets.MAVEN_CENTRAL_USERNAME }}","password":"${{ secrets.MAVEN_CENTRAL_PASSWORD }}"}]'
- name: Validate inputs and repo version
id: resolve
run: |
set -euo pipefail
POM_VERSION="$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)"
POM_RELEASE_VERSION="${POM_VERSION%-SNAPSHOT}"
RELEASE_VERSION="${{ inputs.release_version }}"
if [ -z "${RELEASE_VERSION}" ]; then
RELEASE_VERSION="${POM_RELEASE_VERSION}"
fi
if [[ ! "$RELEASE_VERSION" =~ ^1\.[0-9]+\.[0-9]+$ ]]; then
echo "release_version must match 1.X.Y"
exit 1
fi
NEXT_SNAPSHOT="${{ inputs.next_snapshot }}"
if [ -z "${NEXT_SNAPSHOT}" ]; then
IFS='.' read -r major minor patch <<< "${RELEASE_VERSION}"
NEXT_SNAPSHOT="${major}.${minor}.$((patch + 1))-SNAPSHOT"
fi
if [[ ! "$NEXT_SNAPSHOT" =~ ^1\.[0-9]+\.[0-9]+-SNAPSHOT$ ]]; then
echo "next_snapshot must match 1.X.Y-SNAPSHOT"
exit 1
fi
if [[ "${POM_VERSION}" == *-SNAPSHOT ]]; then
echo "master pom.xml version (${POM_VERSION}) is a snapshot. Merge the prepare-release PR first, then rerun this workflow."
exit 1
fi
if [[ "${POM_VERSION}" != "${RELEASE_VERSION}" ]]; then
echo "master pom.xml version (${POM_VERSION}) must match release_version (${RELEASE_VERSION})"
exit 1
fi
echo "release_version=${RELEASE_VERSION}" >> "$GITHUB_OUTPUT"
echo "next_snapshot=${NEXT_SNAPSHOT}" >> "$GITHUB_OUTPUT"
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }}
- name: Build generators with release version
run: ./mvnw -Prelease clean verify -U --settings "$HOME/.m2/settings.xml"
- name: Publish prepared draft release notes
# Publishes the draft release created in prepare-release workflow.
uses: actions/github-script@v8
with:
script: |
const tag = `v${{ steps.resolve.outputs.release_version }}`;
const owner = context.repo.owner;
const repo = context.repo.repo;
const releases = await github.paginate(github.rest.repos.listReleases, {
owner,
repo,
per_page: 100,
});
const release = releases.find((r) => r.tag_name === tag);
if (!release) {
core.setFailed(`Expected prepared draft release for tag ${tag}, but it was not found.`);
return;
}
if (!release.draft) {
core.info(`Release ${tag} is already published.`);
return;
}
await github.rest.repos.updateRelease({
owner,
repo,
release_id: release.id,
draft: false,
});
core.info(`Published release ${tag}.`);
- name: Bump to next snapshot
id: bump
run: |
set -euo pipefail
BRANCH="post-release-${{ steps.resolve.outputs.release_version }}-snapshot-bump"
NEXT_SNAPSHOT="${{ steps.resolve.outputs.next_snapshot }}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git fetch origin "${BRANCH}" || true
if git show-ref --verify --quiet "refs/remotes/origin/${BRANCH}"; then
git checkout -B "${BRANCH}" "origin/${BRANCH}"
git reset --hard "${GITHUB_SHA}"
else
git checkout -B "${BRANCH}"
fi
mvn -q -B versions:set -DnewVersion="${NEXT_SNAPSHOT}" -DgenerateBackupPoms=false
git add pom.xml
if git diff --cached --quiet; then
echo "No pom.xml changes to commit."
else
git commit -m "chore: bump snapshot to ${NEXT_SNAPSHOT}"
fi
git push --force-with-lease origin "${BRANCH}"
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
- name: Create or update post-release snapshot PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
BRANCH="${{ steps.bump.outputs.branch }}"
TITLE="chore: bump snapshot to ${{ steps.resolve.outputs.next_snapshot }}"
BODY="Post-release snapshot bump after v${{ steps.resolve.outputs.release_version }} publication."
EXISTING="$(gh pr list --base master --head "${BRANCH}" --state open --json number --jq '.[0].number' || true)"
if [ -n "${EXISTING}" ]; then
echo "PR #${EXISTING} already exists; updating title and body."
gh pr edit "${EXISTING}" --title "${TITLE}" --body "${BODY}"
else
gh pr create --base master --head "${BRANCH}" --title "${TITLE}" --body "${BODY}"
fi