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
name: Release
# Tagging `vX.Y.Z` builds cross-platform binaries and publishes a GitHub Release
# with notes drawn from CHANGELOG.md. No manual release steps required.
on:
push:
tags:
# Dispatchable so the crates.io publish can be run after the token secret is
# added, without having to invent a version bump or re-push a tag.
workflow_dispatch:
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Package (unix)
if: runner.os != 'Windows'
run: |
bin="target/${{ matrix.target }}/release/killer"
tar -czf "killer-${{ matrix.target }}.tar.gz" -C "$(dirname "$bin")" killer
shasum -a 256 "killer-${{ matrix.target }}.tar.gz" > "killer-${{ matrix.target }}.tar.gz.sha256"
- name: Package (windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$bin = "target/${{ matrix.target }}/release/killer.exe"
Compress-Archive -Path $bin -DestinationPath "killer-${{ matrix.target }}.zip"
(Get-FileHash "killer-${{ matrix.target }}.zip" -Algorithm SHA256).Hash | Out-File "killer-${{ matrix.target }}.zip.sha256"
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: killer-${{ matrix.target }}
path: |
killer-${{ matrix.target }}.*
release:
name: Publish release
needs: build
# Only on a tag. A workflow_dispatch run has no tag for the release action
# to attach to, so without this the job fails every time the workflow is
# dispatched to re-run the crates.io publish.
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Download artifacts
uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Extract release notes from CHANGELOG
id: notes
run: |
version="${GITHUB_REF_NAME#v}"
awk -v v="$version" '
$0 ~ "^## \\[" v "\\]" {flag=1; next}
/^## \[/ {flag=0}
flag {print}
' CHANGELOG.md > release-notes.md
if [ ! -s release-notes.md ]; then echo "Release $GITHUB_REF_NAME" > release-notes.md; fi
- name: Publish GitHub Release
uses: softprops/action-gh-release@v3
with:
body_path: release-notes.md
files: dist/*
generate_release_notes: false
publish-crate:
name: Publish to crates.io
needs: build
runs-on: ubuntu-latest
env:
# Add a repository secret named CARGO_REGISTRY_TOKEN (a crates.io API
# token) to enable this. Until then the step below skips cleanly.
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: |
if [ -z "${CARGO_REGISTRY_TOKEN}" ]; then
echo "CARGO_REGISTRY_TOKEN not set — skipping crates.io publish."
echo "Add the secret in Settings → Secrets and variables → Actions to enable it."
exit 0
fi
cargo publish