diff --git a/.github/workflows/cache_cleanup.yml b/.github/workflows/cache_cleanup.yml new file mode 100644 index 00000000..103e6546 --- /dev/null +++ b/.github/workflows/cache_cleanup.yml @@ -0,0 +1,33 @@ +# Delete the GitHub Actions caches of a pull request once it is closed. +# +# A repository can only hold 10 GB of caches, and the oldest ones are evicted when it is full. +# Without this the caches of merged pull requests would push out the `main` cache +# that every new pull request starts from. + +name: Cache Cleanup + +on: + pull_request: + types: [closed] + +permissions: + actions: write + +jobs: + cleanup: + name: Delete the caches of the closed PR + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Delete caches + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + PR_REF: refs/pull/${{ github.event.pull_request.number }}/merge + BRANCH_REF: refs/heads/${{ github.event.pull_request.head.ref }} + run: | + for ref in "$PR_REF" "$BRANCH_REF"; do + echo "Deleting the caches of $ref" + gh cache list --ref "$ref" --limit 100 --json id --jq '.[].id' \ + | xargs -r -I {} gh cache delete {} + done diff --git a/.github/workflows/png_only_on_lfs.yml b/.github/workflows/png_only_on_lfs.yml index 0b7c122f..a80ae4f0 100644 --- a/.github/workflows/png_only_on_lfs.yml +++ b/.github/workflows/png_only_on_lfs.yml @@ -1,6 +1,11 @@ name: All; .png on git LFS -on: [push, pull_request] +on: + # Only on `main`, so that a PR from a branch in this repo + # doesn't run the whole workflow twice (once for the push, once for the PR): + push: + branches: ["main"] + pull_request: jobs: check-binary-files: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 29dff6b7..46476133 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,4 +1,9 @@ -on: [push, pull_request] +on: + # Only on `main`, so that a PR from a branch in this repo + # doesn't run the whole workflow twice (once for the push, once for the PR): + push: + branches: ["main"] + pull_request: name: Rust @@ -31,6 +36,9 @@ jobs: - name: Set up cargo cache uses: Swatinem/rust-cache@v2 + with: + # Only `main` writes to the cache, so PR caches can't evict it (10 GB repository limit). + save-if: ${{ github.ref == 'refs/heads/main' }} - name: Rustfmt run: cargo fmt --all -- --check @@ -81,6 +89,9 @@ jobs: - name: Set up cargo cache uses: Swatinem/rust-cache@v2 + with: + # Only `main` writes to the cache, so PR caches can't evict it (10 GB repository limit). + save-if: ${{ github.ref == 'refs/heads/main' }} - name: clippy wasm32 egui_demo_app run: cargo clippy -p egui_demo_app --lib --target wasm32-unknown-unknown @@ -112,6 +123,9 @@ jobs: - name: Set up cargo cache uses: Swatinem/rust-cache@v2 + with: + # Only `main` writes to the cache, so PR caches can't evict it (10 GB repository limit). + save-if: ${{ github.ref == 'refs/heads/main' }} - uses: dtolnay/rust-toolchain@stable with: toolchain: ${{env.NIGHTLY_VERSION}} @@ -169,6 +183,9 @@ jobs: - name: Set up cargo cache uses: Swatinem/rust-cache@v2 + with: + # Only `main` writes to the cache, so PR caches can't evict it (10 GB repository limit). + save-if: ${{ github.ref == 'refs/heads/main' }} # Default features disabled to turn off accesskit, which does not work # with NativeActivity. @@ -191,6 +208,9 @@ jobs: - name: Set up cargo cache uses: Swatinem/rust-cache@v2 + with: + # Only `main` writes to the cache, so PR caches can't evict it (10 GB repository limit). + save-if: ${{ github.ref == 'refs/heads/main' }} # Default features are disabled because glutin doesn't compile for ios. - run: cargo check --features wgpu --target aarch64-apple-ios --no-default-features @@ -210,6 +230,9 @@ jobs: - name: Set up cargo cache uses: Swatinem/rust-cache@v2 + with: + # Only `main` writes to the cache, so PR caches can't evict it (10 GB repository limit). + save-if: ${{ github.ref == 'refs/heads/main' }} - run: cargo clippy --all-targets --all-features @@ -232,6 +255,9 @@ jobs: - name: Set up cargo cache uses: Swatinem/rust-cache@v2 + with: + # Only `main` writes to the cache, so PR caches can't evict it (10 GB repository limit). + save-if: ${{ github.ref == 'refs/heads/main' }} # `--no-fail-fast` so that a failing snapshot test in one crate doesn't # stop the tests of the other crates from running.