Skip to content

Commit 24feb04

Browse files
committed
ci: derive crate versions from git tag at release time
Cargo.toml and .cabal files now use 0.0.0-dev placeholders. The release workflow extracts the version from the git tag (v*.*.*) and patches all manifest files before publishing to crates.io and Hackage. Removes the need to manually bump version numbers.
1 parent 22e5f52 commit 24feb04

6 files changed

Lines changed: 34 additions & 13 deletions

File tree

.github/workflows/release.yml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,44 @@ jobs:
2020
- uses: dtolnay/rust-toolchain@stable
2121
- uses: Swatinem/rust-cache@v2
2222

23+
- name: Set version from tag
24+
run: |
25+
VERSION="${GITHUB_REF_NAME#v}"
26+
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
27+
sed -i "0,/version = \"0.0.0-dev\"/s//version = \"$VERSION\"/" hsrs-macros/Cargo.toml
28+
sed -i "0,/version = \"0.0.0-dev\"/s//version = \"$VERSION\"/" hsrs/Cargo.toml
29+
sed -i "0,/version = \"0.0.0-dev\"/s//version = \"$VERSION\"/" hsrs-codegen/Cargo.toml
30+
sed -i "s/hsrs-macros = { version = \"0.0.0-dev\"/hsrs-macros = { version = \"$VERSION\"/" hsrs/Cargo.toml
31+
cargo check --workspace
32+
2333
- name: Publish hsrs-macros
2434
run: |
25-
VERSION=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="hsrs-macros") | .version')
2635
if curl -sf "https://crates.io/api/v1/crates/hsrs-macros/$VERSION" > /dev/null 2>&1; then
2736
echo "hsrs-macros@$VERSION already published, skipping"
2837
else
29-
cargo publish -p hsrs-macros --token ${{ secrets.CRATES_IO_TOKEN }}
38+
cargo publish -p hsrs-macros --token ${{ secrets.CRATES_IO_TOKEN }} --allow-dirty
3039
fi
3140
3241
- name: Wait for crates.io index
3342
run: sleep 30
3443

3544
- name: Publish hsrs
3645
run: |
37-
VERSION=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="hsrs") | .version')
3846
if curl -sf "https://crates.io/api/v1/crates/hsrs/$VERSION" > /dev/null 2>&1; then
3947
echo "hsrs@$VERSION already published, skipping"
4048
else
41-
cargo publish -p hsrs --token ${{ secrets.CRATES_IO_TOKEN }}
49+
cargo publish -p hsrs --token ${{ secrets.CRATES_IO_TOKEN }} --allow-dirty
4250
fi
4351
4452
- name: Wait for crates.io index
4553
run: sleep 30
4654

4755
- name: Publish hsrs-codegen
4856
run: |
49-
VERSION=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name=="hsrs-codegen") | .version')
5057
if curl -sf "https://crates.io/api/v1/crates/hsrs-codegen/$VERSION" > /dev/null 2>&1; then
5158
echo "hsrs-codegen@$VERSION already published, skipping"
5259
else
53-
cargo publish -p hsrs-codegen --token ${{ secrets.CRATES_IO_TOKEN }}
60+
cargo publish -p hsrs-codegen --token ${{ secrets.CRATES_IO_TOKEN }} --allow-dirty
5461
fi
5562
5663
hackage:
@@ -66,8 +73,22 @@ jobs:
6673
ghc-version: "9.6"
6774
cabal-version: "3.14"
6875

76+
- name: Set version from tag
77+
run: |
78+
VERSION="${GITHUB_REF_NAME#v}"
79+
CABAL_VERSION=$(echo "$VERSION" | sed 's/\./\./g; s/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\1.\2.\3.0/')
80+
sed -i "s/^version: 0.0.0.0/version: $CABAL_VERSION/" hsrs.cabal
81+
6982
- name: Build sdist
7083
run: cabal sdist
7184

7285
- name: Upload to Hackage
73-
run: cabal upload --publish dist-newstyle/sdist/hsrs-*.tar.gz --token ${{ secrets.HACKAGE_TOKEN }}
86+
run: |
87+
VERSION="${GITHUB_REF_NAME#v}"
88+
CABAL_VERSION=$(echo "$VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\1.\2.\3.0/')
89+
TARBALL="dist-newstyle/sdist/hsrs-${CABAL_VERSION}.tar.gz"
90+
if curl -sf "https://hackage.haskell.org/package/hsrs-${CABAL_VERSION}" > /dev/null 2>&1; then
91+
echo "hsrs@$CABAL_VERSION already published on Hackage, skipping"
92+
else
93+
cabal upload --publish "$TARBALL" --token ${{ secrets.HACKAGE_TOKEN }}
94+
fi

hsrs-codegen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hsrs-codegen"
3-
version = "0.1.0"
3+
version = "0.0.0-dev"
44
edition = "2024"
55
license = "MIT OR Apache-2.0"
66
description = "Haskell code generator for hsrs FFI bindings"

hsrs-codegen/tests/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,5 @@ fn version_flag_exits_successfully() {
179179
let output = hsrs_codegen().arg("--version").output().unwrap();
180180
assert!(output.status.success());
181181
let stdout = String::from_utf8_lossy(&output.stdout);
182-
assert!(stdout.contains("0.1.0"));
182+
assert!(stdout.contains(env!("CARGO_PKG_VERSION")));
183183
}

hsrs-haskell/hsrs.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.4
22
name: hsrs
3-
version: 0.1.0.0
3+
version: 0.0.0.0
44
synopsis: Runtime support for hsrs-generated Haskell FFI bindings
55
description:
66
Provides the Haskell-side runtime needed by code generated

hsrs-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hsrs-macros"
3-
version = "0.1.0"
3+
version = "0.0.0-dev"
44
edition = "2024"
55
license = "MIT OR Apache-2.0"
66
description = "Proc macros for hsrs Rust-to-Haskell FFI bindings"

hsrs/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hsrs"
3-
version = "0.1.0"
3+
version = "0.0.0-dev"
44
edition = "2024"
55
license = "MIT OR Apache-2.0"
66
description = "Type-safe Rust-to-Haskell FFI with automatic binding generation"
@@ -10,7 +10,7 @@ keywords = ["ffi", "haskell", "bindings", "codegen"]
1010
categories = ["development-tools::ffi", "api-bindings"]
1111

1212
[dependencies]
13-
hsrs-macros = { version = "0.1.0", path = "../hsrs-macros" }
13+
hsrs-macros = { version = "0.0.0-dev", path = "../hsrs-macros" }
1414
safer-ffi = { version = "0.2.0-rc1", features = ["alloc"] }
1515
borsh = { workspace = true }
1616

0 commit comments

Comments
 (0)