From 42bad8371f0070b4a8abbb2d3c31ed1029e446d0 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 4 May 2025 10:17:09 -0700 Subject: [PATCH 1/3] Simplify regex --- src/manifest/rule.rs | 62 +++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/src/manifest/rule.rs b/src/manifest/rule.rs index 2f73011..b2b87cc 100644 --- a/src/manifest/rule.rs +++ b/src/manifest/rule.rs @@ -25,34 +25,26 @@ impl RegexSegment { // Neighboring doublestar is always responsible for slashes (_, Self::Single(x), Some(Self::DoubleStar)) => x.to_owned(), - // [^/]+ is a "segment" (a block of non-slash chars) - // The "base" doublestar pattern is a segment - // followed by zero or more segments prefixed by a slash. - // // No additional slashes - (None, Self::DoubleStar, None) => "((?:[^/]+(?:[/][^/]+)*)?)".into(), + (None, Self::DoubleStar, None) => "((?:.*)?)".into(), + + // Leading slash + (Some(Self::Single(_)), Self::DoubleStar, None) => "((?:[/].*)?)".into(), + + // Trailing slash + (None, Self::DoubleStar, Some(Self::Single(_))) => "((?:.*[/])?)".into(), + + // Leading and trailing slash. + // Also, replace self with a [/] when empty. + (Some(Self::Single(_)), Self::DoubleStar, Some(Self::Single(_))) => { + "((?:[/].*[/])|[/])".into() + } // Doublestars cannot be neighbors (_, Self::DoubleStar, Some(Self::DoubleStar)) | (Some(Self::DoubleStar), Self::DoubleStar, _) => { unreachable!("consecutive doublestars must be reduced") } - - // Leading slash - (Some(Self::Single(_)), Self::DoubleStar, None) => { - "((?:[/][^/]+(?:[/][^/]+)*)?)".into() - } - - // Trailing slash - (None, Self::DoubleStar, Some(Self::Single(_))) => { - "((?:[^/]+(?:[/][^/]+)*[/])?)".into() - } - - // Leading and trailing slash. - // Also, replace self with a [/] when empty. - (Some(Self::Single(_)), Self::DoubleStar, Some(Self::Single(_))) => { - "((?:[/][^/]+(?:[/][^/]+)*[/])|[/])".into() - } } } } @@ -301,6 +293,34 @@ mod tests { assert!(!regex.is_match("root/testfile")); assert!(!regex.is_match("root/testxxfile")); } + + #[test] + fn doublestar_nullable() { + let regex = rule_regex(&["root/**/file"]); + + assert!(regex.is_match("root/test/file")); + assert!(regex.is_match("root/file")); + assert!(!regex.is_match("rootfile")); + } + + #[test] + fn doublestar_nullable_post() { + let regex = rule_regex(&["root/**"]); + + assert!(regex.is_match("root")); + assert!(regex.is_match("root/file")); + assert!(!regex.is_match("rootfile")); + } + + #[test] + fn doublestar_nullable_pre() { + let regex = rule_regex(&["**/file"]); + + assert!(regex.is_match("file")); + assert!(regex.is_match("root/file")); + assert!(!regex.is_match("rootfile")); + } + #[test] fn doublestar_bad_extension() { let regex = rule_regex(&["**.flac"]); -- 2.49.0 From 65b60029aed2db641c4f45b50e105a3d084b2e2e Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 4 May 2025 10:26:54 -0700 Subject: [PATCH 2/3] CI --- .gitea/workflows/ci.yml | 33 +++++++++++++++++++++++++++++++++ .gitea/workflows/release.yml | 19 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 37ba63b..289f812 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -52,3 +52,36 @@ jobs: - name: Test run: cargo test --release + + check-version: + name: Check version + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: check version + run: | + # Get base branch (usually main) + BASE_REF="${{ github.base_ref }}" + if [ -z "$BASE_REF" ]; then + BASE_REF="main" + fi + + # Get current version + CURRENT_VERSION=$(grep -m 1 '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/') + echo "Current version: $CURRENT_VERSION" + + # Get version from base branch + git fetch origin $BASE_REF + BASE_VERSION=$(git show origin/$BASE_REF:Cargo.toml | grep -m 1 '^version = ' | sed 's/version = "\(.*\)"/\1/') + echo "Base version: $BASE_VERSION" + + # Check if version changed + if [ "$CURRENT_VERSION" = "$BASE_VERSION" ]; then + echo "::error::Version in Cargo.toml has not been changed." + exit 1 + else + echo "Version has been updated from $BASE_VERSION to $CURRENT_VERSION" + fi diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..ec13cd6 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,19 @@ +name: Release + +on: + push: + branches: + - main + workflow_dispatch: + +release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + id: use-go-action + uses: https://gitea.com/actions/release-action@main + with: + api_key: '${{secrets.RELEASE_TOKEN}}' \ No newline at end of file -- 2.49.0 From e1e9b28a807e087d09d04a77ced5171c1653764f Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 4 May 2025 10:28:45 -0700 Subject: [PATCH 3/3] version --- Cargo.lock | 2 +- Cargo.toml | 2 +- default.nix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c8dfd0d..2879e5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -306,7 +306,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "pick" -version = "0.0.1" +version = "0.0.2" dependencies = [ "anstyle", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index ade33b3..e59d653 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pick" -version = "0.0.1" +version = "0.0.2" edition = "2024" # diff --git a/default.nix b/default.nix index 0deb489..a38c710 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,7 @@ { lib, fetchgit, rustPlatform }: rustPlatform.buildRustPackage rec { pname = "pick"; - version = "0.0.1"; + version = "0.0.2"; cargoLock.lockFile = src + /Cargo.lock; src = builtins.fetchGit { -- 2.49.0