Skip to content
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
44 changes: 36 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,56 @@ env:
RUSTFLAGS: "-Dwarnings"

jobs:
check-linux:
name: check-linux
runs-on: ubuntu-latest
lint-and-test:
name: Run linters and tests
strategy:
matrix:
platform:
- os_name: Linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-musl
bin: coman
name: coman-Linux-x86_64-musl.tar.gz
cargo_command: cargo

- os_name: Windows-aarch64
os: windows-latest
target: aarch64-pc-windows-msvc
bin: coman.exe
name: coman-Windows-aarch64.zip
cargo_command: cargo

# enable this if there's ever a case where something works on linux but not on macos
# - os_name: macOS-x86_64
# os: macOS-latest
# target: x86_64-apple-darwin
# bin: coman
# name: coman-Darwin-x86_64.tar.gz
# cargo_command: cargo
runs-on: ${{ matrix.platform.os }}
steps:
- name: Checkout
uses: actions/checkout@v5
- name: setup rust
run: |
rustup update stable
rustup default stable
rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt
- name: Install toolchain
# nightly needed for cargo fmt
uses: dtolnay/rust-toolchain@nightly
with:
targets: ${{ matrix.platform.target }}
components: clippy rustfmt
- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: "v0-rust"
cache-workspace-crates: "true"
- name: install tooling
run: cargo install oas3-gen@0.21.1
- name: Build
run: cargo build --verbose
- name: Check formatting
if: contains(matrix.platform.os, 'ubuntu')
run: cargo +nightly fmt --check
- name: Lint
if: contains(matrix.platform.os, 'ubuntu')
run: cargo clippy --all-targets --all-features -p coman
- name: Test
run: cargo test --verbose
48 changes: 48 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions coman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ aws-sdk-s3 = "1.115.0"
[build-dependencies]
anyhow = "1.0.90"
vergen-gix = { version = "1.0.2", features = ["build", "cargo"] }

[dev-dependencies]
rstest = "0.26.1"
56 changes: 46 additions & 10 deletions coman/src/util/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use nom::{
bytes::tag,
character::complete::{alphanumeric1, digit1},
combinator::{complete, opt, recognize},
multi::separated_list1,
multi::{many_m_n, many1, separated_list0, separated_list1},
sequence::{preceded, terminated},
};
use oci_distribution::{
Expand Down Expand Up @@ -127,18 +127,31 @@ impl FromStr for DockerImageUrl {
type Err = Report;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut parser = complete((
opt(terminated(
// see https://ktomk.github.io/pipelines/doc/DOCKER-NAME-TAG.html#syntax
let host = opt(terminated(
alt((
recognize((separated_list1(tag("."), alphanumeric1), tag(":"), digit1)),
recognize(separated_list1(tag("."), alphanumeric1)),
)),
tag("/"),
));
let image = recognize(separated_list0(
tag("/"),
separated_list0(
alt((
recognize((separated_list1(tag("."), alphanumeric1), tag(":"), digit1)),
recognize(separated_list1(tag("."), alphanumeric1)),
tag("."),
recognize(many_m_n(1, 2, tag("_"))),
recognize(many1(tag("-"))),
)),
tag("/"),
)),
alt((recognize((alphanumeric1, tag("/"), alphanumeric1)), alphanumeric1)),
opt(preceded(tag(":"), alphanumeric1)),
opt(preceded(tag("@sha256:"), alphanumeric1)),
alphanumeric1,
),
));
let docker_tag = opt(preceded(
tag(":"),
recognize(separated_list0(alt((tag("."), tag("-"))), alphanumeric1)),
));
let digest = opt(preceded(tag("@sha256:"), alphanumeric1));
let mut parser = complete((host, image, docker_tag, digest));
let parsed: DockerParseType = parser.parse(s);
match parsed {
Ok(result) => Ok(DockerImageUrl {
Expand Down Expand Up @@ -178,3 +191,26 @@ impl Display for DockerImageUrl {
Ok(())
}
}

#[cfg(test)]
mod tests {
use rstest::rstest;

use super::*;

#[rstest]
#[case("ubuntu",(None,"ubuntu",None,None))]
#[case("docker.io/library/hello-world:latest@sha256:deadbeef",(Some("docker.io"),"library/hello-world",Some("latest"),Some("deadbeef")))]
#[case("ghcr.io/swissdatasciencecenter/renku-frontend-buildpacks/run-image:0.2.1",(Some("ghcr.io"),"swissdatasciencecenter/renku-frontend-buildpacks/run-image",Some("0.2.1"),None))]
#[case("test.ghcr.io/a/b/c/d/e:a-1.f-2", (Some("test.ghcr.io"), "a/b/c/d/e", Some("a-1.f-2"), None))]
fn test_docker_parsing(
#[case] docker_url: &str,
#[case] expected: (Option<&str>, &str, Option<&str>, Option<&str>),
) {
let image = DockerImageUrl::from_str(docker_url).expect("couldn't parse image");
assert_eq!(image.registry, expected.0.map(|s| s.to_owned()));
assert_eq!(image.image.as_str(), expected.1);
assert_eq!(image.tag, expected.2.map(|s| s.to_owned()));
assert_eq!(image.digest, expected.3.map(|s| s.to_owned()));
}
}
2 changes: 1 addition & 1 deletion firecrest_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! AUTO-GENERATED CODE - DO NOT EDIT!
//!
//! FirecREST
//! Source: /tmp/.tmprFbIr1.json
//! Source: /tmp/.tmppwtkBD.json
//! Version: 2.4.1
//! Generated by `oas3-gen v0.21.1`
//!
Expand Down