Repository navigation
189 lines (162 loc) · 5.76 KB
/
Copy pathrelease.yml
File metadata and controls
189 lines (162 loc) · 5.76 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
name: Release
on:
push:
tags: ["v*"]
permissions:
contents: read
jobs:
preflight:
name: release-preflight
runs-on: ubuntu-latest
timeout-minutes: 30
env:
RUSTFLAGS: "-D warnings"
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2.9.1
- name: Verify tag and package versions
shell: bash
run: |
set -euo pipefail
tag_version=${GITHUB_REF_NAME#v}
cargo_version=$(sed -n 's/^version = "\([^"]*\)"/\1/p' Cargo.toml | head -n 1)
action_version=$(sed -n "/^ version:$/,/^ paths:$/ s/^ default: '\([^']*\)'/\1/p" action.yml)
test "$tag_version" = "$cargo_version"
test "$tag_version" = "$action_version"
grep -Fq "## [$tag_version] -" CHANGELOG.md
- name: Validate distribution automation
run: python3 scripts/action_validation/validate.py
- name: Check formatting
run: cargo fmt --all --check
- name: Run tests
run: cargo test --all-features --all-targets
- name: Run tests (release)
run: cargo test --release --all-features --all-targets
- name: Run Clippy
run: cargo clippy --all-features --all-targets -- -D warnings
- name: Check package
run: cargo package --locked
release:
name: release-${{ matrix.platform.asset_name }}
needs: preflight
runs-on: ${{ matrix.platform.os }}
permissions:
contents: write
strategy:
matrix:
platform:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
asset_name: linux
arch: x86_64
- os: macos-latest
target: x86_64-apple-darwin
asset_name: darwin
arch: x86_64
- os: macos-latest
target: aarch64-apple-darwin
asset_name: darwin
arch: aarch64
- os: windows-latest
target: x86_64-pc-windows-msvc
asset_name: windows
arch: x86_64
env:
BINARY_NAME: keywatch-${{ matrix.platform.asset_name }}-${{ matrix.platform.arch }}${{ matrix.platform.os == 'windows-latest' && '.exe' || '' }}
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Extract Release Notes
id: release-notes
shell: bash
run: |
VERSION=${GITHUB_REF#refs/tags/}
VER=${VERSION#v}
NOTES=$(awk -v ver="$VER" '
/^## \[/ { if (p) { exit }; if ($2 == "["ver"]") { p=1; next } }
p { print }
' CHANGELOG.md)
if [ -z "$(printf '%s' "$NOTES" | tr -d '[:space:]')" ]; then
echo "::error::Release notes for $VERSION not found in CHANGELOG.md"
exit 1
fi
echo "NOTES<<EOF" >> "$GITHUB_OUTPUT"
echo "$NOTES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
# Build the specific package
- name: Build Binary
run: |
cargo build --locked --release --target ${{ matrix.platform.target }}
- name: Prepare Asset
shell: bash
run: |
mkdir -p release
cp target/${{ matrix.platform.target }}/release/key-watch${{ matrix.platform.os == 'windows-latest' && '.exe' || '' }} \
release/${{ env.BINARY_NAME }}
if [ "${{ matrix.platform.os }}" = "ubuntu-latest" ]; then
cp detectors.toml release/detectors.toml
fi
# Windows: Generate checksum using cmd and Windows syntax.
- name: Generate SHA-256 (Windows)
if: matrix.platform.os == 'windows-latest'
shell: cmd
run: |
cd release
certutil -hashfile %BINARY_NAME% SHA256 | findstr /V "hash" > %BINARY_NAME%.sha256
# Unix (macOS/Ubuntu): Generate checksum using bash.
- name: Generate SHA-256 (Unix)
if: matrix.platform.os != 'windows-latest'
shell: bash
run: |
cd release
shasum -a 256 "$BINARY_NAME" > "$BINARY_NAME".sha256
if [ "${{ matrix.platform.os }}" = "ubuntu-latest" ]; then
shasum -a 256 detectors.toml > detectors.toml.sha256
fi
# Create Release
- name: Create Release
uses: softprops/action-gh-release@v3.0.2
with:
name: "KeyWatch ${{ github.ref_name }}"
files: |
release/${{ env.BINARY_NAME }}
release/${{ env.BINARY_NAME }}.sha256
${{ matrix.platform.os == 'ubuntu-latest' && 'release/detectors.toml' || '' }}
${{ matrix.platform.os == 'ubuntu-latest' && 'release/detectors.toml.sha256' || '' }}
body: ${{ steps.release-notes.outputs.NOTES }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
major-tag:
name: update-major-tag
needs: release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Move the major tag to this release
env:
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
case "$REF_NAME" in
*-*) echo "Prerelease tag; major tag not moved."; exit 0 ;;
esac
major="${REF_NAME%%.*}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -fa "$major" -m "Update $major tag"
git push origin "$major" --force