Skip to content

Commit 1437f3f

Browse files
committed
ci: skip tests/clippy/udeps for docs-only changes
Implemented a DRY approach using a composite action that detects when only documentation files have changed. This speeds up CI for docs-only PRs while keeping all checks green. - Created reusable composite action '.github/actions/check-docs-only' - Refactored workflow to use the composite action across all jobs - Tests, clippy, and udeps checks now pass immediately for docs-only changes
1 parent dfd6b19 commit 1437f3f

2 files changed

Lines changed: 98 additions & 1 deletion

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: 'Check Docs Only Changes'
2+
description: 'Check if only documentation files were changed'
3+
outputs:
4+
docs-only:
5+
description: "True if only documentation files were changed"
6+
value: ${{ steps.check.outputs.docs_only }}
7+
runs:
8+
using: "composite"
9+
steps:
10+
- name: Check if only docs changed
11+
id: check
12+
shell: bash
13+
run: |
14+
# Determine the base SHA for comparison
15+
if [ "${{ github.event_name }}" = "pull_request" ]; then
16+
# For PRs, compare against the base branch
17+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
18+
FILES_CHANGED=$(git diff --name-only "${BASE_SHA}"...HEAD)
19+
else
20+
# For pushes, compare with previous commit
21+
FILES_CHANGED=$(git diff --name-only HEAD~1...HEAD 2>/dev/null || echo "")
22+
fi
23+
24+
# Check if all changed files are in docs/ directory
25+
if [ -z "$FILES_CHANGED" ]; then
26+
echo "docs_only=false" >> $GITHUB_OUTPUT
27+
echo "No files changed"
28+
elif echo "$FILES_CHANGED" | grep -vE '^docs/' > /dev/null; then
29+
echo "docs_only=false" >> $GITHUB_OUTPUT
30+
echo "Non-documentation files changed"
31+
else
32+
echo "docs_only=true" >> $GITHUB_OUTPUT
33+
echo "All changes are in docs/ folder, checks will pass automatically"
34+
fi

.github/workflows/tests.yml

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,54 @@ jobs:
1919

2020
steps:
2121
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Check for docs-only changes
26+
id: docs-check
27+
uses: ./.github/actions/check-docs-only
2228

2329
- name: Install Rust
30+
if: steps.docs-check.outputs.docs-only != 'true'
2431
uses: dtolnay/rust-toolchain@stable
2532
with:
2633
toolchain: stable
2734

2835
- name: Setup Rust cache
36+
if: steps.docs-check.outputs.docs-only != 'true'
2937
uses: Swatinem/rust-cache@v2
3038
with:
3139
shared-key: ${{ runner.os }}
3240

3341
- name: Install nextest
42+
if: steps.docs-check.outputs.docs-only != 'true'
3443
uses: taiki-e/install-action@nextest
3544
with:
3645
tool: nextest
3746

3847
- name: Run all tests
48+
if: steps.docs-check.outputs.docs-only != 'true'
3949
run: cargo nextest run --profile ci
4050

51+
- name: Skip tests for docs-only changes
52+
if: steps.docs-check.outputs.docs-only == 'true'
53+
run: echo "✅ Skipping tests - only documentation changed"
54+
4155
test-linux:
4256
name: Linux Tests
4357
runs-on: [self-hosted, linux]
4458

4559
steps:
60+
- uses: actions/checkout@v4
61+
with:
62+
fetch-depth: 0
63+
64+
- name: Check for docs-only changes
65+
id: docs-check
66+
uses: ./.github/actions/check-docs-only
67+
4668
- name: Fix permissions from previous runs
69+
if: steps.docs-check.outputs.docs-only != 'true'
4770
run: |
4871
# Clean up any files left from previous sudo runs before checkout
4972
# Use GITHUB_WORKSPACE parent directory or current working directory
@@ -55,14 +78,15 @@ jobs:
5578
if [ -d /home/ci/.cargo ]; then
5679
sudo chown -R ci:ci /home/ci/.cargo || true
5780
fi
58-
- uses: actions/checkout@v4
5981
6082
- name: Install Rust
83+
if: steps.docs-check.outputs.docs-only != 'true'
6184
uses: dtolnay/rust-toolchain@stable
6285
with:
6386
toolchain: stable
6487

6588
- name: Fix permissions on current directory
89+
if: steps.docs-check.outputs.docs-only != 'true'
6690
run: |
6791
# Clean up any files left from previous sudo runs
6892
if [ -d target ]; then
@@ -78,45 +102,57 @@ jobs:
78102
fi
79103
80104
- name: Setup Rust cache
105+
if: steps.docs-check.outputs.docs-only != 'true'
81106
uses: Swatinem/rust-cache@v2
82107
with:
83108
shared-key: ${{ runner.os }}
84109

85110
- name: Setup Rust environment
111+
if: steps.docs-check.outputs.docs-only != 'true'
86112
run: |
87113
source ~/.cargo/env
88114
rustup default stable
89115
90116
- name: Install nextest
117+
if: steps.docs-check.outputs.docs-only != 'true'
91118
uses: taiki-e/install-action@nextest
92119
with:
93120
tool: nextest
94121

95122
- name: Fix target directory permissions from previous runs
123+
if: steps.docs-check.outputs.docs-only != 'true'
96124
run: |
97125
if [ -d target ]; then
98126
sudo chown -R ci:ci target || true
99127
fi
100128
101129
- name: Run all tests (non-root)
130+
if: steps.docs-check.outputs.docs-only != 'true'
102131
run: |
103132
source ~/.cargo/env
104133
cargo nextest run --profile ci --verbose -E 'not (binary(linux_integration) or binary(weak_integration))'
105134
106135
- name: Install dependencies for weak mode (curl)
136+
if: steps.docs-check.outputs.docs-only != 'true'
107137
run: sudo apt-get update && sudo apt-get install -y curl
108138

109139
- name: Run weak mode integration tests (Linux)
140+
if: steps.docs-check.outputs.docs-only != 'true'
110141
run: |
111142
source ~/.cargo/env
112143
cargo nextest run --profile ci --test weak_integration
113144
114145
- name: Run Linux jail integration tests (sudo)
146+
if: steps.docs-check.outputs.docs-only != 'true'
115147
run: |
116148
source ~/.cargo/env
117149
# Run Linux-specific jail tests with sudo to satisfy root requirements
118150
sudo -E $(which cargo) nextest run --profile ci --test linux_integration --verbose
119151
152+
- name: Skip tests for docs-only changes
153+
if: steps.docs-check.outputs.docs-only == 'true'
154+
run: echo "✅ Skipping tests - only documentation changed"
155+
120156
clippy:
121157
name: Clippy (${{ matrix.os }})
122158
runs-on: ${{ matrix.os }}
@@ -126,21 +162,34 @@ jobs:
126162

127163
steps:
128164
- uses: actions/checkout@v4
165+
with:
166+
fetch-depth: 0
167+
168+
- name: Check for docs-only changes
169+
id: docs-check
170+
uses: ./.github/actions/check-docs-only
129171

130172
- name: Install Rust
173+
if: steps.docs-check.outputs.docs-only != 'true'
131174
uses: dtolnay/rust-toolchain@stable
132175
with:
133176
toolchain: stable
134177
components: clippy
135178

136179
- name: Setup Rust cache
180+
if: steps.docs-check.outputs.docs-only != 'true'
137181
uses: Swatinem/rust-cache@v2
138182
with:
139183
shared-key: ${{ runner.os }}
140184

141185
- name: Run clippy
186+
if: steps.docs-check.outputs.docs-only != 'true'
142187
run: cargo clippy --all-targets -- -D warnings
143188

189+
- name: Skip clippy for docs-only changes
190+
if: steps.docs-check.outputs.docs-only == 'true'
191+
run: echo "✅ Skipping clippy - only documentation changed"
192+
144193
fmt:
145194
name: Format
146195
runs-on: ubuntu-latest-8-cores
@@ -168,21 +217,31 @@ jobs:
168217

169218
steps:
170219
- uses: actions/checkout@v4
220+
with:
221+
fetch-depth: 0
222+
223+
- name: Check for docs-only changes
224+
id: docs-check
225+
uses: ./.github/actions/check-docs-only
171226

172227
- name: Install Rust (nightly for cargo-udeps)
228+
if: steps.docs-check.outputs.docs-only != 'true'
173229
uses: dtolnay/rust-toolchain@stable
174230
with:
175231
toolchain: nightly
176232

177233
- name: Setup Rust cache
234+
if: steps.docs-check.outputs.docs-only != 'true'
178235
uses: Swatinem/rust-cache@v2
179236
with:
180237
shared-key: ${{ runner.os }}
181238

182239
- name: Install cargo-udeps
240+
if: steps.docs-check.outputs.docs-only != 'true'
183241
uses: taiki-e/install-action@cargo-udeps
184242

185243
- name: Check for unused dependencies
244+
if: steps.docs-check.outputs.docs-only != 'true'
186245
run: |
187246
set -euo pipefail
188247
# Run with nightly; capture output without failing the step
@@ -206,3 +265,7 @@ jobs:
206265
echo "Unused dependencies detected"
207266
exit 1
208267
fi
268+
269+
- name: Skip udeps for docs-only changes
270+
if: steps.docs-check.outputs.docs-only == 'true'
271+
run: echo "✅ Skipping unused dependency check - only documentation changed"

0 commit comments

Comments
 (0)