Repository navigation
185 lines (164 loc) · 6.77 KB
/
Copy pathrelease.yml
File metadata and controls
185 lines (164 loc) · 6.77 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
name: Release
# Artifacts are produced only from a pushed RELEASE.* tag. There is no manual
# trigger and no free-text ref: the provenance attestation names the workflow
# ref that ran, and a dispatch could run this file from one ref while
# building another. Retry a failed run with GitHub's native job rerun; the
# Draft it left behind is replaced from scratch (check-release-state.sh).
on:
push:
tags:
- "RELEASE.*"
permissions:
contents: write
# Sigstore build provenance for the artifacts this run produces and does not
# later modify. See the attestation step for why RPMs are excluded.
id-token: write
attestations: write
# check-release-commit.sh reads workflow runs through the Actions API. Every
# permission not listed here is "none", so omitting this fails a legitimate
# release with "Resource not accessible by integration".
actions: read
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: true
- name: Verify clean checkout
run: |
set -euo pipefail
if [ -n "$(git status --porcelain)" ]; then
echo "Refusing to release from a dirty working tree:" >&2
git status --porcelain >&2
exit 1
fi
- name: Compute release variables
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
VERSION_HYPHEN="${TAG#RELEASE.}"
PKG_VERSION="$(echo "${VERSION_HYPHEN}" | sed -E 's/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2})-([0-9]{2})-([0-9]{2})Z$/\1\2\3\4\5\6.0.0/')"
if [ "${PKG_VERSION}" = "${VERSION_HYPHEN}" ]; then
echo "Invalid release tag format: ${TAG}"
exit 1
fi
if ! TAG_COMMIT="$(git rev-parse "${TAG}^{commit}" 2>/dev/null)"; then
echo "Release tag ${TAG} does not resolve to a commit" >&2
exit 1
fi
HEAD_COMMIT="$(git rev-parse HEAD)"
if [ "${TAG_COMMIT}" != "${HEAD_COMMIT}" ]; then
echo "Release tag ${TAG} resolves to ${TAG_COMMIT}, checkout is ${HEAD_COMMIT}" >&2
exit 1
fi
if [ "${GITHUB_SHA}" != "${HEAD_COMMIT}" ]; then
echo "Event SHA ${GITHUB_SHA} does not match checkout ${HEAD_COMMIT}" >&2
exit 1
fi
VERSION_COLON="$(echo "${VERSION_HYPHEN}" | sed -E 's/T([0-9]{2})-([0-9]{2})-([0-9]{2})Z$/T\1:\2:\3Z/')"
LDFLAGS="$(MC_RELEASE=RELEASE go run buildscripts/gen-ldflags.go "${VERSION_COLON}")"
{
echo "RELEASE_TAG=${TAG}"
echo "RELEASE_COMMIT=${HEAD_COMMIT}"
echo "PKG_VERSION=${PKG_VERSION}"
echo "LDFLAGS=${LDFLAGS}"
} >> "${GITHUB_ENV}"
echo "Release tag: ${TAG}"
echo "Release commit: ${HEAD_COMMIT}"
echo "Package version: ${PKG_VERSION}"
echo "LDFLAGS: ${LDFLAGS}"
# The expected fingerprint and key location are repository variables,
# not files in the tree the tag points at, so the commit being released
# cannot vouch for itself.
- name: Verify the release tag is annotated and signed
env:
RELEASE_SIGNING_FINGERPRINT: ${{ vars.RELEASE_SIGNING_FINGERPRINT }}
RELEASE_SIGNING_KEY_URL: ${{ vars.RELEASE_SIGNING_KEY_URL }}
run: |
set -euo pipefail
buildscripts/verify-release-tag.sh "${RELEASE_TAG}"
- name: Check release commit is the tip of main with green CI
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
buildscripts/check-release-commit.sh "${RELEASE_COMMIT}"
- name: Check existing release state
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
buildscripts/check-release-state.sh "${RELEASE_TAG}"
- name: Build Draft release with GoReleaser
uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3
with:
version: v2.20.1
args: release --clean --skip=validate --config .github/goreleaser.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ env.RELEASE_TAG }}
LDFLAGS: ${{ env.LDFLAGS }}
PKG_VERSION: ${{ env.PKG_VERSION }}
- name: Verify binary provenance stamps
run: |
set -euo pipefail
buildscripts/verify-build-provenance.sh
- name: Install nFPM
run: |
set -euo pipefail
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.48.0
echo "$(go env GOPATH)/bin" >> "${GITHUB_PATH}"
- name: Build nFPM packages
run: |
set -euo pipefail
buildscripts/package-release.sh
- name: Confirm Draft release state
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REQUIRE_DRAFT: "true"
run: |
set -euo pipefail
buildscripts/check-release-state.sh "${RELEASE_TAG}"
- name: Upload nFPM packages to Draft release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
mapfile -t files < <(find dist/packages -maxdepth 1 -type f \
\( -name '*.rpm' -o -name '*.deb' -o -name '*.apk' -o -name '*.sha256sum' \) | sort)
if [ "${#files[@]}" -eq 0 ]; then
echo "No package artifacts to upload."
exit 1
fi
gh release upload "${RELEASE_TAG}" "${files[@]}"
# RPMs are deliberately absent: buildscripts/sign-release-rpms.sh runs
# afterwards on a maintainer machine, rewrites their bytes with rpmsign
# and replaces the uploaded assets while the Release is still a Draft.
# An attestation made here would name a digest that no published RPM
# has, so `gh attestation verify` on the shipped file would fail. RPM
# integrity is covered by its detached GPG signature instead.
- name: Attest build provenance for release artifacts
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-path: |
dist/mcli_*.tar.gz
dist/mcli_*.zip
dist/mcli_*_checksums.txt
dist/packages/*.deb
dist/packages/*.apk
- name: Upload dist artifact
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist
path: dist/