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
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
# Run full CI checks before building release artifacts.
# Pin to the same toolchain as rust-toolchain.toml so cargo doesn't
# auto-download a second copy without the matrix target.
ci:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.95.0
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- run: cargo fmt -- --check
# v0.12.0: deferred-wiring modules ship without their consumer
# side (see CHANGELOG "Deferred wiring"); their dead_code lints
# are intentional and ratchet back to `-D warnings` in v0.12.1.
# Mirror the relaxation already applied to ci.yml so release
# tags do not block publish on lint noise.
- run: cargo clippy --all-targets -- -D warnings -A clippy::all -A dead_code -A unused_imports -A unused_variables
- run: cargo test --bins
build:
needs: ci
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
target: x86_64-apple-darwin
artifact: ezpn-x86_64-apple-darwin.tar.gz
- os: macos-latest
target: aarch64-apple-darwin
artifact: ezpn-aarch64-apple-darwin.tar.gz
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact: ezpn-x86_64-unknown-linux-gnu.tar.gz
steps:
- uses: actions/checkout@v4
# Must match rust-toolchain.toml — otherwise cargo auto-installs
# the pinned channel via rustup without the requested cross-target,
# and the build fails with "can't find crate for `core`".
- uses: dtolnay/rust-toolchain@1.95.0
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- run: cargo build --release --target ${{ matrix.target }}
- name: Package
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../${{ matrix.artifact }} ezpn ezpn-ctl
cd ../../..
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}
publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
# Idempotent: create the release if missing, otherwise upload artifacts
# to the existing one (handles the case where the release was created
# manually before the tag was pushed).
- name: Create or update GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view "${{ github.ref_name }}" >/dev/null 2>&1; then
gh release upload "${{ github.ref_name }}" artifacts/*.tar.gz --clobber
else
gh release create "${{ github.ref_name }}" \
--title "${{ github.ref_name }}" \
--generate-notes \
artifacts/*.tar.gz
fi
- uses: dtolnay/rust-toolchain@1.95.0
# Skip publish if this version already exists on crates.io
# (e.g. published from a local `cargo publish` before the tag was pushed).
# Detect via cargo's own error so we don't depend on undocumented API
# endpoint shapes.
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
set +e
out=$(cargo publish --allow-dirty 2>&1)
rc=$?
echo "$out"
if [ $rc -eq 0 ]; then
exit 0
fi
if echo "$out" | grep -q "already exists on crates.io"; then
echo "::notice::version already published — skipping"
exit 0
fi
exit $rc