-
Notifications
You must be signed in to change notification settings - Fork 782
208 lines (172 loc) · 7.07 KB
/
Copy pathprepare-release.yml
File metadata and controls
208 lines (172 loc) · 7.07 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
name: Prepare Release
# Creates a release PR from develop → main.
# Maintainers trigger this from Actions → Prepare Release → Run workflow.
# After reviewing, merge the PR — the "Finalize Release" workflow handles the rest.
on:
workflow_dispatch:
inputs:
release_type:
description: 'Release type (controls the pre-release label on main)'
required: true
type: choice
options:
- beta
- rc
- stable
default: 'beta'
version_override:
description: 'Version override (optional, e.g., 2.0.0). Leave blank to let GitVersion calculate it.'
required: false
type: string
# Prevent two prepare-release runs from picking the same version number
concurrency:
group: prepare-release
cancel-in-progress: false
jobs:
prepare-release:
name: Create Release PR
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout develop
uses: actions/checkout@v7
with:
ref: develop
fetch-depth: 0
token: ${{ secrets.RELEASE_PAT }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v4.7.0
with:
versionSpec: '6.x'
- name: Determine Version
uses: gittools/actions/gitversion/execute@v4.7.0
with:
useConfigFile: true
id: gitversion
- name: Compute release version
id: version
run: |
if [ -n "${{ github.event.inputs.version_override }}" ]; then
VERSION="${{ github.event.inputs.version_override }}"
else
VERSION="${{ steps.gitversion.outputs.MajorMinorPatch }}"
fi
RELEASE_TYPE="${{ github.event.inputs.release_type }}"
if [ "$RELEASE_TYPE" = "stable" ]; then
SEMVER="${VERSION}"
TAG="v${VERSION}"
else
# Find the latest existing tag for this version + release type
# and increment the pre-release number.
# --sort=-v:refname gives correct numeric ordering (e.g., .9 before .10)
LATEST_TAG=$(git tag -l "v${VERSION}-${RELEASE_TYPE}.*" --sort=-v:refname | head -1)
if [ -z "$LATEST_TAG" ]; then
NEXT_NUM=1
else
# Extract the trailing number: v2.0.0-beta.217 → 217
CURRENT_NUM="${LATEST_TAG##*.}"
NEXT_NUM=$((CURRENT_NUM + 1))
fi
SEMVER="${VERSION}-${RELEASE_TYPE}.${NEXT_NUM}"
TAG="v${SEMVER}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "semver=${SEMVER}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "release_type=${RELEASE_TYPE}" >> $GITHUB_OUTPUT
echo "::notice::Computed version: ${SEMVER} (tag: ${TAG})"
- name: Check for conflicts
run: |
TAG="${{ steps.version.outputs.tag }}"
# Ensure tag does not already exist
if git rev-parse "${TAG}" >/dev/null 2>&1; then
echo "::error::Tag ${TAG} already exists."
echo "::error::Choose a different version or delete the existing tag first."
exit 1
fi
# Ensure no release branch or open PR already targets this version
BRANCH="release/${TAG}"
if git ls-remote --heads origin "${BRANCH}" | grep -q .; then
echo "::error::Branch ${BRANCH} already exists on the remote."
echo "::error::Delete it first or choose a different version."
exit 1
fi
- name: Create release branch
run: |
BRANCH="release/${{ steps.version.outputs.tag }}"
git checkout -b "$BRANCH"
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
id: branch
- name: Update GitVersion.yml label for release type
run: |
RELEASE_TYPE="${{ steps.version.outputs.release_type }}"
if [ "$RELEASE_TYPE" = "stable" ]; then
NEW_LABEL="''"
else
NEW_LABEL="${RELEASE_TYPE}"
fi
# Update the label line that follows the main branch regex.
sed -i "/regex: \^main/,/^ [a-z]/{s/^ label: .*/ label: ${NEW_LABEL}/}" GitVersion.yml
echo "Updated GitVersion.yml main label to: '${NEW_LABEL}'"
grep -A 5 "^ main:" GitVersion.yml
- name: Commit label change
run: |
if git diff --quiet GitVersion.yml; then
echo "No label change needed"
else
git add GitVersion.yml
git commit -m "Set release label to '${{ steps.version.outputs.release_type }}' for ${{ steps.version.outputs.tag }}"
fi
- name: Push release branch
run: |
BRANCH="release/${{ steps.version.outputs.tag }}"
git push origin "$BRANCH"
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.RELEASE_PAT }}
SEMVER: ${{ steps.version.outputs.semver }}
TAG: ${{ steps.version.outputs.tag }}
RELEASE_TYPE: ${{ steps.version.outputs.release_type }}
run: |
BRANCH="release/${TAG}"
if [ "$RELEASE_TYPE" = "stable" ]; then
PRERELEASE_NOTE=""
else
PRERELEASE_NOTE="This is a **${RELEASE_TYPE}** pre-release."
fi
cat > /tmp/pr_body.md << EOF
## Release ${TAG}
${PRERELEASE_NOTE}
**Version:** \`${SEMVER}\`
**NuGet Package:** \`Terminal.Gui ${SEMVER}\`
### What happens when this PR is merged
1. ✅ The **Finalize Release** workflow will automatically create tag \`${TAG}\`
2. ✅ The **Publish** workflow will build and push to [NuGet.org](https://www.nuget.org/packages/Terminal.Gui)
3. ✅ A **GitHub Release** will be created with auto-generated notes
4. ✅ A **back-merge PR** from \`main\` → \`develop\` will be opened
### Checklist
- [ ] CI passes on this PR
- [ ] Version looks correct: \`${SEMVER}\`
- [ ] Release notes reviewed (will be auto-generated on merge)
EOF
gh pr create \
--base main \
--head "$BRANCH" \
--title "Release ${TAG}" \
--body-file /tmp/pr_body.md
- name: Summary
run: |
echo "## Release PR Created :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ steps.version.outputs.semver }}" >> $GITHUB_STEP_SUMMARY
echo "- **Tag:** ${{ steps.version.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **Type:** ${{ steps.version.outputs.release_type }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch:** release/${{ steps.version.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Review and merge the PR to trigger the release." >> $GITHUB_STEP_SUMMARY