Skip to content

Commit

Permalink
Add semver script for determining latest aws-lc tag (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail authored Apr 14, 2023
1 parent 1e96011 commit 5c19a82
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ update-aws-lc-fips-sys:

update-aws-lc-sys:
git submodule update --init --remote --checkout -- aws-lc-sys/aws-lc
cd aws-lc-sys/aws-lc && \
git fetch --all && \
git tag -l | xargs ../../scripts/tools/semver.rs | xargs git checkout

update-submodules: update-aws-lc-fips-sys update-aws-lc-sys

Expand Down
41 changes: 41 additions & 0 deletions scripts/tools/semver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! clap = { version = "4.2.2", features = ["derive"] }
//! regex = "1.7.3"
//! semver = "1.0.17"
//! ```
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

use clap::Parser;

#[derive(Parser)]
#[command(about)]
struct Args {
tags: Vec<String>,
}

fn main() {
let args = Args::parse();

let input: Vec<String> = args.tags;

// Modified regex from https://semver.org/
let re = regex::Regex::new(
r"^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$",
).unwrap();

let mut tags: Vec<semver::Version> = input
.into_iter()
.filter(|t| re.is_match(t))
.map(|t| semver::Version::parse(t.strip_prefix("v").unwrap()).unwrap())
.collect();

tags.sort();

let latest = tags.pop().unwrap();

println!("v{latest}")
}

0 comments on commit 5c19a82

Please sign in to comment.