-
Notifications
You must be signed in to change notification settings - Fork 0
285 lines (255 loc) · 9.3 KB
/
Copy pathrelease.yml
File metadata and controls
285 lines (255 loc) · 9.3 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
name: Release
on:
# Trigger on push to main for Release PR creation/update
push:
branches:
- main
paths-ignore:
- ".github/ISSUE_TEMPLATE/**"
- ".github/PULL_REQUEST_TEMPLATE/**"
# Trigger on PR events for dry-run checks
pull_request:
types:
- opened
- synchronize
- reopened
branches:
- main
# Manual trigger for emergency releases
workflow_dispatch:
inputs:
mode:
description: "Workflow mode to run"
required: false
type: choice
default: release-pr
options:
- release-pr
- dry-run
force_release:
description: "Force a release even if no changes"
required: false
type: boolean
default: false
head_ref:
description: "Release PR head ref for dispatched dry-run validation"
required: false
type: string
pr_number:
description: "Release PR number for dispatched dry-run validation"
required: false
type: string
concurrency:
group: release-${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
env:
GO_VERSION: "1.25.9"
INITIAL_VERSION: "v0.0.10"
NODE_VERSION: "22"
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
permissions:
actions: write
contents: write
packages: write
pull-requests: write
id-token: write
attestations: write
jobs:
# Job 1: Create or update Release PR
release-pr:
name: Create/Update Release PR
if: |
(github.event_name == 'push' &&
github.ref == 'refs/heads/main' &&
!startsWith(github.event.head_commit.message, 'release:') &&
!startsWith(github.event.head_commit.message, 'ci(release):') &&
!startsWith(github.event.head_commit.message, 'Merge pull request') &&
github.event.head_commit.author.name != 'github-actions[bot]') ||
(github.event_name == 'workflow_dispatch' &&
(inputs.mode == 'release-pr' || inputs.mode == ''))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: ./.github/actions/setup-go
with:
go-version: ${{ env.GO_VERSION }}
install-tools: "false"
- uses: ./.github/actions/setup-node
- uses: ./.github/actions/setup-git-cliff
- name: Build pr-release CLI
run: go build -o bin/pr-release .
- name: Run PR Release Orchestrator
id: pr_release
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
INITIAL_VERSION: ${{ env.INITIAL_VERSION }}
run: |
set -euo pipefail
if [[ "${{ github.event.inputs.force_release }}" == "true" ]]; then
./bin/pr-release pr-release --force --enable-rollback --ci-output
else
./bin/pr-release pr-release --enable-rollback --ci-output
fi
branch="$(git branch --show-current)"
if [[ "$branch" =~ ^release/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "has_release_pr=true" >> "$GITHUB_OUTPUT"
echo "release_branch=$branch" >> "$GITHUB_OUTPUT"
else
echo "No release PR branch produced; skipping release PR checks."
echo "has_release_pr=false" >> "$GITHUB_OUTPUT"
fi
- name: Dispatch Release PR Checks
if: steps.pr_release.outputs.has_release_pr == 'true'
env:
GH_TOKEN: ${{ github.token }}
RELEASE_BRANCH: ${{ steps.pr_release.outputs.release_branch }}
run: |
set -euo pipefail
branch="$RELEASE_BRANCH"
if [[ ! "$branch" =~ ^release/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "::error::Expected to be on a release branch after orchestration, got '$branch'"
exit 1
fi
pr_number="$(gh pr view "$branch" --json number --jq '.number')"
if [[ -z "$pr_number" ]]; then
echo "::error::Could not resolve pull request for $branch"
exit 1
fi
echo "Dispatching CI workflow for $branch"
gh workflow run ci.yml --ref "$branch"
echo "Dispatching release dry-run workflow for $branch (PR #$pr_number)"
gh workflow run release.yml \
--ref "$branch" \
-f mode=dry-run \
-f head_ref="$branch" \
-f pr_number="$pr_number"
# Job 2: Dry-run checks on Release PR
dry-run:
name: Dry-Run Release Check
if: |
(
github.event_name == 'pull_request' &&
(
startsWith(github.event.pull_request.title, 'release: Release ') ||
startsWith(github.event.pull_request.title, 'ci(release): Release ')
)
) ||
(
github.event_name == 'workflow_dispatch' &&
inputs.mode == 'dry-run'
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.head_ref || github.ref }}
- uses: ./.github/actions/setup-go
with:
go-version: ${{ env.GO_VERSION }}
install-tools: false
- uses: ./.github/actions/setup-node
- name: Build pr-release CLI
run: go build -o bin/pr-release .
- name: Setup Release Tools
uses: ./.github/actions/setup-release
with:
goreleaser-distribution: goreleaser-pro
setup-docker: false
setup-docker-login: false
- name: Run Dry-Run Orchestrator
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
GITHUB_HEAD_REF: ${{ github.event_name == 'workflow_dispatch' && inputs.head_ref || github.head_ref }}
GITHUB_ISSUE_NUMBER: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }}
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
run: ./bin/pr-release dry-run --ci-output
# Job 3: Production release on merge
release:
name: Production Release
if: |
github.event_name == 'push' &&
github.ref == 'refs/heads/main' &&
(
startsWith(github.event.head_commit.message, 'release:') ||
startsWith(github.event.head_commit.message, 'ci(release):')
)
runs-on: ubuntu-latest
timeout-minutes: 120
env:
DOCKER_CLI_EXPERIMENTAL: enabled
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up Go with caching
uses: ./.github/actions/setup-go
with:
go-version: ${{ env.GO_VERSION }}
install-tools: "true"
- uses: ./.github/actions/setup-node
- name: Setup Release Tools
uses: ./.github/actions/setup-release
with:
goreleaser-distribution: goreleaser-pro
setup-docker: true
setup-docker-login: true
setup-qemu: true
docker-registry: ghcr.io
docker-username: ${{ github.actor }}
docker-token: ${{ secrets.GITHUB_TOKEN }}
cosign-version: "v2.2.4"
- name: Create Git Tag
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
# Use git-cliff to get the bumped version
VERSION=$(git cliff --bumped-version 2>/dev/null | sed 's/^v//')
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin "v$VERSION"
echo "Created and pushed tag v$VERSION"
else
echo "Could not get version from git-cliff. Got: $VERSION"
echo "Fallback: Extract from commit message"
VERSION=$(git log -1 --pretty=format:"%s" | sed -E 's/.*Release v([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin "v$VERSION"
echo "Created and pushed tag v$VERSION"
else
echo "Could not extract version from any source. Got: $VERSION"
exit 1
fi
fi
- uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
version: ~> v2
args: >-
release --clean
--release-notes=RELEASE_BODY.md
--release-header-tmpl=.goreleaser.release-header.md.tmpl
--release-footer-tmpl=.goreleaser.release-footer.md.tmpl
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
AUR_KEY: ${{ secrets.AUR_KEY }}
COSIGN_EXPERIMENTAL: 1
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}