Repository navigation
194 lines (189 loc) · 8.38 KB
/
Copy pathrelease.yml
File metadata and controls
194 lines (189 loc) · 8.38 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
# Release binaries (issue #66): cross-compiles ./cmd/openstorage for
# linux/darwin × amd64/arm64 (pure Go, CGO off), packages
# openstorage_<version>_<os>_<arch>.tar.gz + checksums.txt, verifies the
# native binary and bundled LICENSE on both a linux and a macOS runner, serves
# a repository from the native darwin binary on the local store (create repo,
# push, clone), then uploads everything as assets on the GitHub release for
# the tag.
#
# Not tag/release-triggered on purpose: release-please creates tags with the
# default GITHUB_TOKEN, and GITHUB_TOKEN-created events never trigger
# workflows. Instead release-please.yml chains this via workflow_call in the
# same run. workflow_dispatch is the manual escape hatch to (re)build assets
# for an existing release tag, e.g. after a transient failure.
name: release
on:
workflow_call:
inputs:
tag:
description: "Release tag to build and upload assets for (e.g. v0.1.0)"
required: true
type: string
workflow_dispatch:
inputs:
tag:
description: "Existing release tag to (re)build assets for (e.g. v0.1.0)"
required: true
type: string
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.tag }}
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
- name: Build archives + checksums (CGO off)
env:
TAG: ${{ inputs.tag }}
# Write outside the checkout: Go stamps vcs.modified=true on every
# build that sees untracked files, and older tags do not gitignore
# dist/ (#414).
run: ./scripts/release-archives.sh "$TAG" "$RUNNER_TEMP/dist"
- name: Require a clean VCS stamp and no test build tag on every binary
run: |
cd "$RUNNER_TEMP/dist"
bad=0
for archive in openstorage_*.tar.gz; do
tar -xOzf "$archive" openstorage >"$RUNNER_TEMP/vcs-check"
if go version -m "$RUNNER_TEMP/vcs-check" | grep -qxF $'\tbuild\tvcs.modified=false'; then
echo "clean VCS stamp: $archive"
else
echo "::error title=Dirty VCS stamp::$archive does not report vcs.modified=false"
bad=1
fi
# openstorage_viewcheck is test-only (internal/meta, #503).
if go version -m "$RUNNER_TEMP/vcs-check" | grep -q 'openstorage_viewcheck'; then
echo "::error title=Test build tag::$archive was built with the openstorage_viewcheck tag"
bad=1
fi
done
exit "$bad"
- name: Verify native archive (linux/amd64), bundled license, and all checksums
env:
TAG: ${{ inputs.tag }}
run: |
cd "$RUNNER_TEMP/dist"
sha256sum -c checksums.txt
tar -xzf "openstorage_${TAG#v}_linux_amd64.tar.gz"
cmp LICENSE "$GITHUB_WORKSPACE/LICENSE"
out="$(./openstorage --version)"
echo "$out"
grep -F "$TAG" <<<"$out"
grep -F "$(git -C "$GITHUB_WORKSPACE" rev-parse HEAD)" <<<"$out"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: release-archives
path: |
${{ runner.temp }}/dist/openstorage_*.tar.gz
${{ runner.temp }}/dist/checksums.txt
if-no-files-found: error
# The darwin binaries come from a linux cross-compile; prove the one
# matching this runner's architecture actually runs on macOS, and serves a
# repository from the SQLite local store, before anything lands on the
# release. (macos-latest is Apple Silicon today, so this exercises
# darwin/arm64, but resolve the arch at runtime instead of hard-asserting a
# mutable runner label.)
verify-macos:
needs: build
runs-on: macos-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.tag }}
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: release-archives
path: dist
- name: Verify native darwin archive, bundled license, and all checksums
env:
TAG: ${{ inputs.tag }}
run: |
case "$(uname -m)" in
arm64) arch=arm64 ;;
x86_64) arch=amd64 ;;
*) echo "unexpected macOS runner arch: $(uname -m)" >&2; exit 1 ;;
esac
cd dist
shasum -a 256 -c checksums.txt
tar -xzf "openstorage_${TAG#v}_darwin_${arch}.tar.gz"
cmp LICENSE ../LICENSE
./openstorage --version | grep -F "$TAG"
# The smoke lives in this workflow file, not in the tag's checkout, so a
# workflow_dispatch rebuild of an older tag runs the same smoke.
- name: Smoke the native darwin binary on the local store (create repo, push, clone)
run: |
set -euo pipefail
bin="$PWD/dist/openstorage"
work="$(mktemp -d "${RUNNER_TEMP}/os-smoke.XXXXXX")"
pid=""
cleanup() {
if [ -n "$pid" ]; then
kill "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
fi
rm -rf "$work"
}
trap cleanup EXIT
mkdir -p "$work/keys" "$work/data" "$work/home"
: >"$work/serve.out"
"$bin" keygen --out "$work/keys/org" >/dev/null
OPENSTORAGE_ORG=selfhost OPENSTORAGE_ORG_PUBKEYS="$work/keys/org.pub.pem" \
"$bin" serve --listen 127.0.0.1:0 --data-dir "$work/data" \
>"$work/serve.out" 2>"$work/serve.err" &
pid=$!
addr=""
for _ in $(seq 1 60); do
addr="$(sed -n 's/^listening on //p' "$work/serve.out" | head -n 1)"
[ -n "$addr" ] && break
kill -0 "$pid" 2>/dev/null || { echo "serve exited early" >&2; cat "$work/serve.err" >&2; exit 1; }
sleep 1
done
[ -n "$addr" ] || { echo "serve did not announce an address within 60 s" >&2; cat "$work/serve.err" >&2; exit 1; }
echo "serve listens on $addr"
mint() { "$bin" mint --key "$work/keys/org.pem" --iss selfhost --repo demo --scopes "$1"; }
create="$(mint repo:write)"
rw="$(mint git:read,git:write)"
code="$(curl -sS --max-time 30 -o "$work/create.body" -w '%{http_code}' -X POST "http://$addr/api/v1/repos" \
-H "Authorization: Bearer $create" -H 'Content-Type: application/json' \
--data '{"default_branch":"main"}')"
# v0.15.0 answers 200 where later tags answer 201.
[ "$code" = 201 ] || [ "$code" = 200 ] || { echo "create repo: HTTP $code" >&2; cat "$work/create.body" >&2; exit 1; }
export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null GIT_TERMINAL_PROMPT=0 HOME="$work/home"
export GIT_AUTHOR_NAME=smoke GIT_AUTHOR_EMAIL=smoke@example.invalid
export GIT_COMMITTER_NAME=smoke GIT_COMMITTER_EMAIL=smoke@example.invalid
url="http://t:$rw@$addr/demo.git"
git -c advice.defaultBranchName=false clone -q "$url" "$work/one"
head -c 1000000 /dev/urandom >"$work/one/blob.bin"
echo hello >"$work/one/hello.txt"
git -C "$work/one" add hello.txt blob.bin
git -C "$work/one" commit -q -m smoke
git -C "$work/one" push -q origin HEAD:refs/heads/main
git clone -q "$url" "$work/two"
[ "$(git -C "$work/one" rev-parse HEAD)" = "$(git -C "$work/two" rev-parse HEAD)" ]
cmp "$work/one/blob.bin" "$work/two/blob.bin"
echo "local-store smoke passed: create repo, push, clone"
publish:
needs: [build, verify-macos]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: release-archives
path: dist
- name: Upload assets to the GitHub release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
TAG: ${{ inputs.tag }}
# --clobber so a workflow_dispatch rebuild replaces existing assets.
run: gh release upload "$TAG" dist/openstorage_*.tar.gz dist/checksums.txt --clobber