-
Notifications
You must be signed in to change notification settings - Fork 0
167 lines (140 loc) · 5.2 KB
/
Copy pathprepare-release.yml
File metadata and controls
167 lines (140 loc) · 5.2 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
name: Prepare Release
on:
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
type: choice
options:
- beta
- rc
- stable
default: stable
version_override:
description: 'Version override (optional, e.g., 0.1.0). Defaults to Directory.Build.props without -develop.'
required: false
type: string
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@v5
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: Compute release version
id: version
shell: bash
run: |
if [ -n "${{ github.event.inputs.version_override }}" ]; then
VERSION="${{ github.event.inputs.version_override }}"
else
VERSION=$(sed -n 's|.*<Version>\(.*\)</Version>.*|\1|p' Directory.Build.props | head -1)
VERSION="${VERSION%%-*}"
fi
RELEASE_TYPE="${{ github.event.inputs.release_type }}"
if [ -z "$VERSION" ]; then
echo "::error::Could not resolve release version."
exit 1
fi
if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Release version must be a stable SemVer core like 0.1.0; got '$VERSION'."
exit 1
fi
if [ "$RELEASE_TYPE" = "stable" ]; then
SEMVER="$VERSION"
TAG="v${VERSION}"
else
LATEST_TAG=$(git tag -l "v${VERSION}-${RELEASE_TYPE}.*" --sort=-v:refname | head -1)
if [ -z "$LATEST_TAG" ]; then
NEXT_NUM=1
else
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"
- name: Check for conflicts
shell: bash
run: |
TAG="${{ steps.version.outputs.tag }}"
BRANCH="release/${TAG}"
if git rev-parse "${TAG}" >/dev/null 2>&1; then
echo "::error::Tag ${TAG} already exists."
exit 1
fi
if git ls-remote --heads origin "${BRANCH}" | grep -q .; then
echo "::error::Branch ${BRANCH} already exists on the remote."
exit 1
fi
if curl -fsS https://api.nuget.org/v3-flatcontainer/terminal.gui.cli/index.json \
| jq -r '.versions[]' | grep -Fxq "${{ steps.version.outputs.semver }}"; then
echo "::error::Terminal.Gui.Cli ${{ steps.version.outputs.semver }} already exists on NuGet.org."
echo "::error::Choose a new version_override."
exit 1
fi
if gh pr list --state open --base main --head "${BRANCH}" --json number --jq 'length' | grep -vq '^0$'; then
echo "::error::An open release PR already exists for ${BRANCH}."
exit 1
fi
env:
GH_TOKEN: ${{ secrets.RELEASE_PAT }}
- name: Create release branch
shell: bash
run: |
BRANCH="release/${{ steps.version.outputs.tag }}"
git checkout -b "$BRANCH"
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 }}
shell: bash
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 << EOF2
## Release ${TAG}
${PRERELEASE_NOTE}
**Version:** \`${SEMVER}\`
**NuGet Package:** \`Terminal.Gui.Cli ${SEMVER}\`
### What happens when this PR is merged
1. The **Finalize Release** workflow creates tag \`${TAG}\`
2. The **Release** workflow builds and pushes \`Terminal.Gui.Cli ${SEMVER}\` to NuGet.org
3. A **GitHub Release** is created with auto-generated notes
4. A **back-merge PR** from \`main\` -> \`develop\` is opened
### Checklist
- [ ] CI passes on this PR
- [ ] Version looks correct: \`${SEMVER}\`
- [ ] Release notes reviewed
EOF2
gh pr create \
--base main \
--head "$BRANCH" \
--title "Release ${TAG}" \
--body-file /tmp/pr_body.md