Skip to content

Commit d81a252

Browse files
StarefossenCopilot
andcommitted
feat: inject release tag as version at build time via build.rs
CNCTL_VERSION env var overrides CARGO_PKG_VERSION at compile time so cnctl --version prints the date+sha release tag instead of 0.1.0. The release workflow now sets CNCTL_VERSION to the computed date+sha. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 60a73b8 commit d81a252

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ jobs:
6464

6565
- name: Build
6666
run: |
67+
COMMIT_SHA="${{ github.event.workflow_run.head_sha || github.sha }}"
68+
SHORT_SHA="${COMMIT_SHA:0:7}"
69+
VERSION="$(date -u +%Y.%m.%d)-${SHORT_SHA}"
6770
if [ "${{ matrix.cross }}" = "true" ]; then
68-
cross build --release --target ${{ matrix.target }}
71+
CNCTL_VERSION="$VERSION" cross build --release --target ${{ matrix.target }}
6972
else
70-
cargo build --release --target ${{ matrix.target }}
73+
CNCTL_VERSION="$VERSION" cargo build --release --target ${{ matrix.target }}
7174
fi
7275
shell: bash
7376

build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
// Allow overriding the version at build time (used by CI for date+sha releases).
3+
// Usage: CNCTL_VERSION="2026.04.05-abc1234" cargo build --release
4+
if let Ok(v) = std::env::var("CNCTL_VERSION") {
5+
println!("cargo:rustc-env=CARGO_PKG_VERSION={v}");
6+
}
7+
println!("cargo:rerun-if-env-changed=CNCTL_VERSION");
8+
}

0 commit comments

Comments
 (0)