diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 5508090c..24ae301c 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup ruby uses: ruby/setup-ruby@v1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ec49e4c..a4c8bf1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,18 +10,20 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macOS-latest] + os: [ubuntu-latest, windows-latest, macos-latest] rust: [beta, stable] steps: - name: Checkout Repository - uses: actions/checkout@master + uses: actions/checkout@v4 - name: Install Rust toolchain ${{ matrix.rust }} uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: ${{ matrix.rust }} - components: rustfmt, clippy override: true + - name: Install rustfmt and clippy + run: | + rustup component add rustfmt clippy || true - name: Install wasm32-unknown-unknown for ${{ matrix.rust }} uses: actions-rs/toolchain@v1 with: @@ -31,25 +33,33 @@ jobs: # Work around https://github.com/actions/cache/issues/403 by using GNU tar # instead of BSD tar. - name: Install GNU tar - if: matrix.os == 'macOS-latest' + if: matrix.os == 'macos-latest' run: | - brew install gnu-tar - echo PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" >> $GITHUB_ENV + # Install GNU tar if not present, on macOS Homebrew may be in different locations + if ! command -v gtar >/dev/null 2>&1; then + brew install gnu-tar || true + fi + # Add GNU tar to PATH via GITHUB_ENV for actions that rely on gnu-tar + if [ -d "/usr/local/opt/gnu-tar/libexec/gnubin" ]; then + echo "PATH=/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" >> $GITHUB_ENV + elif [ -d "/opt/homebrew/opt/gnu-tar/libexec/gnubin" ]; then + echo "PATH=/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH" >> $GITHUB_ENV + fi - name: Cache cargo registry - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: ~/.cargo/registry - key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}-${{ secrets.CACHE_VERSION }} + key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}-${{ secrets.CACHE_VERSION || github.run_id }} - name: Cache cargo index - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: ~/.cargo/git - key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-index-${{ hashFiles('**/Cargo.toml') }}-${{ secrets.CACHE_VERSION }} + key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-index-${{ hashFiles('**/Cargo.toml') }}-${{ secrets.CACHE_VERSION || github.run_id }} - name: Cache cargo build - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: target - key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }}-${{ secrets.CACHE_VERSION }} + key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }}-${{ secrets.CACHE_VERSION || github.run_id }} - name: Release build async-std uses: actions-rs/cargo@v1 with: @@ -72,6 +82,8 @@ jobs: args: --no-default-features --features runtime-tokio,cached,glob,ip,watcher,logging,incremental,explain - name: Cargo Check Wasm uses: actions-rs/cargo@v1 + env: + RUSTFLAGS: '--cfg getrandom_backend="wasm_js"' with: command: check args: --target wasm32-unknown-unknown --no-default-features --features runtime-async-std,cached,glob,ip,watcher,logging,incremental diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index faf5055b..71341357 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout Repository - uses: actions/checkout@master + uses: actions/checkout@v4 - name: Install Rust toolchain uses: actions-rs/toolchain@v1 @@ -32,6 +32,6 @@ jobs: cargo tarpaulin --no-default-features --features runtime-async-std,cached,glob,ip,watcher,logging,incremental,explain - name: Upload to codecov.io - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 with: token: ${{secrets.CODECOV_TOKEN}} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c829630d..0a95dde1 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -7,24 +7,31 @@ jobs: name: run benchmark runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v5 with: ref: ${{github.event.pull_request.head.ref}} repository: ${{github.event.pull_request.head.repo.full_name}} + fetch-depth: 0 - uses: actions-rs/toolchain@v1 with: toolchain: stable override: true profile: minimal - name: Cache cargo - uses: actions/cache@v2.1.4 + uses: actions/cache@v4 with: path: | - target - ~/.cargo/git - ~/.cargo/registry + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - uses: smrpn/criterion-compare-action@move_to_actions + restore-keys: | + ${{ runner.os }}-cargo- + - name: Install critcmp with force + run: cargo install critcmp --force + - uses: smrpn/criterion-compare-action@master with: cwd: benches token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/rustdoc.yml b/.github/workflows/rustdoc.yml index 234c4ad1..e668e1bd 100644 --- a/.github/workflows/rustdoc.yml +++ b/.github/workflows/rustdoc.yml @@ -12,7 +12,7 @@ jobs: steps: - name: Checkout Repository - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Install Rust toolchain uses: actions-rs/toolchain@v1 diff --git a/Cargo.toml b/Cargo.toml index f4f54825..d6efdf8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ runtime-tokio = ["tokio/fs", "tokio/io-util"] watcher = [] [target.'cfg(target_arch = "wasm32")'.dependencies] -getrandom = { version = "0.2", features = ["js"] } +getrandom = { version = "0.3", features = ["wasm_js"] } wasm-bindgen-test = "0.3.49" [target.'cfg(target_arch = "wasm32")'.dev-dependencies] diff --git a/src/adapter/file_adapter.rs b/src/adapter/file_adapter.rs index ba9042a7..ff50d1f7 100644 --- a/src/adapter/file_adapter.rs +++ b/src/adapter/file_adapter.rs @@ -18,10 +18,7 @@ use async_std::{ }; #[cfg(feature = "runtime-tokio")] -use std::{ - io::{Error as ioError, ErrorKind as ioErrorKind}, - path::Path as ioPath, -}; +use std::path::Path as ioPath; #[cfg(feature = "runtime-tokio")] use tokio::{ fs::File as file, @@ -137,8 +134,7 @@ where async fn save_policy(&mut self, m: &mut dyn Model) -> Result<()> { if self.file_path.as_ref().as_os_str().is_empty() { - return Err(ioError::new( - ioErrorKind::Other, + return Err(std::io::Error::other( "save policy failed, file path is empty", ) .into()); diff --git a/src/config.rs b/src/config.rs index 4f8f330e..99bf1910 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,22 +3,18 @@ use crate::Result; #[cfg(feature = "runtime-async-std")] use async_std::{ io::prelude::*, - io::{ - BufReader as ioBufReader, Cursor as ioCursor, Error as ioError, - ErrorKind as ioErrorKind, - }, + io::{BufReader as ioBufReader, Cursor as ioCursor}, }; #[cfg(all(feature = "runtime-async-std", not(target_arch = "wasm32")))] use async_std::{fs::File as file, path::Path as ioPath}; #[cfg(feature = "runtime-tokio")] -use std::{io::Cursor as ioCursor, path::Path as ioPath}; +use std::io::Cursor as ioCursor; #[cfg(feature = "runtime-tokio")] -use tokio::io::{ - AsyncBufReadExt, AsyncReadExt, BufReader as ioBufReader, Error as ioError, - ErrorKind as ioErrorKind, -}; +use std::path::Path as ioPath; +#[cfg(feature = "runtime-tokio")] +use tokio::io::{AsyncBufReadExt, AsyncReadExt, BufReader as ioBufReader}; #[cfg(all(feature = "runtime-tokio", not(target_arch = "wasm32")))] use tokio::fs::File as file; @@ -128,10 +124,10 @@ impl Config { .collect(); if option_val.len() != 2 { - return Err(ioError::new( - ioErrorKind::Other, - format!("parse content error, line={}", line), - ) + return Err(std::io::Error::other(format!( + "parse content error, line={}", + line + )) .into()); } diff --git a/src/util.rs b/src/util.rs index f18defef..19691613 100644 --- a/src/util.rs +++ b/src/util.rs @@ -32,7 +32,7 @@ pub fn remove_comment(s: &str) -> String { s.trim_end().to_owned() } -pub fn escape_eval(m: &str) -> Cow { +pub fn escape_eval(m: &str) -> Cow<'_, str> { ESC_E.replace_all(m, "eval(escape_assertion(${1}))") }