Skip to content

Commit 62f6f64

Browse files
authored
ci: release workflow for trusted publishing (#504)
1 parent aba6b42 commit 62f6f64

1 file changed

Lines changed: 185 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
BIN_NAME: steamguard
11+
12+
jobs:
13+
build:
14+
name: Build ${{ matrix.name }}
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- name: linux
21+
target: x86_64-unknown-linux-gnu
22+
artifact: steamguard-linux-x86_64
23+
binary: steamguard
24+
use-cross: false
25+
- name: linux-arm64
26+
target: aarch64-unknown-linux-gnu
27+
artifact: steamguard-linux-aarch64
28+
binary: steamguard
29+
use-cross: true
30+
- name: linux-musl
31+
target: x86_64-unknown-linux-musl
32+
artifact: steamguard-linux-musl-x86_64
33+
binary: steamguard
34+
use-cross: true
35+
- name: windows
36+
target: x86_64-pc-windows-gnu
37+
artifact: steamguard-windows-x86_64.exe
38+
binary: steamguard.exe
39+
use-cross: true
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- run: rustup toolchain install --profile minimal
45+
46+
- name: Rust Cache
47+
uses: Swatinem/rust-cache@v2
48+
with:
49+
prefix-key: v0-release-${{ matrix.target }}
50+
51+
- name: Install Cross
52+
if: matrix.use-cross
53+
uses: baptiste0928/cargo-install@v2
54+
with:
55+
crate: cross
56+
57+
- name: Build
58+
run: |
59+
if [[ "${{ matrix.use-cross }}" == "true" ]]; then
60+
cross build --release --bin "$BIN_NAME" --target "${{ matrix.target }}"
61+
else
62+
cargo build --release --bin "$BIN_NAME" --target "${{ matrix.target }}"
63+
fi
64+
65+
- name: Stage artifact
66+
run: |
67+
mkdir -p dist
68+
cp "target/${{ matrix.target }}/release/${{ matrix.binary }}" "dist/${{ matrix.artifact }}"
69+
70+
- name: Upload artifact
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: ${{ matrix.artifact }}
74+
path: dist/${{ matrix.artifact }}
75+
if-no-files-found: error
76+
77+
package-deb:
78+
name: Package Debian
79+
runs-on: ubuntu-latest
80+
needs: build
81+
strategy:
82+
fail-fast: false
83+
matrix:
84+
include:
85+
- arch: amd64
86+
binary-artifact: steamguard-linux-musl-x86_64
87+
- arch: arm64
88+
binary-artifact: steamguard-linux-aarch64
89+
90+
steps:
91+
- name: Download package binary
92+
uses: actions/download-artifact@v4
93+
with:
94+
name: ${{ matrix.binary-artifact }}
95+
path: package-input
96+
97+
- name: Download native binary
98+
uses: actions/download-artifact@v4
99+
with:
100+
name: steamguard-linux-x86_64
101+
path: native-input
102+
103+
- name: Build Debian package
104+
run: |
105+
version="${GITHUB_REF_NAME#v}"
106+
package_root="steamguard-cli_${version}_${{ matrix.arch }}"
107+
binary_path="package-input/${{ matrix.binary-artifact }}"
108+
native_binary_path="native-input/steamguard-linux-x86_64"
109+
110+
chmod +x "$binary_path" "$native_binary_path"
111+
mkdir -p "$package_root/usr/local/bin"
112+
mkdir -p "$package_root/etc/bash_completion.d"
113+
mkdir -p "$package_root/DEBIAN"
114+
115+
cp "$binary_path" "$package_root/usr/local/bin/steamguard"
116+
"$native_binary_path" completion --shell bash > "$package_root/etc/bash_completion.d/steamguard"
117+
118+
cat > "$package_root/DEBIAN/control" <<EOF
119+
Package: steamguard-cli
120+
Depends:
121+
Version: $version
122+
Section: base
123+
Priority: optional
124+
Architecture: ${{ matrix.arch }}
125+
Maintainer: Carson McManus <carson.mcmanus1@gmail.com>
126+
Description: steamguard-cli
127+
A command line utility to generate Steam 2FA codes and respond to confirmations.
128+
EOF
129+
130+
dpkg-deb -Zxz --build "$package_root" "steamguard-cli_${version}-0_${{ matrix.arch }}.deb"
131+
132+
- name: Upload Debian package
133+
uses: actions/upload-artifact@v4
134+
with:
135+
name: steamguard-cli-deb-${{ matrix.arch }}
136+
path: steamguard-cli_*-0_${{ matrix.arch }}.deb
137+
if-no-files-found: error
138+
139+
publish:
140+
name: Publish
141+
runs-on: ubuntu-latest
142+
needs:
143+
- build
144+
- package-deb
145+
environment: Publish
146+
permissions:
147+
contents: write
148+
id-token: write
149+
150+
steps:
151+
- uses: actions/checkout@v4
152+
153+
- run: rustup toolchain install --profile minimal
154+
155+
- name: Authenticate with crates.io
156+
uses: rust-lang/crates-io-auth-action@v1
157+
id: auth
158+
159+
- name: Publish crates
160+
env:
161+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
162+
run: |
163+
cargo publish --package steamguard
164+
for attempt in 1 2 3 4 5; do
165+
cargo publish --package steamguard-cli && break
166+
if [[ "$attempt" == "5" ]]; then
167+
exit 1
168+
fi
169+
sleep 30
170+
done
171+
172+
- name: Download artifacts
173+
uses: actions/download-artifact@v4
174+
with:
175+
path: dist
176+
merge-multiple: true
177+
178+
- name: Create GitHub release
179+
env:
180+
GH_TOKEN: ${{ github.token }}
181+
run: |
182+
gh release create "${{ github.ref_name }}" dist/* \
183+
--verify-tag \
184+
--title "${{ github.ref_name }}" \
185+
--generate-notes

0 commit comments

Comments
 (0)