From b2511bdd3c54dedf805037cf3e11c9b6dd66a691 Mon Sep 17 00:00:00 2001 From: James Westby Date: Fri, 12 Jul 2024 20:19:11 +0100 Subject: [PATCH] Add github workflows --- .github/workflows/cacheclean.yml | 29 +++++++++++++++++++++++++++++ .github/workflows/cargo.yml | 30 ++++++++++++++++++++++++++++++ src/context.rs | 3 +-- tests/common.rs | 10 ++++++++-- 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/cacheclean.yml create mode 100644 .github/workflows/cargo.yml diff --git a/.github/workflows/cacheclean.yml b/.github/workflows/cacheclean.yml new file mode 100644 index 0000000..4c45f4a --- /dev/null +++ b/.github/workflows/cacheclean.yml @@ -0,0 +1,29 @@ +name: cleanup caches on a merged PR +on: + pull_request: + types: + - closed + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Cleanup + run: | + gh extension install actions/gh-actions-cache + + echo "Fetching list of cache key" + cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 ) + + ## Setting this to not fail the workflow while deleting cache keys. + set +e + echo "Deleting caches..." + for cacheKey in $cacheKeysForPR + do + gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm + done + echo "Done" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge diff --git a/.github/workflows/cargo.yml b/.github/workflows/cargo.yml new file mode 100644 index 0000000..06d2bc2 --- /dev/null +++ b/.github/workflows/cargo.yml @@ -0,0 +1,30 @@ +name: Cargo Tests +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] +jobs: + cargo: + timeout-minutes: 12 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + # Sync with dockerfiles/cargo-base/Dockerfile + toolchain: 1.75 + override: true + components: rustfmt, clippy + - name: Setup cargo cache + uses: Swatinem/rust-cache@v2 + continue-on-error: false + - name: Run cargo fmt + run: cargo fmt --check + - name: Run tests + run: cargo test + - name: Check lint + run: cargo clippy --all-targets --all-features -- -D warnings + - name: Run cargo check + run: cargo check diff --git a/src/context.rs b/src/context.rs index 808e9d4..7b3b24a 100644 --- a/src/context.rs +++ b/src/context.rs @@ -778,8 +778,7 @@ mod tests { #[test] fn uses_globals() { - let mut config = Config::default(); - config.globals = Some(HashMap::new()); + let mut config = Config { globals: Some(HashMap::new()), ..Default::default() }; config .globals .as_mut() diff --git a/tests/common.rs b/tests/common.rs index 6212f2a..7d7d7f7 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -7,12 +7,18 @@ pub struct TestContext { pub workdir: assert_fs::TempDir, } -impl TestContext { - pub fn new() -> Self { +impl Default for TestContext { + fn default() -> Self { Self { workdir: assert_fs::TempDir::new().unwrap(), } } +} + +impl TestContext { + pub fn new() -> Self { + Self::default() + } pub fn workdir(&self) -> &std::path::Path { self.workdir.path()