Skip to content

Commit aa729d8

Browse files
dkgouthamdkgouthamsvlachakis
authored
Add semver-checks workflow (#17)
Signed-off-by: stavrosvl7 <stavrosvl7@gmail.com> Co-authored-by: dkgoutham <d.goutham@iitg.ac.in> Co-authored-by: stavrosvl7 <stavrosvl7@gmail.com>
1 parent 13d4db7 commit aa729d8

11 files changed

Lines changed: 91 additions & 9 deletions

File tree

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
# just remove katex-header.html at the root and RUSTDOCFLAGS here
3232
# TODO(template) update the crate name
3333
- name: Build documentation
34-
run: RUSTDOCFLAGS="--html-in-header katex-header.html" cargo doc --no-deps -p mycrate
34+
run: RUSTDOCFLAGS="--html-in-header katex-header.html" cargo doc --no-deps -p template_crate
3535

3636
- name: Remove lock file
3737
run: rm target/doc/.lock
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-${{ 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"

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ After cloning the repository, follow the instructions below to run the documenta
3030
cargo doc
3131
```
3232

33-
Docs for `TODO(template) template-crate`:
33+
Docs for `TODO(template) template_crate`:
3434

3535
```sh
36-
RUSTDOCFLAGS="--html-in-header katex-header.html" cargo doc --no-deps -p template-crate --open
36+
RUSTDOCFLAGS="--html-in-header katex-header.html" cargo doc --no-deps -p template_crate --open
3737
```

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
# TODO(template) update for the crate name
33
[workspace]
4-
members = ["examples", "mycrate"]
4+
members = ["examples", "template_crate"]
55
resolver = "2"
6-
default-members = ["mycrate"]
6+
default-members = ["template_crate"]
77

88
[workspace.package]
99
version = "0.1.0"

examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ license.workspace = true
88

99
[dependencies]
1010
# TODO(template) update the crate name
11-
mycrate = { path = "../mycrate" }
11+
template_crate = { path = "../template_crate" }

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ To run an example
99
cargo run -p examples --bin addition
1010
```
1111

12-
* `addition` - shows how to add two bounded integers with the [`mycrate`](../mycrate/) library.
12+
* `addition` - shows how to add two bounded integers with the [`template_crate`](../template_crate/) library.

examples/src/bin/addition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// TODO(template) - remove/change the code below and rename the example
2-
use mycrate::add_small_integers;
2+
use template_crate::add_small_integers;
33

44
fn main() {
55
println!("{:?}", add_small_integers(6, 8));
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
# TODO(template) rename
3-
name = "mycrate"
3+
name = "template_crate"
44
version.workspace = true
55
edition.workspace = true
66
repository.workspace = true
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)