-
Notifications
You must be signed in to change notification settings - Fork 0
219 lines (190 loc) · 6.16 KB
/
release.yml
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
name: Release
on:
workflow_dispatch:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
pre-check:
name: Pre-check
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version-check.outputs.version }}
steps:
- uses: actions/checkout@v4
- id: version-check
run: |
version_tag="$(git describe --tags --abbrev=0 | sed 's/^v//')"
version_toml="$(grep -m1 -F 'version =' Cargo.toml | cut -d\" -f2)"
if [[ "$version_tag" != "$version_toml" ]]; then
echo "Error: The git tag does not match the Cargo.toml version."
exit 1
fi
echo "Success: The git tag matches the Cargo.toml version."
echo "version=$version_toml" >> $GITHUB_OUTPUT
build:
needs: pre-check
strategy:
matrix:
name:
- linux-x86-64-gnu
- linux-x86-64-musl
- linux-armhf-gnu
- linux-arm64-gnu
- mac-x86-64
- mac-arm64
- windows-gnu
include:
- name: linux-x86-64-gnu
os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
cross: false
experimental: false
- name: linux-x86-64-musl
os: ubuntu-latest
target: x86_64-unknown-linux-musl
cross: true
experimental: false
- name: linux-armhf-gnu
os: ubuntu-20.04
target: armv7-unknown-linux-gnueabihf
cross: true
experimental: false
- name: linux-arm64-gnu
os: ubuntu-20.04
target: aarch64-unknown-linux-gnu
cross: true
experimental: false
- name: mac-x86-64
os: macos-latest
target: x86_64-apple-darwin
cross: false
experimental: false
- name: mac-arm64
os: macos-latest
target: aarch64-apple-darwin
cross: true
experimental: true
- name: windows-gnu
os: windows-latest
target: x86_64-pc-windows-gnu
cross: true
experimental: false
name: Binaries for ${{ matrix.name }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('Cargo.lock') }}
- uses: actions/cache@v4
if: startsWith(matrix.name, 'linux-')
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-cargo-bin-${{ hashFiles('.github/workflows/release.yml') }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
- uses: taiki-e/install-action@cross
if: ${{ matrix.cross }}
- run: cargo build --release --locked
- name: Extract version
shell: bash
run: |
echo "${{ needs.pre-check.outputs.version }}" > VERSION
- name: Archive and Package
shell: bash
run: |
set -euxo pipefail
ext=""
[[ "${{ matrix.name }}" == windows-* ]] && ext=".exe"
bin="target/${{ matrix.target }}/release/keyweave${ext}"
strip "$bin" || true
dst="keyweave-${{ matrix.target }}"
mkdir -p "$dst" dist
cp "$bin" "$dst/"
if [[ "${{ matrix.name }}" == windows-* ]] ; then
mv "$dst/keyweave${ext}" dist/keyweave-${{ matrix.target }}.exe
else
tar cavf "$dst.tar.xz" "$dst"
mv "$dst.tar.xz" dist/
fi
- uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.target }}
path: dist
release:
needs: build
name: Sign and Release
runs-on: ubuntu-latest
outputs:
sha256sums: ${{ steps.homebrew-inputs.outputs.sha256sums }}
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.cargo/bin
key: sign-tools-${{ hashFiles('.github/workflows/release.yml') }}
- uses: actions/download-artifact@v4
with:
pattern: dist-*
merge-multiple: true
- name: Checksums with SHA512 and SHA256
run: |
sha512sum keyweave-* | tee SHA512SUMS
sha256sum keyweave-* | tee SHA256SUMS
- uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
generate_release_notes: true
fail_on_unmatched_files: true
files: |
keyweave-*.tar.xz
keyweave-*.exe
*SUMS*
- name: Generate SHA256SUM input for Homebrew
id: homebrew-inputs
run: |
sha256sums="{$(awk '{printf "%s '\''%s'\'': '\''%s'\''", (NR>1 ? "," : ""), $2, $1} END {print ""}' SHA256SUMS)}"
echo "sha256sums=$sha256sums" >> $GITHUB_OUTPUT
publish-brew:
needs: [release, pre-check]
name: Publish brew formula
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
name: Dispatch Homebrew release
with:
github-token: ${{ secrets.PAT_TOKEN }}
script: |
const sha256sums = ${{ needs.release.outputs.sha256sums }}
await github.rest.actions.createWorkflowDispatch({
owner: 'bartvdbraak',
repo: 'homebrew-keyweave',
workflow_id: 'release.yml',
ref: 'main',
inputs: {
version: '${{ needs.pre-check.outputs.version }}',
sha256sums: JSON.stringify(sha256sums)
}
})
publish-crate:
needs: release
name: Publish rust crate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish --token ${CARGO_REGISTRY_TOKEN}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}