Skip to content
Open
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
86 changes: 75 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,82 @@ permissions:

jobs:

common:
uses: scm-rs/shared-workflows/.github/workflows/ci.yaml@main
msrv:
runs-on: ubuntu-latest
outputs:
rust-version: ${{ steps.get-version.outputs.rust-version }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Extract version
id: get-version
run: |
MSRV=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].rust_version')
echo "rust-version=$MSRV" >> $GITHUB_OUTPUT
- name: Show version
run: |
echo "MSRV: ${{ steps.get-version.outputs.rust-version }}"

ci:
preflight:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: webiny/[email protected]

- uses: Swatinem/rust-cache@v2
- uses: obi1kenobi/cargo-semver-checks-action@v2

- name: Check formatting
run: cargo fmt --check

check:
needs:
- common
if: always()
- msrv
- preflight
strategy:
matrix:
rust:
- stable
- ${{ needs.msrv.outputs.rust-version }}
os:
- ubuntu-22.04
- windows-2022
- macos-14
runs-on: ${{ matrix.os }}
steps:
- name: Success
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0
- name: Failure
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
- name: Dump matrix config
run: echo "${{ toJSON(matrix) }}"

- uses: actions/checkout@v4
with:
submodules: true
- uses: Swatinem/rust-cache@v2

- name: Install Rust ${{ matrix.rust }}
run: rustup install ${{ matrix.rust }} --no-self-update --component clippy

- name: Tree
run: cargo +${{ matrix.rust }} tree

- name: Clippy
run: cargo +${{ matrix.rust }} clippy --all-targets --tests --bins --all -- -D warnings

- name: Test
run: cargo +${{ matrix.rust }} test

- name: Install binstall
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash

- name: Install cargo-all-features
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: cargo binstall -y cargo-all-features --force

- name: Check (all features)
run: cargo check-all-features
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tests/spec/purl-spec"]
path = tests/spec/purl-spec
url = https://github.com/package-url/purl-spec
4 changes: 4 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ pub enum Error {
InvalidKey(String),
#[error("missing name")]
MissingName,
#[error("missing namespace")]
MissingNamespace,
#[error("invalid namespace component: {0:?}")]
InvalidNamespaceComponent(String),
#[error("missing version")]
MissingVersion,
#[error("missing scheme")]
MissingScheme,
#[error("missing type")]
Expand Down
29 changes: 23 additions & 6 deletions src/purl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS
.add(b'?')
.add(b'{')
.add(b'}')
// .add(b'/')
.add(b'/')
// .add(b':')
.add(b';')
.add(b'=')
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'a> PackageUrl<'a> {
t = to_lowercase(t);
// lowercase name if required by type and needed
match t.as_ref() {
"bitbucket" | "deb" | "github" | "hex" | "npm" => {
"bitbucket" | "deb" | "github" | "hex" | "npm" | "composer" | "mlflow" => {
n = to_lowercase(n);
}
"pypi" => {
Expand Down Expand Up @@ -158,7 +158,7 @@ impl<'a> PackageUrl<'a> {
{
let mut n = namespace.into();
match self.ty.as_ref() {
"bitbucket" | "deb" | "github" | "golang" | "hex" | "rpm" => {
"bitbucket" | "deb" | "github" | "golang" | "hex" | "rpm" | "composer" => {
n = to_lowercase(n);
}
_ => {}
Expand All @@ -179,7 +179,14 @@ impl<'a> PackageUrl<'a> {
where
V: Into<Cow<'a, str>>,
{
self.version = Some(version.into());
let mut v = version.into();
match self.ty.as_ref() {
"huggingface" => {
v = to_lowercase(v);
}
_ => {}
}
self.version = Some(v);
self
}

Expand Down Expand Up @@ -251,13 +258,23 @@ impl FromStr for PackageUrl<'static> {

// Special rules for some types
match ty.as_ref() {
"bitbucket" | "github" => {
"bitbucket" | "github" | "composer" => {
name = name.to_lowercase();
namespace = namespace.map(|ns| ns.to_lowercase());
}
"pypi" => {
name = name.replace('_', "-").to_lowercase();
}
"cpan" => {
if namespace.is_none() {
return Err(Error::MissingNamespace);
}
}
"cran" => {
if version.is_none() {
return Err(Error::MissingVersion);
}
}
_ => {}
};

Expand Down Expand Up @@ -396,7 +413,7 @@ mod tests {
)
.unwrap();
let encoded = purl.to_string();
assert_eq!(encoded, "pkg:deb/ubuntu/gnome-calculator@1:41.1-2ubuntu2?vcs_url=git%2Bhttps://salsa.debian.org/gnome-team/gnome-calculator.git%40debian/1%2541.1-2");
assert_eq!(encoded, "pkg:deb/ubuntu/gnome-calculator@1:41.1-2ubuntu2?vcs_url=git%2Bhttps:%2F%2Fsalsa.debian.org%2Fgnome-team%2Fgnome-calculator.git%40debian%2F1%2541.1-2");
}

#[cfg(feature = "serde")]
Expand Down
3 changes: 1 addition & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[macro_use]
extern crate serde;
extern crate packageurl;
extern crate serde;
extern crate serde_json;

mod spec;
Loading