-
Notifications
You must be signed in to change notification settings - Fork 5
241 lines (207 loc) · 8.55 KB
/
auto-release.yml
File metadata and controls
241 lines (207 loc) · 8.55 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Auto Release Bundle
on:
push:
branches: [main]
paths:
- 'extensions/**/pom.xml'
concurrency:
group: auto-release
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
env:
MAVEN_OPTS: >-
-Xmx4g
-Dorg.slf4j.simpleLogger.defaultLogLevel=WARN
jobs:
detect-release:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[auto-release]')"
outputs:
bundles: ${{ steps.detect.outputs.bundles }}
has_releases: ${{ steps.detect.outputs.has_releases }}
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Detect Release-Ready Bundles
id: detect
run: |
RELEASE_BUNDLES=()
CHANGED_POMS=$(git diff --name-only HEAD~1 HEAD -- 'extensions/**/pom.xml')
for pom in $CHANGED_POMS; do
dir=$(dirname "$pom")
# Only consider bundle aggregator POMs (with <modules>)
if ! grep -q '<modules>' "$pom" 2>/dev/null; then
continue
fi
# Extract the current version from the <revision> property (CI-friendly versions)
VERSION=$(grep '<revision>' "$pom" | sed 's/.*<revision>\(.*\)<\/revision>.*/\1/' | tr -d ' ')
# Check if version is a release (not SNAPSHOT)
if [[ "$VERSION" != *-SNAPSHOT ]]; then
echo "Release detected: $dir @ $VERSION"
RELEASE_BUNDLES+=("{\"path\":\"$dir\",\"version\":\"$VERSION\"}")
fi
done
if [ ${#RELEASE_BUNDLES[@]} -eq 0 ]; then
echo "bundles=[]" >> $GITHUB_OUTPUT
echo "has_releases=false" >> $GITHUB_OUTPUT
else
JSON=$(printf '%s\n' "${RELEASE_BUNDLES[@]}" | jq -sc .)
echo "bundles=$JSON" >> $GITHUB_OUTPUT
echo "has_releases=true" >> $GITHUB_OUTPUT
echo "Bundles to release: $JSON"
fi
release:
needs: detect-release
if: needs.detect-release.outputs.has_releases == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1
matrix:
bundle: ${{ fromJson(needs.detect-release.outputs.bundles) }}
name: Release ${{ matrix.bundle.path }} v${{ matrix.bundle.version }}
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Set up Java 21
uses: actions/setup-java@v5
with:
distribution: 'corretto'
java-version: '21'
cache: 'maven'
- name: Build and Verify
run: >
./mvnw clean verify
-Pcontrib-check
-f ${{ matrix.bundle.path }}/pom.xml
--show-version
--no-snapshot-updates
--no-transfer-progress
- name: Extract Artifact Info
id: artifact
run: |
BUNDLE_PATH="${{ matrix.bundle.path }}"
ARTIFACT_ID=$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout -f "$BUNDLE_PATH/pom.xml")
echo "artifact_id=$ARTIFACT_ID" >> $GITHUB_OUTPUT
TAG_NAME="${ARTIFACT_ID}-${{ matrix.bundle.version }}"
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
- name: Find NAR File
id: nar
run: |
NAR_FILE=$(find ${{ matrix.bundle.path }} -name "*.nar" -path "*/target/*" | head -1)
if [ -n "$NAR_FILE" ]; then
echo "nar_file=$NAR_FILE" >> $GITHUB_OUTPUT
echo "has_nar=true" >> $GITHUB_OUTPUT
else
echo "has_nar=false" >> $GITHUB_OUTPUT
fi
- name: Create Git Tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.artifact.outputs.tag_name }}" -m "Release ${{ steps.artifact.outputs.artifact_id }} ${{ matrix.bundle.version }}"
git push origin "${{ steps.artifact.outputs.tag_name }}"
- name: Generate Release Notes
id: notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ARTIFACT_ID="${{ steps.artifact.outputs.artifact_id }}"
BUNDLE_PATH="${{ matrix.bundle.path }}"
CURRENT_TAG="${{ steps.artifact.outputs.tag_name }}"
REPO="${{ github.repository }}"
NOTES_FILE="${RUNNER_TEMP}/release-notes.md"
PREV_TAG=$(git tag --list "${ARTIFACT_ID}-*" --sort=-version:refname | grep -v "^${CURRENT_TAG}$" | head -1)
echo "## What's Changed" > "$NOTES_FILE"
echo "" >> "$NOTES_FILE"
if [ -n "$PREV_TAG" ]; then
LOG_RANGE="${PREV_TAG}..${CURRENT_TAG}"
else
LOG_RANGE=""
fi
FOUND_ENTRIES=false
git log $LOG_RANGE --format="%s" -- "$BUNDLE_PATH" | while IFS= read -r subject; do
PR_NUM=$(echo "$subject" | grep -oP '\(#\K[0-9]+(?=\))' || true)
if [ -n "$PR_NUM" ]; then
PR_JSON=$(gh pr view "$PR_NUM" --json title,author,number --jq '{title: .title, author: .author.login, number: .number}' 2>/dev/null || true)
if [ -n "$PR_JSON" ]; then
PR_TITLE=$(echo "$PR_JSON" | jq -r .title)
PR_AUTHOR=$(echo "$PR_JSON" | jq -r .author)
echo "* ${PR_TITLE} by @${PR_AUTHOR} in [#${PR_NUM}](https://github.com/${REPO}/pull/${PR_NUM})" >> "$NOTES_FILE"
else
echo "* ${subject}" >> "$NOTES_FILE"
fi
else
echo "* ${subject}" >> "$NOTES_FILE"
fi
FOUND_ENTRIES=true
done
if ! grep -q '^\*' "$NOTES_FILE"; then
echo "* Initial release" >> "$NOTES_FILE"
fi
if [ -n "$PREV_TAG" ]; then
echo "" >> "$NOTES_FILE"
echo "**Full diff**: [\`${PREV_TAG}...${CURRENT_TAG}\`](https://github.com/${REPO}/compare/${PREV_TAG}...${CURRENT_TAG})" >> "$NOTES_FILE"
fi
echo "notes_file=$NOTES_FILE" >> $GITHUB_OUTPUT
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RELEASE_ARGS=(
"${{ steps.artifact.outputs.tag_name }}"
--title "${{ steps.artifact.outputs.artifact_id }} ${{ matrix.bundle.version }}"
--notes-file "${{ steps.notes.outputs.notes_file }}"
)
if [ "${{ steps.nar.outputs.has_nar }}" = "true" ]; then
RELEASE_ARGS+=("${{ steps.nar.outputs.nar_file }}")
fi
gh release create "${RELEASE_ARGS[@]}"
- name: Bump to Next SNAPSHOT Version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git pull origin main
ARTIFACT_ID="${{ steps.artifact.outputs.artifact_id }}"
RELEASE_VERSION="${{ matrix.bundle.version }}"
MAJOR=$(echo "$RELEASE_VERSION" | cut -d. -f1)
MINOR=$(echo "$RELEASE_VERSION" | cut -d. -f2)
PATCH=$(echo "$RELEASE_VERSION" | cut -d. -f3)
NEXT_PATCH=$((PATCH + 1))
NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-SNAPSHOT"
BRANCH="auto-release/${ARTIFACT_ID}-${NEXT_VERSION}"
git checkout -b "$BRANCH"
./mvnw versions:set-property \
-Dproperty=revision \
-DnewVersion="$NEXT_VERSION" \
-DgenerateBackupPoms=false \
-f ${{ matrix.bundle.path }}/pom.xml
git add -A
git commit -m "[auto-release] Prepare ${ARTIFACT_ID} ${NEXT_VERSION} for next development iteration"
git push origin "$BRANCH"
gh pr create \
--base main \
--head "$BRANCH" \
--title "[auto-release] Prepare ${ARTIFACT_ID} ${NEXT_VERSION}" \
--body "Automated version bump after release of **${ARTIFACT_ID}** ${RELEASE_VERSION}. Prepares the next development iteration." \
--label "infra"