Skip to content

Commit 47a3b8b

Browse files
frozenspiderWiseMrMusa
authored andcommitted
Make caching GitHub actions use separate caches (#35)
A follow-up to #34 Once cache is formed, it's not updated anymore (see actions/toolkit#505). As such, it doesn't make sense having the cache shared between unrelated actions. Made each action using a cache key tied to its tool.
1 parent c08ad17 commit 47a3b8b

4 files changed

Lines changed: 88 additions & 6 deletions

File tree

.github/workflows/coverage-pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ jobs:
9797
~/.cargo/registry/cache/
9898
~/.cargo/git/db/
9999
target/
100-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
101-
restore-keys: ${{ runner.os }}-cargo-
100+
key: ${{ runner.os }}-cargo-llvm-cov-${{ hashFiles('**/Cargo.lock') }}
101+
restore-keys: ${{ runner.os }}-cargo-llvm-cov
102102

103103
- name: Install cargo-llvm-cov (fallback path)
104104
if: ${{ steps.base_art.outputs.found == 'false' }}

.github/workflows/coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
~/.cargo/registry/cache/
2929
~/.cargo/git/db/
3030
target/
31-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
32-
restore-keys: ${{ runner.os }}-cargo-
31+
key: ${{ runner.os }}-cargo-llvm-cov-${{ hashFiles('**/Cargo.lock') }}
32+
restore-keys: ${{ runner.os }}-cargo-llvm-cov
3333

3434
- run: which cargo-llvm-cov || cargo install cargo-llvm-cov
3535
- run: rustup component add llvm-tools-preview

.github/workflows/dependency-audit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
~/.cargo/registry/cache/
3333
~/.cargo/git/db/
3434
target/
35-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
36-
restore-keys: ${{ runner.os }}-cargo-
35+
key: ${{ runner.os }}-cargo-deny-${{ hashFiles('**/Cargo.lock') }}
36+
restore-keys: ${{ runner.os }}-cargo-deny
3737

3838
- name: Run audit-check action
3939
run: |
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Semver checks
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
paths: ['**/Cargo.toml'] # Only run when Cargo.toml changes
7+
push:
8+
tags: ['v*'] # Run on version tags
9+
10+
# Limit permissions to minimum required
11+
permissions:
12+
contents: read
13+
14+
env:
15+
CARGO_TERM_COLOR: always
16+
CARGO_INCREMENTAL: 0
17+
18+
jobs:
19+
semver:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
# cargo-semver-checks needs the full git history to compare versions
27+
fetch-depth: 0
28+
29+
- name: Cache cargo registry
30+
uses: actions/cache@v4
31+
with:
32+
path: |
33+
~/.cargo/registry/index/
34+
~/.cargo/registry/cache/
35+
~/.cargo/git/db/
36+
key: ${{ runner.os }}-cargo-semver-checks-${{ hashFiles('**/Cargo.lock') }}
37+
restore-keys: |
38+
${{ runner.os }}-cargo-semver-checks
39+
40+
- name: Get latest version tag
41+
id: get-baseline
42+
run: |
43+
# Find the latest version tag (v0.1.0 or higher)
44+
latest_tag=$(git describe --tags --abbrev=0 --match='v*' 2>/dev/null || echo "")
45+
if [ -z "$latest_tag" ]; then
46+
echo "No version tags found - skipping semver check"
47+
echo "This is normal for new projects or templates"
48+
echo "skip=true" >> $GITHUB_OUTPUT
49+
else
50+
# Extract version without 'v' prefix for comparison
51+
version=${latest_tag#v}
52+
53+
# Check if version is >= 0.1.0 (using semver comparison)
54+
if printf '%s\n%s\n' "0.1.0" "$version" | sort -V | head -n1 | grep -q "^0\.1\.0$"; then
55+
echo "Found suitable baseline tag: $latest_tag (>= v0.1.0)"
56+
echo "baseline_rev=$latest_tag" >> $GITHUB_OUTPUT
57+
echo "skip=false" >> $GITHUB_OUTPUT
58+
else
59+
echo "Found tag $latest_tag but it's < v0.1.0 - skipping semver check"
60+
echo "Semver checking typically starts from v0.1.0 when APIs stabilize"
61+
echo "skip=true" >> $GITHUB_OUTPUT
62+
fi
63+
fi
64+
65+
- name: Check semver compatibility
66+
if: steps.get-baseline.outputs.skip == 'false'
67+
uses: obi1kenobi/cargo-semver-checks-action@v2
68+
with:
69+
baseline-rev: ${{ steps.get-baseline.outputs.baseline_rev }}
70+
verbose: true
71+
72+
- name: Semver check skipped
73+
if: steps.get-baseline.outputs.skip == 'true'
74+
run: |
75+
echo "✅ Semver check skipped - no suitable version tags found"
76+
echo "To enable semver checking:"
77+
echo "1. Tag your first stable release: git tag v0.1.0"
78+
echo "2. Push the tag: git push origin v0.1.0"
79+
echo "3. Future changes will be checked against tagged versions"
80+
echo ""
81+
echo "Note: Semver checking starts from v0.1.0 as this indicates"
82+
echo "the beginning of API stability commitments in Rust projects"

0 commit comments

Comments
 (0)