Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add semver script for determining latest aws-lc tag #105

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")
}