-
Notifications
You must be signed in to change notification settings - Fork 0
271 lines (234 loc) · 9.53 KB
/
release.yml
File metadata and controls
271 lines (234 loc) · 9.53 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
name: Release and Marketplace
# This workflow handles automatic semantic versioning, tagging, and GitHub Marketplace submission
# It runs when changes are pushed to main and creates releases based on changelog entries
on:
push:
branches: [main]
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.2.3 or major/minor/patch)'
required: true
default: 'patch'
jobs:
check-changelog:
name: Check Changelog
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
has_unreleased: ${{ steps.check.outputs.has_unreleased }}
release_notes: ${{ steps.extract.outputs.release_notes }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for unreleased changes
id: check
run: |
if grep -q "## \[Unreleased\]" CHANGELOG.md; then
# Check if there's actual content under Unreleased
if grep -A 20 "## \[Unreleased\]" CHANGELOG.md | \
grep -qE "^### (Added|Changed|Deprecated|Removed|Fixed|Security)"; then
echo "has_unreleased=true" >> $GITHUB_OUTPUT
echo "✓ Found unreleased changes in CHANGELOG.md"
else
echo "has_unreleased=false" >> $GITHUB_OUTPUT
echo "No unreleased changes found in CHANGELOG.md"
fi
else
echo "has_unreleased=false" >> $GITHUB_OUTPUT
echo "No Unreleased section found in CHANGELOG.md"
fi
- name: Extract release notes
id: extract
if: steps.check.outputs.has_unreleased == 'true'
run: |
# Extract content between [Unreleased] and the next version heading
NOTES=$(awk '/## \[Unreleased\]/,/^## \[/' CHANGELOG.md | sed '1d;$d' | sed '/^$/d')
# Save to output (handle multiline)
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
echo "$NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "Extracted release notes:"
echo "$NOTES"
determine-version:
name: Determine Next Version
runs-on: ubuntu-latest
permissions:
contents: read
needs: check-changelog
if: needs.check-changelog.outputs.has_unreleased == 'true' || github.event_name == 'workflow_dispatch'
outputs:
new_version: ${{ steps.determine-version.outputs.new_version }}
previous_version: ${{ steps.determine-version.outputs.previous_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get latest tag
id: get-latest-tag
run: |
# Get the latest semantic version tag
LATEST_TAG=$(git tag -l 'v*.*.*' | sort -V | tail -n 1)
if [ -z "$LATEST_TAG" ]; then
echo "No previous version tags found, starting with v1.0.0"
echo "latest_tag=v0.0.0" >> $GITHUB_OUTPUT
else
echo "Latest tag: $LATEST_TAG"
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
fi
- name: Determine version bump
id: determine-version
run: |
LATEST_TAG="${{ steps.get-latest-tag.outputs.latest_tag }}"
# Remove 'v' prefix for version manipulation
CURRENT_VERSION=${LATEST_TAG#v}
# Parse version parts
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]:-0}"
MINOR="${VERSION_PARTS[1]:-0}"
PATCH="${VERSION_PARTS[2]:-0}"
# Determine bump type
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
BUMP_TYPE="${{ github.event.inputs.version }}"
else
# Auto-detect from changelog or default to patch
BUMP_TYPE="patch"
# Check changelog for breaking changes or new features
if grep -A 20 "## \[Unreleased\]" CHANGELOG.md | grep -q "^### Changed" || \
grep -A 20 "## \[Unreleased\]" CHANGELOG.md | grep -q "BREAKING"; then
BUMP_TYPE="minor"
fi
fi
echo "Bump type: $BUMP_TYPE"
# Check if BUMP_TYPE is a specific version (e.g., 1.0.0 or v1.0.0)
if [[ "$BUMP_TYPE" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# Strip 'v' prefix if present
BUMP_TYPE="${BUMP_TYPE#v}"
echo "Using specific version: $BUMP_TYPE"
NEW_VERSION="v${BUMP_TYPE}"
else
# Apply semantic version bump
case "$BUMP_TYPE" in
major|MAJOR)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor|MINOR)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch|PATCH|*)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
MTAG="v${MAJOR}"
fi
echo "Previous version: $LATEST_TAG"
echo "New version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "previous_version=$LATEST_TAG" >> $GITHUB_OUTPUT
create-release:
name: Create Release
runs-on: ubuntu-latest
needs:
- check-changelog
- determine-version
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Update CHANGELOG with version
run: |
NEW_VERSION="${{ needs.determine-version.outputs.new_version }}"
TODAY=$(date +%Y-%m-%d)
# Replace [Unreleased] with the new version
sed -i "s/## \[Unreleased\]/## [${NEW_VERSION#v}] - $TODAY\n\n## [Unreleased]/" CHANGELOG.md
echo "Updated CHANGELOG.md with version $NEW_VERSION"
- name: Commit changelog update
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add CHANGELOG.md
git commit -m "Update CHANGELOG for ${{ needs.determine-version.outputs.new_version }}"
git push
- name: Create and push tag
run: |
NEW_VERSION="${{ needs.determine-version.outputs.new_version }}"
git tag -a "$NEW_VERSION" -m "Release $NEW_VERSION"
git push origin "$NEW_VERSION"
echo "✓ Created and pushed tag $NEW_VERSION"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.determine-version.outputs.new_version }}
name: Release ${{ needs.determine-version.outputs.new_version }}
body: |
${{ needs.check-changelog.outputs.release_notes }}
---
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ needs.determine-version.outputs.previous_version }}...${{ needs.determine-version.outputs.new_version }}
draft: false
prerelease: false
- name: Update major version tag
run: |
NEW_VERSION="${{ needs.determine-version.outputs.new_version }}"
MAJOR_VERSION=$(echo "$NEW_VERSION" | cut -d. -f1)
# Force update the major version tag (e.g., v1)
git tag -fa "$MAJOR_VERSION" -m "Update $MAJOR_VERSION to $NEW_VERSION"
git push origin "$MAJOR_VERSION" --force
echo "✓ Updated major version tag $MAJOR_VERSION"
marketplace-submission:
name: Marketplace Submission Info
runs-on: ubuntu-latest
permissions:
contents: read
needs: create-release
steps:
- name: Marketplace submission info
run: |
echo "🎉 Release created successfully!"
echo ""
echo "📦 GitHub Marketplace Submission:"
echo "This action is configured for GitHub Marketplace in action.yml"
echo ""
echo "To publish to the marketplace:"
echo "1. Go to: https://github.com/${{ github.repository }}/releases"
echo "2. Edit the latest release"
echo "3. Check 'Publish this Action to the GitHub Marketplace'"
echo "4. Review and accept the terms"
echo "5. Click 'Update release'"
echo ""
echo "The action.yml already includes marketplace metadata:"
echo " - Name: Python Unit Testing"
echo " - Description: Run Python tests using pytest, generate SVG badges for test results, and optionally commit the badges to the repository."
echo " - Author: Jason Miller"
echo " - Branding: check-circle icon, green color"
workflow-summary:
name: Release Summary
runs-on: ubuntu-latest
permissions:
contents: read
needs:
- determine-version
- create-release
- marketplace-submission
steps:
- name: Summary
run: |
echo "✅ Release workflow completed successfully!"
echo ""
echo "Release details:"
echo " Version: ${{ needs.determine-version.outputs.new_version }}"
echo " Previous: ${{ needs.determine-version.outputs.previous_version }}"
echo ""
echo "Next steps:"
echo " - Verify release at: https://github.com/${{ github.repository }}/releases"
echo " - Publish to GitHub Marketplace if desired"