Repository navigation
210 lines (202 loc) · 8.07 KB
/
Copy pathrelease.yml
File metadata and controls
210 lines (202 loc) · 8.07 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
# Releases a vX.Y.Z tag:
# - prebuilt binaries: static Linux (musl, x86_64 + aarch64), macOS (arm64 +
# x86_64), Windows (x86_64)
# - a vendored source bundle that builds fully offline (no crates.io needed)
# - SHA256SUMS and GitHub build-provenance attestations for every file
# - install.sh and install.ps1 attached for convenience
# - then the crate is published to crates.io using CARGO_REGISTRY_TOKEN
# Auto release calls this after CI passes on main with a Cargo.toml version no tag has yet (the usual path);
# pushing a tag yourself runs it too.
#
# Asset names: <name>-<tag>-<target>.tar.gz|zip and <name>-<tag>-vendored-src.tar.gz
name: release
on:
push:
tags: ["v*"]
workflow_call:
inputs:
tag:
description: The vX.Y.Z tag to release (Auto release passes the one it made).
type: string
required: true
permissions:
contents: read
env:
NAME: twokey # crate and binary name (keep in sync with Cargo.toml)
TAG: ${{ inputs.tag || github.ref_name }}
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.tag || github.ref }}
- name: Tag matches Cargo.toml version; Cargo.lock is committed
run: |
test -f Cargo.lock || { echo "::error::commit Cargo.lock before releasing"; exit 1; }
v=$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2)
[ "v$v" = "$TAG" ] || { echo "::error::tag $TAG != Cargo.toml version v$v"; exit 1; }
build:
needs: check
strategy:
fail-fast: false
matrix:
include:
- { target: x86_64-unknown-linux-musl, os: ubuntu-latest, musl: true }
- { target: aarch64-unknown-linux-musl, os: ubuntu-24.04-arm, musl: true }
- { target: aarch64-apple-darwin, os: macos-latest }
- { target: x86_64-apple-darwin, os: macos-latest }
- { target: x86_64-pc-windows-msvc, os: windows-latest }
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.tag || github.ref }}
- uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: musl toolchain
if: matrix.musl
run: |
sudo apt-get update && sudo apt-get install -y musl-tools
# tree-sitter grammars are C; compile them with musl-gcc for a fully static binary
t=$(echo "${{ matrix.target }}" | tr '-' '_')
echo "CC_$t=musl-gcc" >> "$GITHUB_ENV"
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
# Separate cross-compilation targets; rust-cache also keys on rustc,
# Cargo.lock and compiler environment (including CC set above).
key: ${{ matrix.target }}
cache-on-failure: true
- name: Test (native targets only)
if: matrix.target != 'x86_64-apple-darwin'
run: cargo test --locked --release --target ${{ matrix.target }}
- run: cargo build --locked --release --target ${{ matrix.target }}
- name: Package
shell: bash
run: |
stem="$NAME-$TAG-${{ matrix.target }}"
dir="target/${{ matrix.target }}/release"
mkdir -p dist
if [ "$RUNNER_OS" = Windows ]; then
cp "$dir/$NAME.exe" .
7z a "dist/$stem.zip" "$NAME.exe" README.md >/dev/null
else
cp "$dir/$NAME" .
tar -czf "dist/$stem.tar.gz" "$NAME" README.md
fi
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: bin-${{ matrix.target }}
path: dist/*
vendored-source:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.tag || github.ref }}
- uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master
with:
toolchain: stable
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
# Reuse registry downloads, but keep the offline source build clean
# so cached artifacts cannot hide an incomplete vendor bundle.
cache-targets: false
cache-on-failure: true
- name: Vendor every dependency into the source tree
run: |
stem="$NAME-$TAG-vendored-src"
mkdir -p "/tmp/$stem" dist
git archive HEAD | tar -x -C "/tmp/$stem"
cd "/tmp/$stem"
mkdir -p .cargo
cargo vendor --locked vendor > .cargo/config.toml
# Prove it builds with the network off.
cargo build --release --offline --locked
rm -rf target
cd /tmp && tar -czf "$GITHUB_WORKSPACE/dist/$stem.tar.gz" "$stem"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: vendored-src
path: dist/*
publish-github:
needs: [build, vendored-source]
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write # provenance
attestations: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.tag || github.ref }}
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: dist
merge-multiple: true
- name: Checksums
run: |
cp install.sh install.ps1 dist/
cd dist && sha256sum * > SHA256SUMS && cat SHA256SUMS
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-path: dist/*
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: |
{
echo "## Install"
echo
echo '```sh'
echo "curl -fsSL https://github.com/$GITHUB_REPOSITORY/releases/download/$TAG/install.sh | sh -s -- --version $TAG"
echo '```'
echo
echo 'Windows (PowerShell):'
echo '```powershell'
echo "Invoke-WebRequest https://github.com/$GITHUB_REPOSITORY/releases/download/$TAG/install.ps1 -OutFile install.ps1"
echo "./install.ps1 -Version $TAG"
echo '```'
echo
echo "Or: \`cargo binstall $NAME\`, \`cargo install $NAME\`, or build offline from \`$NAME-$TAG-vendored-src.tar.gz\`:"
echo '`cargo install --path <dir> --offline --locked`.'
echo
echo "Verify any file: \`gh attestation verify <file> --repo $GITHUB_REPOSITORY\` and \`sha256sum -c SHA256SUMS\`."
echo
echo '## SHA256SUMS'
echo '```'
cat dist/SHA256SUMS
echo '```'
} > notes.md
gh release create "$TAG" dist/* \
--repo "$GITHUB_REPOSITORY" --title "$TAG" --notes-file notes.md --generate-notes \
$(case "$TAG" in *-*) echo --prerelease ;; esac)
# Publish every release using the configured crates.io API token.
publish-crates-io:
needs: publish-github
runs-on: ubuntu-latest
environment: crates-io
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.tag || github.ref }}
- uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master
with:
toolchain: stable
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
cache-on-failure: true
- name: Publish to crates.io
run: |
if [ -z "$CARGO_REGISTRY_TOKEN" ]; then
echo "::error::Set the CARGO_REGISTRY_TOKEN Actions secret to a crates.io publishing token."
exit 1
fi
cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}