Repository navigation
323 lines (283 loc) · 10.1 KB
/
Copy pathrelease.yml
File metadata and controls
323 lines (283 loc) · 10.1 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
name: Release
# Builds and publishes a tagged version: binaries on the GitHub release,
# the Docker image, the Homebrew formula, and loxone-config and loxone-client on
# crates.io when their version is new. Runs for a pushed vX.Y.Z tag, when auto-release.yml calls
# it after tagging, or by hand for an existing tag (to retry a failed run).
on:
push:
tags:
- "v*"
workflow_call:
inputs:
tag:
description: The tag to release (vX.Y.Z), already pushed
required: true
type: string
workflow_dispatch:
inputs:
tag:
description: Existing tag to build and release, e.g. v0.15.0
required: true
type: string
env:
CARGO_TERM_COLOR: always
TAG: ${{ inputs.tag || github.ref_name }}
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
matrix:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
artifact: lox-linux-x86_64
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
artifact: lox-linux-aarch64
- target: x86_64-apple-darwin
os: macos-latest
artifact: lox-macos-x86_64
- target: aarch64-apple-darwin
os: macos-latest
artifact: lox-macos-aarch64
- target: x86_64-pc-windows-msvc
os: windows-latest
artifact: lox-windows-x86_64
- target: aarch64-pc-windows-msvc
os: windows-latest
artifact: lox-windows-aarch64
steps:
- uses: actions/checkout@v7
with:
ref: ${{ env.TAG }}
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cargo-zigbuild (Linux musl)
if: contains(matrix.target, 'linux-musl')
run: |
pip install ziglang
cargo install cargo-zigbuild --locked
- name: Cache cargo
uses: actions/cache@v6
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.target }}-cargo-
- name: Build (zigbuild for musl)
if: contains(matrix.target, 'linux-musl')
run: cargo zigbuild --release --target ${{ matrix.target }}
- name: Build
if: ${{ !contains(matrix.target, 'linux-musl') }}
run: cargo build --release --target ${{ matrix.target }}
- name: Rename binary (Unix)
if: runner.os != 'Windows'
run: |
cp target/${{ matrix.target }}/release/lox ${{ matrix.artifact }}
- name: Rename binary (Windows)
if: runner.os == 'Windows'
run: |
cp target/${{ matrix.target }}/release/lox.exe ${{ matrix.artifact }}.exe
- name: SHA256 checksum (Unix)
if: runner.os != 'Windows'
run: |
if command -v sha256sum >/dev/null 2>&1; then
sha256sum ${{ matrix.artifact }} > ${{ matrix.artifact }}.sha256
else
shasum -a 256 ${{ matrix.artifact }} > ${{ matrix.artifact }}.sha256
fi
- name: SHA256 checksum (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$hash = (Get-FileHash "${{ matrix.artifact }}.exe" -Algorithm SHA256).Hash.ToLower()
"$hash ${{ matrix.artifact }}.exe" | Out-File -Encoding ascii "${{ matrix.artifact }}.exe.sha256"
- name: Upload artifacts (Unix)
if: runner.os != 'Windows'
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact }}
path: |
${{ matrix.artifact }}
${{ matrix.artifact }}.sha256
- name: Upload artifacts (Windows)
if: runner.os == 'Windows'
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact }}
path: |
${{ matrix.artifact }}.exe
${{ matrix.artifact }}.exe.sha256
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
ref: ${{ env.TAG }}
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
pattern: lox-*
merge-multiple: true
# The CHANGELOG section of this version in the release style (title
# "vX.Y.Z — tagline", emoji headings), above GitHub's list of PRs
- name: Release notes
id: notes
run: python3 .github/scripts/prepare_release.py --notes "$TAG" > release-notes.md
- name: Create Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ env.TAG }}
name: ${{ steps.notes.outputs.name }}
files: artifacts/*
body_path: release-notes.md
generate_release_notes: true
docker:
name: Push Docker image
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v7
with:
ref: ${{ env.TAG }}
- name: Download Linux artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
pattern: lox-*
merge-multiple: true
- name: Prepare binaries
run: |
mkdir -p docker/linux/amd64 docker/linux/arm64
cp artifacts/lox-linux-x86_64 docker/linux/amd64/lox
cp artifacts/lox-linux-aarch64 docker/linux/arm64/lox
chmod +x docker/linux/amd64/lox docker/linux/arm64/lox
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ env.TAG }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.TAG }}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
file: Dockerfile.release
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
update-homebrew:
name: Update Homebrew Formula
needs: release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
ref: main
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
pattern: lox-*
merge-multiple: true
- name: Update formula with checksums
run: |
VERSION="${TAG#v}"
export SHA_MACOS_ARM=$(awk '{print $1}' artifacts/lox-macos-aarch64.sha256)
export SHA_MACOS_X86=$(awk '{print $1}' artifacts/lox-macos-x86_64.sha256)
export SHA_LINUX_ARM=$(awk '{print $1}' artifacts/lox-linux-aarch64.sha256)
export SHA_LINUX_X86=$(awk '{print $1}' artifacts/lox-linux-x86_64.sha256)
sed -i "s/^ version \".*\"/ version \"${VERSION}\"/" Formula/lox.rb
# Update SHA256 values in order of appearance:
# 1st = macos-aarch64, 2nd = macos-x86_64,
# 3rd = linux-aarch64, 4th = linux-x86_64
python3 - <<'PYEOF'
import re, os
sha_map = [
os.environ["SHA_MACOS_ARM"],
os.environ["SHA_MACOS_X86"],
os.environ["SHA_LINUX_ARM"],
os.environ["SHA_LINUX_X86"],
]
with open("Formula/lox.rb") as f:
content = f.read()
idx = [0]
def replacer(m):
i = idx[0]
idx[0] += 1
return f'sha256 "{sha_map[i]}"'
content = re.sub(r'sha256 "[^"]*"', replacer, content)
with open("Formula/lox.rb", "w") as f:
f.write(content)
PYEOF
- name: Commit updated formula
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/lox.rb
if git diff --cached --quiet; then
echo "Formula already at ${TAG}"
exit 0
fi
git commit -m "brew: update formula to ${TAG}"
# A PR merged meanwhile must not fail the release
git pull --rebase origin main
git push origin main
publish-crates:
name: Publish the library crates to crates.io (new versions only)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
ref: ${{ env.TAG }}
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
# loxone-config and loxone-client keep their own versions (crates/*/Cargo.toml);
# bump one there and the next release publishes it. loxone-config goes first.
- name: Publish what crates.io lacks
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
for crate in loxone-config loxone-client; do
version=$(cargo metadata --no-deps --format-version 1 \
| jq -r --arg c "$crate" '.packages[] | select(.name == $c) | .version')
if curl -fsS -o /dev/null -A "lox release (github.com/${GITHUB_REPOSITORY})" \
"https://crates.io/api/v1/crates/${crate}/${version}"; then
echo "${crate} ${version} is on crates.io already"
elif [ -z "$CARGO_REGISTRY_TOKEN" ]; then
echo "::warning::${crate} ${version} is not on crates.io, and there is no CARGO_REGISTRY_TOKEN secret to publish it"
else
cargo publish -p "$crate" --locked
fi
done