Minor tweaks (#1)
Some checks failed
CI / Typos (push) Successful in 10s
CI / Clippy (push) Successful in 41s
CI / Check version (push) Failing after 3s
CI / Build and test (push) Successful in 55s

This commit is contained in:
2025-05-04 10:31:04 -07:00
committed by Mark
parent 64f45a443c
commit 3e1130a3b5
6 changed files with 96 additions and 24 deletions

View File

@ -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

View File

@ -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}}'

2
Cargo.lock generated
View File

@ -306,7 +306,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "pick"
version = "0.0.1"
version = "0.0.2"
dependencies = [
"anstyle",
"anyhow",

View File

@ -1,6 +1,6 @@
[package]
name = "pick"
version = "0.0.1"
version = "0.0.2"
edition = "2024"
#

View File

@ -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 {

View File

@ -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"]);