Repository navigation
355 lines (335 loc) · 13.3 KB
/
Copy pathrelease.yml
File metadata and controls
355 lines (335 loc) · 13.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
name: Release
# Manual release only
on:
workflow_dispatch:
inputs:
tag:
description: "Release tag (example: 1.2.3 or 1.2.3-rc.1)"
required: true
type: string
permissions:
contents: write
jobs:
resolve:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.resolve_version.outputs.version }}
is_prerelease: ${{ steps.resolve_version.outputs.is_prerelease }}
steps:
- name: Resolve release version
id: resolve_version
run: |
if [ "${{ github.event_name }}" = "push" ]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION="${{ github.event.inputs.tag }}"
fi
if [ -z "${VERSION}" ]; then
echo "Error: VERSION is empty"
exit 1
fi
if [[ "${VERSION}" == v* ]]; then
echo "Error: tags must not use 'v' prefix (got: ${VERSION})"
exit 1
fi
if ! [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
echo "Error: VERSION must be SemVer-like (got: ${VERSION})"
exit 1
fi
BASE_VERSION="${VERSION%%+*}"
if [[ "${BASE_VERSION}" == *-* ]]; then
IS_PRERELEASE=true
else
IS_PRERELEASE=false
fi
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "is_prerelease=${IS_PRERELEASE}" >> "${GITHUB_OUTPUT}"
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- name: Run linter
uses: golangci/golangci-lint-action@v9
with:
version: v2.12.2
args: --timeout=5m
# The microsandbox SDK's FFI bridge is cgo (dlopen-based), so every binary
# must be built with CGO_ENABLED=1 on a toolchain that can target it:
# native runners per platform, cross-cgo (gcc-aarch64-linux-gnu) for
# linux/arm64. Plain GOOS/GOARCH cross builds drop the cgo files and fail
# with "build constraints exclude all Go files" in internal/ffi.
test-linux-amd64:
runs-on: ubuntu-latest
needs: resolve
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- name: Run tests
run: make test-ci
- name: Build linux/amd64
env:
VERSION: ${{ needs.resolve.outputs.version }}
run: |
./scripts/embed-msb-runtime.sh
mkdir -p dist
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags msbembed -ldflags "-s -w" -o dist/construct-linux-amd64 ./cmd/construct
- name: Report artifact size delta
run: du -h dist/construct-linux-amd64
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: construct-linux-amd64
path: dist/construct-linux-amd64
if-no-files-found: error
retention-days: 2
build-linux-arm64:
runs-on: ubuntu-latest
needs: resolve
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- name: Install aarch64 cross toolchain
run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Build linux/arm64 (cross-cgo)
run: |
GOOS=linux GOARCH=arm64 ./scripts/embed-msb-runtime.sh
mkdir -p dist
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc go build -tags msbembed -ldflags "-s -w" -o dist/construct-linux-arm64 ./cmd/construct
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: construct-linux-arm64
path: dist/construct-linux-arm64
if-no-files-found: error
retention-days: 2
build-macos:
runs-on: macos-latest
needs: resolve
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- name: Build darwin (arm64 + amd64 via clang -arch)
run: |
mkdir -p dist
# darwin/arm64 embeds the msb pair; darwin/amd64 has no upstream
# assets and the script skips embedding for it (host-msb gate).
GOOS=darwin GOARCH=arm64 ./scripts/embed-msb-runtime.sh
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -tags msbembed -ldflags "-s -w" -o dist/construct-darwin-arm64 ./cmd/construct
GOOS=darwin GOARCH=amd64 ./scripts/embed-msb-runtime.sh
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -tags msbembed -ldflags "-s -w" -o dist/construct-darwin-amd64 ./cmd/construct
# The linker's strip can leave the ad-hoc signature stale, and
# macOS arm64 kernels SIGKILL such binaries at exec. Re-sign each
# slice; the merged binary is re-signed after lipo below.
codesign --force --sign - dist/construct-darwin-arm64
codesign --force --sign - dist/construct-darwin-amd64
- name: Optional release signing and notarization
env:
RELEASE_SIGN: ${{ vars.RELEASE_SIGN }}
RELEASE_NOTARIZE: ${{ vars.RELEASE_NOTARIZE }}
SIGN_IDENTITY: ${{ secrets.APPLE_SIGN_IDENTITY }}
VERSION: ${{ needs.resolve.outputs.version }}
run: |
make release-sign
make notarize-release
- name: Create macOS Universal Binary
run: |
lipo -create -output dist/construct dist/construct-darwin-amd64 dist/construct-darwin-arm64
lipo -info dist/construct
codesign --force --sign - dist/construct
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: construct-darwin
path: |
dist/construct-darwin-arm64
dist/construct-darwin-amd64
dist/construct
if-no-files-found: error
retention-days: 2
release:
runs-on: ubuntu-latest
needs: [resolve, lint, test-linux-amd64, build-linux-arm64, build-macos]
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Package release archives
env:
VERSION: ${{ needs.resolve.outputs.version }}
run: |
cd dist
chmod +x construct-darwin-arm64 construct-darwin-amd64 construct-linux-amd64 construct-linux-arm64
tar -czf "construct-darwin-arm64-${VERSION}.tar.gz" construct-darwin-arm64
tar -czf "construct-darwin-amd64-${VERSION}.tar.gz" construct-darwin-amd64
tar -czf "construct-linux-amd64-${VERSION}.tar.gz" construct-linux-amd64
tar -czf "construct-linux-arm64-${VERSION}.tar.gz" construct-linux-arm64
mkdir -p linux-amd64 linux-arm64
cp construct-linux-amd64 linux-amd64/construct
cp construct-linux-arm64 linux-arm64/construct
tar -czf construct-cli-linux-amd64.tar.gz -C linux-amd64 construct
tar -czf construct-cli-linux-arm64.tar.gz -C linux-arm64 construct
rm -rf linux-amd64 linux-arm64
tar -czf construct-cli-macos-universal.tar.gz construct
rm construct
- name: Generate checksums
env:
VERSION: ${{ needs.resolve.outputs.version }}
run: |
cd dist
sha256sum \
"construct-darwin-arm64-${VERSION}.tar.gz" \
"construct-darwin-amd64-${VERSION}.tar.gz" \
"construct-linux-amd64-${VERSION}.tar.gz" \
"construct-linux-arm64-${VERSION}.tar.gz" \
"construct-cli-macos-universal.tar.gz" \
"construct-cli-linux-amd64.tar.gz" \
"construct-cli-linux-arm64.tar.gz" \
> checksums.txt
- name: Verify release outputs
env:
VERSION: ${{ needs.resolve.outputs.version }}
run: |
set -e
expected_files=(
"dist/construct-darwin-arm64-${VERSION}.tar.gz"
"dist/construct-darwin-amd64-${VERSION}.tar.gz"
"dist/construct-linux-amd64-${VERSION}.tar.gz"
"dist/construct-linux-arm64-${VERSION}.tar.gz"
"dist/construct-cli-macos-universal.tar.gz"
"dist/construct-cli-linux-amd64.tar.gz"
"dist/construct-cli-linux-arm64.tar.gz"
"dist/checksums.txt"
)
for file in "${expected_files[@]}"; do
if [ -f "${file}" ]; then
size=$(stat -c%s "${file}")
echo "OK ${file} (size: ${size} bytes)"
else
echo "Missing expected artifact: ${file}"
exit 1
fi
done
- name: Extract release notes from CHANGELOG.md
env:
VERSION_SEMVER: ${{ needs.resolve.outputs.version }}
run: |
set -euo pipefail
changelog_file="CHANGELOG.md"
notes_file="release_notes.md"
start_marker="<!-- RELEASE:START ${VERSION_SEMVER} -->"
end_marker="<!-- RELEASE:END ${VERSION_SEMVER} -->"
if [ -f "${changelog_file}" ]; then
awk -v start="${start_marker}" -v end="${end_marker}" '
$0 == start { in_section = 1; next }
$0 == end { in_section = 0; exit }
in_section { print }
' "${changelog_file}" > "${notes_file}"
else
: > "${notes_file}"
fi
if ! grep -q '[^[:space:]]' "${notes_file}"; then
prev_tag=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || true)
if [ -n "${prev_tag}" ]; then
echo "**Full changelog:** ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/compare/${prev_tag}...${VERSION_SEMVER}" > "${notes_file}"
else
echo "**Full changelog:** ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/tag/${VERSION_SEMVER}" > "${notes_file}"
fi
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.resolve.outputs.version }}
name: The Construct CLI ${{ needs.resolve.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: ${{ needs.resolve.outputs.is_prerelease == 'true' }}
files: |
dist/construct-darwin-arm64-${{ needs.resolve.outputs.version }}.tar.gz
dist/construct-darwin-amd64-${{ needs.resolve.outputs.version }}.tar.gz
dist/construct-linux-amd64-${{ needs.resolve.outputs.version }}.tar.gz
dist/construct-linux-arm64-${{ needs.resolve.outputs.version }}.tar.gz
dist/construct-cli-macos-universal.tar.gz
dist/construct-cli-linux-amd64.tar.gz
dist/construct-cli-linux-arm64.tar.gz
dist/checksums.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update release marker file
env:
VERSION: ${{ needs.resolve.outputs.version }}
IS_PRERELEASE: ${{ needs.resolve.outputs.is_prerelease }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# The job checks out the tag (detached HEAD). When the tag commit is
# off main's lineage, `push HEAD:main` is rejected non-fast-forward
# and a swallowed error left main/VERSION stale (1.17.13 shipped
# while main still said 1.17.12). Commit the marker on top of
# origin/main so the push is always a fast-forward, and let a
# rejected push fail the step loudly.
git fetch origin main
git checkout -B release-marker origin/main
if [ "$IS_PRERELEASE" = "true" ]; then
echo "$VERSION" > VERSION-BETA
git add VERSION-BETA
git commit -m "chore: update VERSION-BETA to $VERSION" || echo "No changes to commit"
else
echo "$VERSION" > VERSION
git add VERSION
git commit -m "chore: update VERSION to $VERSION" || echo "No changes to commit"
fi
git push origin release-marker:main
update-tap:
needs: [release, resolve]
if: ${{ needs.resolve.outputs.is_prerelease != 'true' }}
runs-on: ubuntu-latest
steps:
- name: Trigger Homebrew Tap Update
uses: actions/github-script@v9
with:
github-token: ${{ secrets.TAP_GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'EstebanForge',
repo: 'homebrew-tap',
workflow_id: 'update-formula.yml',
ref: 'main',
inputs: {
formula: 'construct-cli',
tag: '${{ needs.resolve.outputs.version }}',
repository: '${{ github.repository }}'
}
})