From 28d63c14e38236a2aa636ddd0b5da8a31051b193 Mon Sep 17 00:00:00 2001 From: Alex Maldonado Date: Fri, 7 Aug 2026 23:20:42 -0400 Subject: [PATCH] feat: git-based nightly versions --- .bumpversion.toml | 2 +- .gitea/workflows/ci.yml | 2 ++ .gitea/workflows/docs.yml | 2 ++ .gitea/workflows/nightly.yml | 2 ++ .gitea/workflows/release.yml | 1 + .gitea/workflows/sync-readme.yml | 3 +-- Cargo.toml | 2 +- build.rs | 22 ++++++++++++++++++++++ pixi.toml | 2 +- scripts/nightly-version.sh | 27 +++++++++++++++++++++++++++ src/cli.rs | 4 ++-- 11 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 build.rs create mode 100755 scripts/nightly-version.sh diff --git a/.bumpversion.toml b/.bumpversion.toml index 698f98b..1b100e5 100644 --- a/.bumpversion.toml +++ b/.bumpversion.toml @@ -1,5 +1,5 @@ [tool.bumpversion] -current_version = "26.8.0" +current_version = "0.0.0" parse = """(?x) (?P (?:[1-9][0-9]?)\\. # YY short year, no leading zero diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index abb8b88..53e9068 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -9,6 +9,8 @@ on: jobs: check: runs-on: pixi-build-rust + env: + CARGO_TARGET_DIR: /opt/cargo-target/${{ gitea.repository }} steps: - uses: actions/checkout@v4 diff --git a/.gitea/workflows/docs.yml b/.gitea/workflows/docs.yml index 0ae5138..25082ba 100644 --- a/.gitea/workflows/docs.yml +++ b/.gitea/workflows/docs.yml @@ -13,6 +13,8 @@ env: jobs: deploy: runs-on: pixi-build-rust + env: + CARGO_TARGET_DIR: /opt/cargo-target/${{ gitea.repository }} steps: - uses: actions/checkout@v4 diff --git a/.gitea/workflows/nightly.yml b/.gitea/workflows/nightly.yml index 01c43e7..09af897 100644 --- a/.gitea/workflows/nightly.yml +++ b/.gitea/workflows/nightly.yml @@ -13,6 +13,7 @@ jobs: permissions: contents: write env: + CARGO_TARGET_DIR: /opt/cargo-target/${{ gitea.repository }} API: ${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }} TOKEN: ${{ secrets.GITEA_TOKEN }} TAG: nightly @@ -21,6 +22,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + fetch-tags: true - name: Install the pinned toolchain run: pixi install diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 38a59d4..9a8d1e1 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -11,6 +11,7 @@ jobs: permissions: contents: write env: + CARGO_TARGET_DIR: /opt/cargo-target/${{ gitea.repository }} API: ${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }} TOKEN: ${{ secrets.GITEA_TOKEN }} TAG: ${{ gitea.ref_name }} diff --git a/.gitea/workflows/sync-readme.yml b/.gitea/workflows/sync-readme.yml index 63993b3..a1aa5a3 100644 --- a/.gitea/workflows/sync-readme.yml +++ b/.gitea/workflows/sync-readme.yml @@ -12,8 +12,7 @@ jobs: sync: runs-on: github-readme-sync steps: - - name: Check out the Gitea repo - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - name: Build the combined README run: | diff --git a/Cargo.toml b/Cargo.toml index 421d1e9..2fd4f8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "coursebank" -version = "26.8.0" +version = "0.0.0" edition = "2024" rust-version = "1.85" description = "Author, assemble, administer, and analyze leveled course assessments from YAML item banks" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..8cd16c1 --- /dev/null +++ b/build.rs @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: Prosperity-3.0.0 +// Copyright Scientific Computing Studio +// Source: https://git.scient.ing/education/coursebank + +//! Chooses the version string compiled into the binary. +//! +//! Normal and release builds use the version from `Cargo.toml`. Nightly builds +//! set `COURSEBANK_VERSION` (to a git-derived string; see +//! `scripts/nightly-version.sh`) so `coursebank --version` reflects how far the +//! build is past the last release rather than an unreleased number. + +use std::env; + +fn main() { + let version = match env::var("COURSEBANK_VERSION") { + Ok(v) if !v.trim().is_empty() => v, + _ => env::var("CARGO_PKG_VERSION").expect("cargo always sets CARGO_PKG_VERSION"), + }; + println!("cargo:rustc-env=COURSEBANK_VERSION={version}"); + println!("cargo:rerun-if-env-changed=COURSEBANK_VERSION"); + println!("cargo:rerun-if-env-changed=CARGO_PKG_VERSION"); +} diff --git a/pixi.toml b/pixi.toml index 36b7112..c0f76be 100644 --- a/pixi.toml +++ b/pixi.toml @@ -1,6 +1,6 @@ [workspace] name = "coursebank" -version = "26.8.0" +version = "0.0.0" authors = ["Scientific Computing Studio "] channels = ["conda-forge"] platforms = ["linux-64", "osx-arm64", "osx-64"] diff --git a/scripts/nightly-version.sh b/scripts/nightly-version.sh new file mode 100755 index 0000000..c7e592a --- /dev/null +++ b/scripts/nightly-version.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Print an auto-generated nightly version string derived from git history: +# +# +.g e.g., 26.8.0+14.gb1a2c3d4 +# +# When no release has been tagged yet, the base is 0.0.0 and the count is the +# total number of commits: +# +# 0.0.0+.g e.g., 0.0.0+57.gb1a2c3d4 +# +# The `+...` part is SemVer build metadata, so the string stays a valid version +# and never sorts ahead of the release it is based on. Needs full history and +# tags (check out with fetch-depth: 0 and fetch-tags: true). Release tags are +# matched as N.N.N; the moving `nightly` tag is ignored. +set -euo pipefail +sha="$(git rev-parse --short=8 HEAD)" +if desc="$(git describe --tags --long \ + --match '[0-9]*.[0-9]*.[0-9]*' --exclude nightly 2>/dev/null)"; then + # desc is --g; the tag itself has no '-', so strip from the right. + rest="${desc%-g*}" # - + n="${rest##*-}" # + tag="${rest%-*}" # + echo "${tag}+${n}.g${sha}" +else + n="$(git rev-list --count HEAD)" + echo "0.0.0+${n}.g${sha}" +fi diff --git a/src/cli.rs b/src/cli.rs index 1870ee5..81e6abf 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -27,7 +27,7 @@ use coursebank::store; /// Manage course item banks, assessments, and the analysis that comes back. #[derive(Debug, Parser)] -#[command(name = "coursebank", version, about, long_about = None)] +#[command(name = "coursebank", version = env!("COURSEBANK_VERSION"), about, long_about = None)] pub(crate) struct Cli { /// Course directory, the one holding course.yaml. #[arg(long, short = 'C', global = true, default_value = ".")] @@ -584,4 +584,4 @@ mod tests { fn the_cli_rejects_an_unknown_subcommand() { assert!(Cli::try_parse_from(["coursebank", "frobnicate"]).is_err()); } -} +} \ No newline at end of file