Repository navigation
193 lines (186 loc) · 8.46 KB
/
Copy pathrelease.yml
File metadata and controls
193 lines (186 loc) · 8.46 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
# Release the visualci CLI: static binaries for Linux (musl) and macOS, attached to a GitHub release v<version>; and
# publish the snapshot-diff crate (crates/snapshot-diff) to crates.io when its version isn't there yet (and, once their
# Cargo.toml files drop `publish = false`, envschema-derive and envschema).
# A release happens by itself once CI passes on main with a workspace version (Cargo.toml) that has no release yet, so
# a version bump is all it takes and the docs never describe a CLI nobody can download. The cli-version job in ci.yml
# fails when the CLI changed since its last release without a bump. Pushing a vX.Y.Z tag by hand still works too.
# Each release also moves the floating major tag (v0) to it: the docs pin the GitHub Action as @v0, so users get the
# newest action, and through its default `version`, the newest CLI, without editing their workflows.
name: Release CLI
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]
push:
tags: ["v*.*.*"]
permissions:
contents: write
jobs:
version:
if: github.event_name == 'push' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.v.outputs.tag }}
sha: ${{ steps.v.outputs.sha }}
release: ${{ steps.v.outputs.release }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- id: v
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ "${{ github.event_name }}" = push ]; then
tag="${{ github.ref_name }}"
else
tag="v$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)"
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
if gh release view "$tag" -R "${{ github.repository }}" >/dev/null 2>&1; then
echo "$tag is already released"
echo "release=false" >> "$GITHUB_OUTPUT"
else
echo "Releasing $tag"
echo "release=true" >> "$GITHUB_OUTPUT"
fi
build:
needs: version
if: needs.version.outputs.release == 'true'
strategy:
matrix:
include:
- { target: x86_64-unknown-linux-musl, os: ubuntu-latest }
- { target: aarch64-unknown-linux-musl, os: ubuntu-24.04-arm }
- { target: aarch64-apple-darwin, os: macos-latest }
- { target: x86_64-apple-darwin, os: macos-latest } # cross-compiled on Apple Silicon (macos-13 runners are retired)
runs-on: ${{ matrix.os }}
timeout-minutes: 40
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.version.outputs.sha }}
- name: musl tools
if: contains(matrix.target, 'musl')
run: sudo apt-get update && sudo apt-get install -y musl-tools
- run: rustup target add ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- run: cargo build --release --locked -p visualci-cli --target ${{ matrix.target }}
- name: Package
run: |
# No version in the name, so https://github.com/DocSpring/visualci/releases/latest/download/visualci-<target>.tar.gz
# always names the latest one (install.sh downloads that, or the release $VISUALCI_VERSION names).
dir=visualci-${{ matrix.target }}
mkdir "$dir" && cp target/${{ matrix.target }}/release/visualci "$dir/" && cp LICENSE* "$dir/" 2>/dev/null || true
tar czf "$dir.tar.gz" "$dir"
shasum -a 256 "$dir.tar.gz" > "$dir.tar.gz.sha256"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: visualci-*.tar.gz*
release:
needs: [version, build]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
merge-multiple: true
- env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${{ needs.version.outputs.tag }}" visualci-*.tar.gz* -R "${{ github.repository }}" \
--target "${{ needs.version.outputs.sha }}" --generate-notes
# The floating major tag (v0) follows the newest release. Created with the workflow's token, so it starts no
# workflow of its own (and the tag trigger above only matches vX.Y.Z).
- env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.version.outputs.tag }}
SHA: ${{ needs.version.outputs.sha }}
REPO: ${{ github.repository }}
run: |
major="${TAG%%.*}"
if gh api "repos/$REPO/git/ref/tags/$major" >/dev/null 2>&1; then
gh api -X PATCH "repos/$REPO/git/refs/tags/$major" -f sha="$SHA" -F force=true >/dev/null
else
gh api -X POST "repos/$REPO/git/refs" -f ref="refs/tags/$major" -f sha="$SHA" >/dev/null
fi
echo "$major now points at $TAG ($SHA)"
# snapshot-diff on crates.io (https://crates.io/crates/snapshot-diff), once per version in its Cargo.toml, with
# crates.io's trusted publishing: the job trades GitHub's OIDC token for a short-lived crates.io token (configured on
# crates.io for DocSpring/visualci's release.yml), so no long-lived token is stored anywhere.
snapshot-diff:
if: github.event_name == 'push' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- id: version
run: |
version=$(sed -n 's/^version = "\(.*\)"/\1/p' crates/snapshot-diff/Cargo.toml | head -1)
code=$(curl -s -o /dev/null -w '%{http_code}' -A 'snapshot-diff release (github.com/DocSpring/visualci)' \
"https://crates.io/api/v1/crates/snapshot-diff/$version")
if [ "$code" = 200 ]; then
echo "snapshot-diff $version is already on crates.io"
echo "publish=false" >> "$GITHUB_OUTPUT"
else
echo "publish=true" >> "$GITHUB_OUTPUT"
fi
- id: auth
if: steps.version.outputs.publish == 'true'
uses: rust-lang/crates-io-auth-action@v1
- if: steps.version.outputs.publish == 'true'
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish --locked -p snapshot-diff
# envschema-derive and envschema on crates.io, the same way: once per version in their Cargo.toml files, the derive
# first (envschema depends on it). Inert while either Cargo.toml says `publish = false`. Before that line goes, the
# first release of each is published by hand with a per-crate token, and trusted publishing is configured on
# crates.io for both crates (DocSpring/visualci, release.yml); this job then publishes every later version.
envschema:
if: github.event_name == 'push' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- id: version
run: |
publish=
for crate in envschema-derive envschema; do
manifest=crates/$crate/Cargo.toml
if grep -q '^publish = false' "$manifest"; then
echo "$crate isn't published yet ($manifest says publish = false)"
continue
fi
version=$(sed -n 's/^version = "\(.*\)"/\1/p' "$manifest" | head -1)
code=$(curl -s -o /dev/null -w '%{http_code}' -A 'envschema release (github.com/DocSpring/visualci)' \
"https://crates.io/api/v1/crates/$crate/$version")
if [ "$code" = 200 ]; then
echo "$crate $version is already on crates.io"
else
publish="$publish $crate"
fi
done
echo "crates=${publish# }" >> "$GITHUB_OUTPUT"
- id: auth
if: steps.version.outputs.crates != ''
uses: rust-lang/crates-io-auth-action@v1
- if: steps.version.outputs.crates != ''
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
CRATES: ${{ steps.version.outputs.crates }}
run: |
for crate in $CRATES; do
cargo publish --locked -p "$crate"
done