Skip to content

Commit

Permalink
Only validate tags for the relevant project in CI
Browse files Browse the repository at this point in the history
With this patch, we ignore tags when checking the version string in the
CI unless we are currently building the relevant project for the runner.
This means that the NKPK build does no longer fail the CI when running
on a release tag for the NK3 firmware.
  • Loading branch information
robin-nitrokey committed Mar 6, 2024
1 parent 3932535 commit 107971a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions components/utils/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use semver::{BuildMetadata, Prerelease, Version};

const PATTERN_PRE: &str = r"rc\.\d+";

pub fn version_string(cargo_pkg_version: &str) -> String {
pub fn version_string(project: &str, cargo_pkg_version: &str) -> String {
let mut version = crate_version(cargo_pkg_version);
let test_prerelease = test_prerelease();

if let Some(tag_version) = tag_version() {
if let Some(tag_version) = tag_version(project) {
assert_eq!(
tag_version.major, version.major,
"bad major component in tag"
Expand Down Expand Up @@ -80,7 +80,10 @@ fn crate_version(cargo_pkg_version: &str) -> Version {
version
}

fn tag_version() -> Option<Version> {
fn tag_version(project: &str) -> Option<Version> {
if option_env!("CI_PROJECT_NAME")? != project {
return None;
}
option_env!("CI_COMMIT_TAG")
.map(|s| s.strip_prefix('v').expect("tag must start with v"))
.map(|s| Version::parse(s).expect("failed to parse version from tag"))
Expand Down
2 changes: 1 addition & 1 deletion runners/embedded/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn generate_memory_x(outpath: &Path, template: &str, regions: &MemoryRegions) {
fn main() -> Result<(), Box<dyn error::Error>> {
println!(
"cargo:rustc-env=NK3_FIRMWARE_VERSION={}",
utils::version_string(env!("CARGO_PKG_VERSION"))
utils::version_string("nitrokey-3-firmware", env!("CARGO_PKG_VERSION"))
);

// @todo: add profile 'platform' items and cross-check them here ...
Expand Down
2 changes: 1 addition & 1 deletion runners/nkpk/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn generate_memory_x(outpath: &Path, template: &str, regions: &MemoryRegions) {
fn main() -> Result<(), Box<dyn error::Error>> {
println!(
"cargo:rustc-env=NKPK_FIRMWARE_VERSION={}",
utils::version_string(env!("CARGO_PKG_VERSION"))
utils::version_string("nitrokey-passkey-firmware", env!("CARGO_PKG_VERSION"))
);

if MEMORY_REGIONS.filesystem.start & 0x3ff != 0 {
Expand Down
2 changes: 1 addition & 1 deletion runners/usbip/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
println!(
"cargo:rustc-env=USBIP_FIRMWARE_VERSION={}",
utils::version_string(env!("CARGO_PKG_VERSION"))
utils::version_string("nitrokey-3-firmware", env!("CARGO_PKG_VERSION"))
);
}

0 comments on commit 107971a

Please sign in to comment.