-
Notifications
You must be signed in to change notification settings - Fork 0
447 lines (373 loc) Β· 14.9 KB
/
release-workflows.yml
File metadata and controls
447 lines (373 loc) Β· 14.9 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# .github/workflows/release-workflows.yml
name: π Release Workflow Repository
on:
push:
branches: [ main ]
paths:
- '.github/workflows/**'
- '.github/actions/**'
- 'CHANGELOG.md'
- 'VERSION'
workflow_dispatch:
inputs:
release-type:
description: 'Release type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
pre-release:
description: 'Create pre-release'
required: false
default: false
type: boolean
permissions:
contents: write
pull-requests: write
packages: write
jobs:
detect-changes:
name: π Detect Workflow Changes
runs-on: ubuntu-latest
outputs:
workflows-changed: ${{ steps.changes.outputs.workflows }}
actions-changed: ${{ steps.changes.outputs.actions }}
should-release: ${{ steps.decision.outputs.should-release }}
current-version: ${{ steps.version.outputs.current }}
next-version: ${{ steps.version.outputs.next }}
steps:
- name: π₯ Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: π Detect changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes
with:
filters: |
workflows:
- '.github/workflows/**'
actions:
- '.github/actions/**'
- name: π Get current version
id: version
run: |
if [ -f VERSION ]; then
CURRENT_VERSION=$(cat VERSION)
else
# Get latest tag or default to 0.0.0
CURRENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.0")
fi
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "π Current version: $CURRENT_VERSION"
# Calculate next version based on input or auto-detection
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
RELEASE_TYPE="${{ github.event.inputs.release-type }}"
else
# Auto-detect release type based on changes
if [[ "${{ steps.changes.outputs.workflows }}" == "true" ]]; then
RELEASE_TYPE="minor" # Workflow changes are minor
elif [[ "${{ steps.changes.outputs.actions }}" == "true" ]]; then
RELEASE_TYPE="patch" # Action changes are patch
else
RELEASE_TYPE="patch" # Default to patch
fi
fi
# Parse current version
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR=${VERSION_PARTS[0]:-0}
MINOR=${VERSION_PARTS[1]:-0}
PATCH=${VERSION_PARTS[2]:-0}
# Calculate next version
case "$RELEASE_TYPE" in
"major")
NEXT_VERSION="$((MAJOR + 1)).0.0"
;;
"minor")
NEXT_VERSION="$MAJOR.$((MINOR + 1)).0"
;;
"patch")
NEXT_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
;;
esac
echo "next=$NEXT_VERSION" >> $GITHUB_OUTPUT
echo "π Next version: $NEXT_VERSION ($RELEASE_TYPE)"
- name: π― Release decision
id: decision
run: |
SHOULD_RELEASE=false
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
SHOULD_RELEASE=true
echo "π― Manual release triggered"
elif [[ "${{ steps.changes.outputs.workflows }}" == "true" || "${{ steps.changes.outputs.actions }}" == "true" ]]; then
SHOULD_RELEASE=true
echo "π― Auto-release triggered by workflow/action changes"
fi
echo "should-release=$SHOULD_RELEASE" >> $GITHUB_OUTPUT
echo "π Should release: $SHOULD_RELEASE"
generate-changelog:
name: π Generate Changelog
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.should-release == 'true'
outputs:
changelog-content: ${{ steps.changelog.outputs.content }}
release-notes: ${{ steps.release-notes.outputs.content }}
steps:
- name: π₯ Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: π Generate changelog
id: changelog
run: |
CURRENT_VERSION="${{ needs.detect-changes.outputs.current-version }}"
NEXT_VERSION="${{ needs.detect-changes.outputs.next-version }}"
echo "π Generating changelog for v$NEXT_VERSION"
# Get the last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
echo "π First release, generating initial changelog"
COMMITS=$(git log --oneline --pretty=format:"- %s (%h)" | head -50)
else
echo "π Generating changelog from $LAST_TAG to HEAD"
COMMITS=$(git log --oneline --pretty=format:"- %s (%h)" "$LAST_TAG"..HEAD)
fi
# Categorize commits
FEATURES=""
FIXES=""
CHORES=""
BREAKING=""
while IFS= read -r commit; do
if [[ "$commit" =~ ^-\ (feat|feature) ]]; then
FEATURES+=$'\n'$commit
elif [[ "$commit" =~ ^-\ (fix|bugfix) ]]; then
FIXES+=$'\n'$commit
elif [[ "$commit" =~ ^-\ (BREAKING|breaking) ]]; then
BREAKING+=$'\n'$commit
else
CHORES+=$'\n'$commit
fi
done <<< "$COMMITS"
# Trim leading newlines
FEATURES=${FEATURES#$'\n'}
FIXES=${FIXES#$'\n'}
CHORES=${CHORES#$'\n'}
BREAKING=${BREAKING#$'\n'}
# Create changelog content
cat > CHANGELOG_NEW.md << EOF
# π Release v$NEXT_VERSION
**Release Date**: $(date -u +"%Y-%m-%d")
EOF
if [ -n "$BREAKING" ]; then
cat >> CHANGELOG_NEW.md << EOF
## π₯ Breaking Changes
$BREAKING
EOF
fi
if [ -n "$FEATURES" ]; then
cat >> CHANGELOG_NEW.md << EOF
## β¨ New Features
$FEATURES
EOF
fi
if [ -n "$FIXES" ]; then
cat >> CHANGELOG_NEW.md << EOF
## π Bug Fixes
$FIXES
EOF
fi
if [ -n "$CHORES" ]; then
cat >> CHANGELOG_NEW.md << EOF
## π§ Maintenance
$CHORES
EOF
fi
cat >> CHANGELOG_NEW.md << EOF
## π¦ Workflow Files Changed
EOF
# List changed workflow files
if [ -n "$LAST_TAG" ]; then
CHANGED_WORKFLOWS=$(git diff --name-only "$LAST_TAG"..HEAD -- '.github/workflows/' '.github/actions/' | sort)
else
CHANGED_WORKFLOWS=$(find .github/workflows/ .github/actions/ -name "*.yml" -o -name "*.yaml" | sort)
fi
if [ -n "$CHANGED_WORKFLOWS" ]; then
while IFS= read -r file; do
echo "- \`$file\`" >> CHANGELOG_NEW.md
done <<< "$CHANGED_WORKFLOWS"
else
echo "- No workflow files changed" >> CHANGELOG_NEW.md
fi
if [ -n "$LAST_TAG" ]; then
FULL_CHANGELOG_URL="https://github.com/${{ github.repository }}/compare/$LAST_TAG...v$NEXT_VERSION"
else
FULL_CHANGELOG_URL="https://github.com/${{ github.repository }}/tree/v$NEXT_VERSION"
fi
cat >> CHANGELOG_NEW.md << EOF
## π Links
- **Full Changelog**: $FULL_CHANGELOG_URL
- **Documentation**: https://github.com/${{ github.repository }}/blob/v$NEXT_VERSION/README.md
---
**π€ This release was automatically created by GitHub Actions**
EOF
# Output changelog content
CHANGELOG_CONTENT=$(cat CHANGELOG_NEW.md)
echo "content<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: π Generate release notes
id: release-notes
run: |
NEXT_VERSION="${{ needs.detect-changes.outputs.next-version }}"
cat > RELEASE_NOTES.md << EOF
This release contains updates to the reusable GitHub Actions workflows.
## π― Quick Start
To use these workflows in your repository, reference them like this:
\`\`\`yaml
jobs:
ci:
uses: ${{ github.repository }}/.github/workflows/java-ci-secure.yml@v$NEXT_VERSION
with:
java-version: '25'
\`\`\`
## π Available Workflows
- **java-ci-secure.yml**: Secure Java CI with matrix testing
- **auto-tag-enhanced.yml**: Enhanced auto-tagging and releases
- **auto-delete-branch-enhanced.yml**: Enhanced branch cleanup
- **dependabot-auto-merge-enhanced.yml**: Enhanced Dependabot automation
- **test-workflows.yml**: Workflow testing and validation
## π§ Available Composite Actions
- **setup-java-maven**: Setup Java and Maven with caching
- **docker-build-push**: Build and push Docker images
See the individual workflow files for detailed documentation and usage examples.
EOF
RELEASE_NOTES_CONTENT=$(cat RELEASE_NOTES.md)
echo "content<<EOF" >> $GITHUB_OUTPUT
echo "$RELEASE_NOTES_CONTENT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
create-release:
name: π·οΈ Create Release
runs-on: ubuntu-latest
needs: [detect-changes, generate-changelog]
if: needs.detect-changes.outputs.should-release == 'true'
outputs:
release-url: ${{ steps.create-release.outputs.html_url }}
tag-name: ${{ steps.create-release.outputs.tag_name }}
steps:
- name: π₯ Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: π Update VERSION file
run: |
NEXT_VERSION="${{ needs.detect-changes.outputs.next-version }}"
echo "$NEXT_VERSION" > VERSION
echo "π Updated VERSION file to $NEXT_VERSION"
- name: π Update CHANGELOG.md
env:
CHANGELOG_CONTENT: ${{ needs.generate-changelog.outputs.changelog-content }}
run: |
if [ -f CHANGELOG.md ]; then
# Prepend new changelog to existing file
printf '%s\n\n' "$CHANGELOG_CONTENT" > CHANGELOG_NEW.md
cat CHANGELOG.md >> CHANGELOG_NEW.md
mv CHANGELOG_NEW.md CHANGELOG.md
else
# Create new changelog file
printf '%s\n' "$CHANGELOG_CONTENT" > CHANGELOG.md
fi
echo "π Updated CHANGELOG.md"
- name: π·οΈ Create and push tag
run: |
NEXT_VERSION="${{ needs.detect-changes.outputs.next-version }}"
TAG_NAME="v$NEXT_VERSION"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add VERSION CHANGELOG.md
if git diff --cached --quiet; then
echo "βΉοΈ No documentation updates detected; skipping commit"
else
git commit -m "chore: release $TAG_NAME" -m "Update VERSION and CHANGELOG [skip ci]"
fi
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
git push origin main
git push origin "$TAG_NAME"
echo "β
Created and pushed tag: $TAG_NAME"
- name: π¦ Create GitHub Release
id: create-release
uses: softprops/action-gh-release@a74c6b72af54cfa997e81df42d94703d6313a2d0 # v2.0.6
with:
tag_name: v${{ needs.detect-changes.outputs.next-version }}
name: v${{ needs.detect-changes.outputs.next-version }}
body: ${{ needs.generate-changelog.outputs.release-notes }}
generate_release_notes: true
draft: false
prerelease: ${{ github.event.inputs.pre-release == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
validate-release:
name: β
Validate Release
runs-on: ubuntu-latest
needs: [create-release]
if: needs.create-release.outputs.tag-name != ''
steps:
- name: π₯ Checkout at tag
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: ${{ needs.create-release.outputs.tag-name }}
- name: π οΈ Install YAML tooling
run: |
python3 -m pip install --upgrade pip
python3 -m pip install --quiet pyyaml
- name: β
Validate workflows at tag
run: |
echo "β
Validating workflows at tag ${{ needs.create-release.outputs.tag-name }}"
# Check that all workflow files are valid YAML
find .github/workflows/ -name "*.yml" -o -name "*.yaml" | while read -r file; do
echo "π Validating $file"
python3 -c "import yaml; yaml.safe_load(open('$file'))" || {
echo "β Invalid YAML in $file"
exit 1
}
done
# Check that VERSION file matches tag
TAG_VERSION="${{ needs.create-release.outputs.tag-name }}"
TAG_VERSION=${TAG_VERSION#v}
if [ -f VERSION ]; then
VERSION_CONTENT=$(cat VERSION)
if [ -z "$TAG_VERSION" ]; then
echo "β οΈ No tag name provided; skipping VERSION consistency check"
elif [ "$VERSION_CONTENT" != "$TAG_VERSION" ]; then
echo "β VERSION file ($VERSION_CONTENT) doesn't match tag ($TAG_VERSION)"
exit 1
else
echo "β
VERSION file matches tag"
fi
fi
echo "β
Release validation completed successfully"
notify-release:
name: π’ Notify Release
runs-on: ubuntu-latest
needs: [create-release, validate-release]
if: always() && needs.create-release.result == 'success'
steps:
- name: π’ Create release summary
run: |
echo "π Workflow Repository Release Created!"
echo "======================================"
echo "π·οΈ **Tag**: ${{ needs.create-release.outputs.tag-name }}"
echo "π **URL**: ${{ needs.create-release.outputs.release-url }}"
echo "π
**Date**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")"
echo "π€ **Triggered by**: ${{ github.actor }}"
echo ""
echo "## π Usage"
echo "Reference workflows using the new tag:"
echo "\`\`\`yaml"
echo "uses: ${{ github.repository }}/.github/workflows/java-ci-secure.yml@${{ needs.create-release.outputs.tag-name }}"
echo "\`\`\`"
echo ""
echo "π View release: ${{ needs.create-release.outputs.release-url }}"