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-${{ hashFiles('**/Cargo.lock') }}
37+ restore-keys : |
38+ ${{ runner.os }}-cargo-
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