Skip to content

Commit

Permalink
ci: rework GitHub caching strategy (#3886)
Browse files Browse the repository at this point in the history
* ci: rework GitHub caching strategy

* clean up some more redundant imports flagged by nightly
  • Loading branch information
davidhewitt authored Feb 23, 2024
1 parent 22a23ff commit 5ca8102
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 44 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/benches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ jobs:
with:
components: rust-src

- uses: actions/cache@v4
- uses: Swatinem/rust-cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
pyo3-benches/target
target
key: cargo-${{ runner.os }}-bench-${{ hashFiles('**/Cargo.toml') }}
workspaces: |
.
pyo3-benches
continue-on-error: true

- name: Install cargo-codspeed
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ jobs:

- uses: Swatinem/rust-cache@v2
with:
key: cargo-${{ inputs.python-architecture }}
continue-on-error: true
save-if: ${{ github.event_name != 'merge_group' }}

- if: inputs.os == 'ubuntu-latest'
name: Prepare LD_LIBRARY_PATH (Ubuntu only)
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/cache-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI Cache Cleanup
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
46 changes: 19 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
check-msrv:
needs: [fmt]
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
Expand All @@ -57,8 +56,7 @@ jobs:
architecture: "x64"
- uses: Swatinem/rust-cache@v2
with:
key: check-msrv-1.56.0
continue-on-error: true
save-if: ${{ github.event_name != 'merge_group' }}
- run: python -m pip install --upgrade pip && pip install nox
- name: Prepare minimal package versions
run: nox -s set-minimal-package-versions
Expand All @@ -70,7 +68,6 @@ jobs:
clippy:
needs: [fmt]
runs-on: ${{ matrix.platform.os }}
if: github.ref != 'refs/heads/main'
strategy:
# If one platform fails, allow the rest to keep testing if `CI-no-fail-fast` label is present
fail-fast: ${{ !contains(github.event.pull_request.labels.*.name, 'CI-no-fail-fast') }}
Expand Down Expand Up @@ -136,8 +133,7 @@ jobs:
architecture: ${{ matrix.platform.python-architecture }}
- uses: Swatinem/rust-cache@v2
with:
key: clippy-${{ matrix.platform.rust-target }}-${{ matrix.platform.os }}-${{ matrix.rust }}
continue-on-error: true
save-if: ${{ github.event_name != 'merge_group' }}
- run: python -m pip install --upgrade pip && pip install nox
- run: nox -s clippy-all
env:
Expand Down Expand Up @@ -199,7 +195,7 @@ jobs:
}
extra-features: "nightly multiple-pymethods"
build-full:
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || (github.event_name != 'pull_request' && github.ref != 'refs/heads/main') }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
name: python${{ matrix.python-version }}-${{ matrix.platform.python-architecture }} ${{ matrix.platform.os }} rust-${{ matrix.rust }}
needs: [fmt]
uses: ./.github/workflows/build.yml
Expand Down Expand Up @@ -293,16 +289,15 @@ jobs:
extra-features: "multiple-pymethods"

valgrind:
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || (github.event_name != 'pull_request' && github.ref != 'refs/heads/main') }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
needs: [fmt]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: Swatinem/rust-cache@v2
with:
key: cargo-valgrind
continue-on-error: true
save-if: ${{ github.event_name != 'merge_group' }}
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@valgrind
- run: python -m pip install --upgrade pip && pip install nox
Expand All @@ -313,16 +308,15 @@ jobs:
TRYBUILD: overwrite

careful:
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || (github.event_name != 'pull_request' && github.ref != 'refs/heads/main') }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
needs: [fmt]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: Swatinem/rust-cache@v2
with:
key: cargo-careful
continue-on-error: true
save-if: ${{ github.event_name != 'merge_group' }}
- uses: dtolnay/rust-toolchain@nightly
with:
components: rust-src
Expand All @@ -334,16 +328,15 @@ jobs:
TRYBUILD: overwrite

docsrs:
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || (github.event_name != 'pull_request' && github.ref != 'refs/heads/main') }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
needs: [fmt]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: Swatinem/rust-cache@v2
with:
key: cargo-careful
continue-on-error: true
save-if: ${{ github.event_name != 'merge_group' }}
- uses: dtolnay/rust-toolchain@nightly
with:
components: rust-src
Expand All @@ -368,8 +361,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
if: steps.should-skip.outputs.skip != 'true'
with:
key: coverage-cargo-${{ matrix.os }}
continue-on-error: true
save-if: ${{ github.event_name != 'merge_group' }}
- uses: dtolnay/rust-toolchain@stable
if: steps.should-skip.outputs.skip != 'true'
with:
Expand All @@ -390,7 +382,7 @@ jobs:

emscripten:
name: emscripten
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || (github.event_name != 'pull_request' && github.ref != 'refs/heads/main') }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -416,7 +408,7 @@ jobs:
key: ${{ hashFiles('emscripten/*') }} - ${{ hashFiles('noxfile.py') }} - ${{ steps.setup-python.outputs.python-path }}
- uses: Swatinem/rust-cache@v2
with:
key: cargo-emscripten-wasm32
save-if: ${{ github.event_name != 'merge_group' }}
- name: Build
if: steps.cache.outputs.cache-hit != 'true'
run: nox -s build-emscripten
Expand All @@ -425,14 +417,12 @@ jobs:

test-debug:
needs: [fmt]
if: github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
key: cargo-test-debug
continue-on-error: true
save-if: ${{ github.event_name != 'merge_group' }}
- uses: dtolnay/rust-toolchain@stable
with:
components: rust-src
Expand Down Expand Up @@ -470,25 +460,27 @@ jobs:

test-version-limits:
needs: [fmt]
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || (github.event_name != 'pull_request' && github.ref != 'refs/heads/main') }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
continue-on-error: true
with:
save-if: ${{ github.event_name != 'merge_group' }}
- uses: dtolnay/rust-toolchain@stable
- run: python3 -m pip install --upgrade pip && pip install nox
- run: python3 -m nox -s test-version-limits

check-feature-powerset:
needs: [fmt]
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || (github.event_name != 'pull_request' && github.ref != 'refs/heads/main') }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: Swatinem/rust-cache@v2
continue-on-error: true
with:
save-if: ${{ github.event_name != 'merge_group' }}
- uses: dtolnay/rust-toolchain@stable
with:
components: rust-src
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ fn timezone_utc_bound(py: Python<'_>) -> Bound<'_, PyAny> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{types::PyTuple, Bound, Py};
use crate::{types::PyTuple, Py};
use std::{cmp::Ordering, panic};

#[test]
Expand Down
2 changes: 0 additions & 2 deletions src/conversions/chrono_tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ impl FromPyObject<'_> for Tz {

#[cfg(all(test, not(windows)))] // Troubles loading timezones on Windows
mod tests {
use crate::{types::any::PyAnyMethods, Bound};

use super::*;

#[test]
Expand Down
5 changes: 1 addition & 4 deletions src/conversions/num_bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,7 @@ fn int_n_bits(long: &Bound<'_, PyLong>) -> PyResult<usize> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
types::{PyDict, PyModule},
Bound,
};
use crate::types::{PyDict, PyModule};
use indoc::indoc;

fn rust_fib<T>() -> impl Iterator<Item = T>
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/num_complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ complex_conversion!(f64);
#[cfg(test)]
mod tests {
use super::*;
use crate::types::{any::PyAnyMethods, complex::PyComplexMethods, PyModule};
use crate::types::{complex::PyComplexMethods, PyModule};

#[test]
fn from_complex() {
Expand Down

0 comments on commit 5ca8102

Please sign in to comment.