Skip to content

Commit bcbe0ad

Browse files
committed
ci: release from actions, only test changed files
This commit introduces release automation triggered by button clicks in Github Actions, guarded by a check on whether all the Cargo.toml files contain the same version string. On PRs, changes to documentation no longer trigger code tests. Similarly, changes to code that don't update documentation do not trigger documentation tests. Changes that fail at the `cargo check` stage abort early to prevent lengthy CI builds of the installer and firmware. Commits on the `main` branch always run the full test suite regardless of what changed. Releases also run the full check, test, build and publish suite.
1 parent 8d8d2bd commit bcbe0ad

File tree

4 files changed

+207
-104
lines changed

4 files changed

+207
-104
lines changed

.github/workflows/check-and-test.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

.github/workflows/build-release.yml renamed to .github/workflows/main.yml

Lines changed: 159 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
name: Build Release
1+
name: Check, test, build release zip, publish docs
22

33
on:
44
push:
5-
branches: [main, "release-*"]
65
pull_request:
7-
branches: ["main"]
6+
workflow_call:
87

98
env:
109
CARGO_TERM_COLOR: always
@@ -13,7 +12,139 @@ env:
1312
FILE_RAYHUNTER_DAEMON_TPLINK: ../../rayhunter-daemon-tplink/rayhunter-daemon
1413

1514
jobs:
15+
files_changed:
16+
name: Detect file changes
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
outputs:
21+
code_changed: ${{ steps.files_changed.outputs.code_count }}
22+
daemon_changed: ${{ steps.files_changed.outputs.daemon_count }}
23+
docs_changed: ${{ steps.files_changed.outputs.docs_count }}
24+
installer_changed: ${{ steps.files_changed.outputs.installer_count }}
25+
rootshell_changed: ${{ steps.files_changed.outputs.rootshell_count }}
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
- name: detect file changes
31+
id: files_changed
32+
run: |
33+
lcommit=${{ github.event.pull_request.base.sha || 'origin/main' }}
34+
if [ ${{ github.ref }} = 'refs/heads/main' ]
35+
then
36+
echo "building everything"
37+
echo code_count=forced >> "$GITHUB_OUTPUT"
38+
echo daemon_count=forced >> "$GITHUB_OUTPUT"
39+
echo docs_count=forced >> "$GITHUB_OUTPUT"
40+
echo installer_count=forced >> "$GITHUB_OUTPUT"
41+
echo rootshell_count=forced >> "$GITHUB_OUTPUT"
42+
else
43+
echo "code_count=$(git diff --name-only $lcommit...HEAD | grep -e ^bin -e ^installer -e ^lib -e ^rootshell -e ^telcom-parser | wc -l)" >> "$GITHUB_OUTPUT"
44+
echo "daemon_count=$(git diff --name-only $lcommit...HEAD | grep -e ^bin -e ^lib -e ^telcom-parser | wc -l)" >> "$GITHUB_OUTPUT"
45+
echo "docs_count=$(git diff --name-only $lcommit...HEAD | grep -e ^book.toml -e ^doc | wc -l)" >> "$GITHUB_OUTPUT"
46+
echo "installer_count=$(git diff --name-only $lcommit...HEAD | grep -e ^installer | wc -l)" >> "$GITHUB_OUTPUT"
47+
echo "rootshell_count=$(git diff --name-only $lcommit...HEAD | grep -e ^rootshell | wc -l)" >> "$GITHUB_OUTPUT"
48+
fi
49+
50+
mdbook_test:
51+
name: Test mdBook Documentation builds
52+
needs: files_changed
53+
if: needs.files_changed.outputs.docs_changed != '0'
54+
runs-on: ubuntu-latest
55+
permissions:
56+
contents: read
57+
steps:
58+
- uses: actions/checkout@v4
59+
- name: Install mdBook
60+
run: |
61+
cargo install mdbook --no-default-features --features search --vers "^0.4" --locked
62+
- name: Test mdBook
63+
run: mdbook test
64+
65+
mdbook_publish:
66+
name: Publish mdBook to Github Pages
67+
needs: mdbook_test
68+
if: ${{ github.event_name != 'pull_request' }}
69+
permissions:
70+
pages: write
71+
contents: write
72+
id-token: write
73+
runs-on: ubuntu-latest
74+
steps:
75+
- uses: actions/checkout@v4
76+
- name: Install mdBook
77+
run: |
78+
cargo install mdbook --no-default-features --features search --vers "^0.4" --locked
79+
80+
- name: Build mdBook
81+
run: mdbook build
82+
83+
- name: Setup Pages
84+
uses: actions/configure-pages@v4
85+
- name: Upload artifact
86+
uses: actions/upload-pages-artifact@v3
87+
with:
88+
path: book
89+
- name: Deploy to Github Pages
90+
uses: actions/deploy-pages@v4
91+
92+
check_and_test:
93+
needs: files_changed
94+
if: needs.files_changed.outputs.code_changed != '0'
95+
strategy:
96+
matrix:
97+
device:
98+
- name: tplink
99+
- name: orbic
100+
runs-on: ubuntu-latest
101+
permissions:
102+
contents: read
103+
steps:
104+
- uses: actions/checkout@v4
105+
- name: Check formatting
106+
run: cargo fmt --all --check
107+
- name: Check
108+
run: |
109+
pushd bin/web
110+
npm install
111+
npm run build
112+
popd
113+
NO_FIRMWARE_BIN=true cargo check --verbose --no-default-features --features=${{ matrix.device.name }}
114+
- name: Run tests
115+
run: |
116+
NO_FIRMWARE_BIN=true cargo test --verbose --no-default-features --features=${{ matrix.device.name }}
117+
- name: Run clippy
118+
run: |
119+
NO_FIRMWARE_BIN=true cargo clippy --verbose --no-default-features --features=${{ matrix.device.name }}
120+
121+
windows_installer_check_and_test:
122+
needs: files_changed
123+
if: needs.files_changed.outputs.installer_changed != '0'
124+
runs-on: windows-latest
125+
permissions:
126+
contents: read
127+
steps:
128+
- uses: actions/checkout@v4
129+
- name: cargo check
130+
shell: bash
131+
run: |
132+
cd installer
133+
NO_FIRMWARE_BIN=true cargo check --verbose
134+
- name: cargo test
135+
shell: bash
136+
run: |
137+
cd installer
138+
NO_FIRMWARE_BIN=true cargo test --verbose --no-default-features
139+
16140
build_rayhunter_check:
141+
if: needs.files_changed.outputs.daemon_changed != '0'
142+
needs:
143+
- check_and_test
144+
- files_changed
145+
permissions:
146+
contents: read
147+
packages: write
17148
strategy:
18149
matrix:
19150
platform:
@@ -42,8 +173,15 @@ jobs:
42173
name: rayhunter-check-${{ matrix.platform.name }}
43174
path: target/release/rayhunter-check${{ matrix.platform.os == 'windows-latest' && '.exe' || '' }}
44175
if-no-files-found: error
176+
45177
build_rootshell:
178+
if: needs.files_changed.outputs.rootshell_changed != '0'
179+
needs:
180+
- check_and_test
181+
- files_changed
46182
runs-on: ubuntu-latest
183+
permissions:
184+
contents: read
47185
steps:
48186
- uses: actions/checkout@v4
49187
- uses: dtolnay/rust-toolchain@stable
@@ -56,7 +194,15 @@ jobs:
56194
name: rootshell
57195
path: target/armv7-unknown-linux-musleabihf/firmware/rootshell
58196
if-no-files-found: error
197+
59198
build_rayhunter:
199+
if: needs.files_changed.outputs.daemon_changed != '0'
200+
needs:
201+
- check_and_test
202+
- files_changed
203+
permissions:
204+
contents: read
205+
packages: write
60206
strategy:
61207
matrix:
62208
device:
@@ -88,9 +234,16 @@ jobs:
88234
name: rayhunter-daemon-${{ matrix.device.name }}
89235
path: target/armv7-unknown-linux-musleabihf/firmware/rayhunter-daemon
90236
if-no-files-found: error
237+
91238
build_rust_installer:
239+
if: needs.files_changed.outputs.installer_changed != '0'
240+
permissions:
241+
contents: read
242+
packages: write
92243
needs:
93244
- build_rayhunter
245+
- files_changed
246+
- windows_installer_check_and_test
94247
strategy:
95248
matrix:
96249
platform:
@@ -124,6 +277,9 @@ jobs:
124277
if-no-files-found: error
125278

126279
build_release_zip:
280+
permissions:
281+
contents: read
282+
packages: write
127283
needs:
128284
- build_rayhunter_check
129285
- build_rootshell

.github/workflows/mdbook.yaml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# To use: navigate on Github to Actions, select "Release rayhunter" on the left, click "Run workflow" > "Run workflow" on the right.
2+
# https://github.com/EFForg/rayhunter/actions/workflows/release.yml
3+
name: Release rayhunter
4+
on:
5+
workflow_dispatch:
6+
7+
env:
8+
GH_TOKEN: ${{ github.token }}
9+
10+
jobs:
11+
check_version_same:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Ensure all Cargo.toml files have the same version defined.
18+
run: |
19+
defined_versions=$(find lib bin installer rootshell telcom-parser -name Cargo.toml -exec grep ^version {} \; | uniq | wc -l)
20+
find lib bin installer rootshell telcom-parser -name Cargo.toml -exec grep ^version {} \;
21+
echo number of defined versions = $defined_versions
22+
if [ $defined_versions != "1" ]
23+
then
24+
echo "all Cargo.toml files must have the same version defined"
25+
exit 1
26+
fi
27+
28+
main:
29+
needs: check_version_same
30+
permissions:
31+
contents: write
32+
id-token: write
33+
packages: write
34+
pages: write
35+
uses: ./.github/workflows/main.yml
36+
37+
release:
38+
runs-on: ubuntu-latest
39+
needs: main
40+
permissions:
41+
contents: write
42+
steps:
43+
- uses: actions/checkout@v4
44+
- uses: actions/download-artifact@v4
45+
- name: Create release
46+
run: |
47+
version=$(grep ^version lib/Cargo.toml | cut -d' ' -f3 | tr -d '"')
48+
gh release create --generate-notes -t "Rayhunter v$version" "v$version" rayhunter-v${version}/rayhunter-*

0 commit comments

Comments
 (0)