Skip to content

Commit 91cb1fa

Browse files
alphaqiuclaude
andcommitted
refactor: reorganize CI/CD workflows to eliminate functional overlap
Option A: Clear separation of concerns - build.yml: Only responsible for cross-platform builds and releases - test.yml: NEW - Responsible for running tests (multi-platform) - coverage.yml: Responsible for test coverage (single-platform) - security.yml: Responsible for security verification (multi-platform) - codeql.yaml: Unchanged - static analysis Changes: - Removed test job from build.yml (was running tests 4x) - Created new test.yml for multi-platform testing - Standardized cache keys with prefixes (build-, test-, coverage-, security-) - Removed 'cd keyring-cli' commands (workflows already in project root) - Removed clippy/format from build.yml (now in test.yml) Benefits: - Eliminates duplicate test execution (was: build.yml 3x + coverage.yml) - Clear separation of concerns - Better cache utilization - Faster CI feedback Co-Authored-By: Claude (glm-4.7) <noreply@anthropic.com>
1 parent 020bec4 commit 91cb1fa

4 files changed

Lines changed: 79 additions & 63 deletions

File tree

.github/workflows/build.yml

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ jobs:
3131
uses: actions/cache@v4
3232
with:
3333
path: ~/.cargo/registry
34-
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
34+
key: build-${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
3535

3636
- name: Cache cargo index
3737
uses: actions/cache@v4
3838
with:
3939
path: ~/.cargo/git
40-
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
40+
key: build-${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
4141

4242
- name: Cache cargo build
4343
uses: actions/cache@v4
4444
with:
4545
path: target
46-
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
46+
key: build-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
4747

4848
- name: Build for x86_64
4949
run: |
@@ -108,7 +108,7 @@ jobs:
108108
~/.cargo/registry
109109
~/.cargo/git
110110
target
111-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
111+
key: build-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
112112

113113
- name: Build
114114
run: |
@@ -163,7 +163,7 @@ jobs:
163163
~/.cargo/registry
164164
~/.cargo/git
165165
target
166-
key: ${{ runner.os }}-cargo-arm64-${{ hashFiles('**/Cargo.lock') }}
166+
key: build-${{ runner.os }}-cargo-arm64-${{ hashFiles('**/Cargo.lock') }}
167167

168168
- name: Build
169169
run: |
@@ -217,7 +217,7 @@ jobs:
217217
~/.cargo/registry
218218
~/.cargo/git
219219
target
220-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
220+
key: build-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
221221

222222
- name: Build
223223
run: |
@@ -266,7 +266,7 @@ jobs:
266266
~/.cargo/registry
267267
~/.cargo/git
268268
target
269-
key: ${{ runner.os }}-cargo-arm64-${{ hashFiles('**/Cargo.lock') }}
269+
key: build-${{ runner.os }}-cargo-arm64-${{ hashFiles('**/Cargo.lock') }}
270270

271271
- name: Build
272272
run: |
@@ -290,47 +290,3 @@ jobs:
290290
files: ok-windows-aarch64.zip
291291
generate_release_notes: true
292292

293-
# Run tests
294-
test:
295-
name: Run Tests
296-
runs-on: ${{ matrix.os }}
297-
strategy:
298-
matrix:
299-
os: [ubuntu-latest, macos-latest, windows-latest]
300-
rust: [stable]
301-
302-
steps:
303-
- name: Checkout code
304-
uses: actions/checkout@v4
305-
306-
- name: Install Rust toolchain
307-
uses: dtolnay/rust-toolchain@master
308-
with:
309-
toolchain: ${{ matrix.rust }}
310-
311-
- name: Install dependencies (Linux)
312-
if: runner.os == 'Linux'
313-
run: |
314-
sudo apt-get update
315-
sudo apt-get install -y pkg-config libssl-dev
316-
317-
- name: Cache cargo
318-
uses: actions/cache@v4
319-
with:
320-
path: |
321-
~/.cargo/registry
322-
~/.cargo/git
323-
target
324-
key: ${{ runner.os }}-test-${{ hashFiles('**/Cargo.lock') }}
325-
326-
- name: Run tests
327-
run: |
328-
cargo test --verbose --all-features
329-
330-
- name: Run clippy
331-
run: |
332-
cargo clippy -- -D warnings
333-
334-
- name: Check formatting
335-
run: |
336-
cargo fmt -- --check

.github/workflows/coverage.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,21 @@ jobs:
2525
~/.cargo/registry
2626
~/.cargo/git
2727
target
28-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
28+
key: coverage-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
2929

3030
- name: Run tests with coverage
3131
run: |
3232
cargo install cargo-tarpaulin
33-
cd keyring-cli
3433
cargo tarpaulin --out Html --output-dir coverage --timeout 300 --verbose
3534
3635
- name: Upload coverage report
3736
uses: actions/upload-artifact@v4
3837
with:
3938
name: coverage-report
40-
path: keyring-cli/coverage/
39+
path: coverage/
4140

4241
- name: Check coverage threshold
4342
run: |
44-
cd keyring-cli
4543
COVERAGE=$(cargo tarpaulin --out Json 2>/dev/null | jq '.coverage // 0' || echo "0")
4644
echo "Coverage: $COVERAGE%"
4745
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
@@ -53,7 +51,6 @@ jobs:
5351
5452
- name: Add coverage summary
5553
run: |
56-
cd keyring-cli
5754
COVERAGE=$(cargo tarpaulin --out Json 2>/dev/null | jq '.coverage // 0' || echo "0")
5855
echo "## Test Coverage" >> $GITHUB_STEP_SUMMARY
5956
echo "Current coverage: **$COVERAGE%**" >> $GITHUB_STEP_SUMMARY

.github/workflows/security.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,17 @@ jobs:
3838
~/.cargo/registry
3939
~/.cargo/git
4040
target
41-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
41+
key: security-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
4242

4343
- name: Build release without test-env
4444
run: |
45-
cd keyring-cli
4645
cargo build --release --no-default-features
4746
4847
- name: Verify test-env NOT in release binary (Linux/macOS)
4948
if: runner.os != 'Windows'
5049
run: |
5150
echo "Checking for test environment variables in release binary..."
52-
if grep -r "OK_MASTER_PASSWORD\|OK_CONFIG_DIR\|OK_DATA_DIR" keyring-cli/target/release/keyring-cli 2>/dev/null; then
51+
if grep -r "OK_MASTER_PASSWORD\|OK_CONFIG_DIR\|OK_DATA_DIR" target/release/keyring-cli 2>/dev/null; then
5352
echo "❌ ERROR: Test environment variables leaked to release!"
5453
exit 1
5554
fi
@@ -60,7 +59,7 @@ jobs:
6059
shell: pwsh
6160
run: |
6261
Write-Host "Checking for test environment variables in release binary..."
63-
$binaryPath = "keyring-cli\target\release\keyring-cli.exe"
62+
$binaryPath = "target\release\keyring-cli.exe"
6463
if (Test-Path $binaryPath) {
6564
$content = Get-Content $binaryPath -Raw -Encoding ASCII
6665
if ($content -match "OK_MASTER_PASSWORD|OK_CONFIG_DIR|OK_DATA_DIR") {
@@ -72,19 +71,16 @@ jobs:
7271
7372
- name: Verify test-env feature works
7473
run: |
75-
cd keyring-cli
7674
cargo build --features test-env
7775
echo "✅ Build with test-env feature successful"
7876
7977
- name: Run security audit
8078
run: |
8179
cargo install cargo-audit
82-
cd keyring-cli
8380
cargo audit || echo "⚠️ Security audit found potential issues"
8481
8582
- name: Check MSRV in Cargo.toml
8683
run: |
87-
cd keyring-cli
8884
if grep -q "rust-version" Cargo.toml; then
8985
echo "✅ MSRV declared in Cargo.toml"
9086
grep "rust-version" Cargo.toml

.github/workflows/test.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ master, develop ]
6+
pull_request:
7+
branches: [ master, develop ]
8+
workflow_dispatch:
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
RUST_BACKTRACE: 1
13+
14+
jobs:
15+
test:
16+
name: Test on ${{ matrix.os }}
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest, macos-latest, windows-latest]
21+
rust: [stable]
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Install Rust toolchain
28+
uses: dtolnay/rust-toolchain@stable
29+
with:
30+
toolchain: ${{ matrix.rust }}
31+
32+
- name: Install dependencies (Linux)
33+
if: runner.os == 'Linux'
34+
run: |
35+
sudo apt-get update
36+
sudo apt-get install -y pkg-config libssl-dev
37+
38+
- name: Cache cargo
39+
uses: actions/cache@v4
40+
with:
41+
path: |
42+
~/.cargo/registry
43+
~/.cargo/git
44+
target
45+
key: test-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
46+
47+
- name: Run tests
48+
run: |
49+
cargo test --verbose --all-features
50+
51+
- name: Run clippy
52+
run: |
53+
cargo clippy --all-features -- -D warnings
54+
55+
- name: Check formatting
56+
run: |
57+
cargo fmt --all -- --check
58+
59+
- name: Test summary
60+
run: |
61+
echo "## Test Results" >> $GITHUB_STEP_SUMMARY
62+
echo "" >> $GITHUB_STEP_SUMMARY
63+
echo "✅ Platform: ${{ runner.os }}" >> $GITHUB_STEP_SUMMARY
64+
echo "✅ Rust: ${{ matrix.rust }}" >> $GITHUB_STEP_SUMMARY
65+
echo "✅ Tests passed" >> $GITHUB_STEP_SUMMARY
66+
echo "✅ Clippy checks passed" >> $GITHUB_STEP_SUMMARY
67+
echo "✅ Format checks passed" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)