-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (119 loc) · 4.69 KB
/
Copy pathmanual-release.yml
File metadata and controls
143 lines (119 loc) · 4.69 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
name: Manual Release
on:
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Validate changelog has unreleased content
run: |
# Extract content between [Unreleased] and next ## [
UNRELEASED_CONTENT=$(sed -n '/^## \[Unreleased\]/,/^## \[/p' CHANGELOG.md | sed '1d;$d' | sed '/^$/d')
if [ -z "$UNRELEASED_CONTENT" ]; then
echo "Error: No content in [Unreleased] section. Nothing to release."
exit 1
fi
echo "Found unreleased content:"
echo "$UNRELEASED_CONTENT"
- name: Calculate new version
id: version
env:
VERSION_BUMP: ${{ inputs.version_bump }}
run: |
# Get current version from the latest git tag
CURRENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.4.0")
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
case "$VERSION_BUMP" in
major)
NEW_VERSION="$((MAJOR + 1)).0.0"
;;
minor)
NEW_VERSION="$MAJOR.$((MINOR + 1)).0"
;;
patch)
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
;;
esac
echo "Current version: $CURRENT_VERSION"
echo "New version: $NEW_VERSION"
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Extract release notes from changelog
run: |
# Extract content between [Unreleased] and next ## [ heading
# Remove the first line ([Unreleased]) and last line (next version header)
RELEASE_NOTES=$(sed -n '/^## \[Unreleased\]/,/^## \[/p' CHANGELOG.md | sed '1d;$d')
# Write to file for use in release (handles multiline properly)
echo "$RELEASE_NOTES" > release_notes.md
echo "Release notes extracted:"
cat release_notes.md
- name: Update CHANGELOG.md
env:
NEW_VERSION: ${{ steps.version.outputs.new }}
CURRENT_VERSION: ${{ steps.version.outputs.current }}
run: |
TODAY=$(date +%Y-%m-%d)
# Replace [Unreleased] with new version, and add new [Unreleased] section
sed -i "s/^## \[Unreleased\]$/## [Unreleased]\n\n## [$NEW_VERSION] - $TODAY/" CHANGELOG.md
# Update the comparison links at the bottom
# Change: [Unreleased]: .../compare/vX.Y.Z...HEAD
# To: [Unreleased]: .../compare/vNEW...HEAD
sed -i "s|\[Unreleased\]: \(.*\)/compare/v${CURRENT_VERSION}\.\.\.HEAD|[Unreleased]: \1/compare/v${NEW_VERSION}...HEAD|" CHANGELOG.md
# Add new version link after [Unreleased] link
sed -i "/^\[Unreleased\]:.*HEAD$/a [$NEW_VERSION]: https://github.com/itk-dev/itkdev-claude-plugins/compare/v${CURRENT_VERSION}...v${NEW_VERSION}" CHANGELOG.md
echo "Updated CHANGELOG.md:"
head -30 CHANGELOG.md
echo "..."
tail -10 CHANGELOG.md
- name: Commit changes
env:
NEW_VERSION: ${{ steps.version.outputs.new }}
run: |
git add CHANGELOG.md
git commit -m "chore: prepare release v${NEW_VERSION}"
- name: Create and push tag
env:
NEW_VERSION: ${{ steps.version.outputs.new }}
run: |
TAG="v${NEW_VERSION}"
git tag -a "$TAG" -m "Release $TAG"
git push origin main
git push origin "$TAG"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_VERSION: ${{ steps.version.outputs.new }}
CURRENT_VERSION: ${{ steps.version.outputs.current }}
run: |
TAG="v${NEW_VERSION}"
# Build release notes with header and footer
{
echo "## What's Changed"
echo ""
cat release_notes.md
echo ""
echo "## Full Changelog"
echo "https://github.com/itk-dev/itkdev-claude-plugins/compare/v${CURRENT_VERSION}...v${NEW_VERSION}"
} > full_release_notes.md
gh release create "$TAG" \
--title "Release $TAG" \
--notes-file full_release_notes.md
echo "Created release: $TAG"