Skip to content

Commit

Permalink
make our rust/pip cache a composite action (#8287)
Browse files Browse the repository at this point in the history
* make our rust/pip cache a composite action

* fixes
  • Loading branch information
reaperhulk committed Feb 14, 2023
1 parent 030381a commit 2bf2f2c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 69 deletions.
43 changes: 43 additions & 0 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Cache rust and pip
description: Caches rust and pip data to speed builds
inputs:
additional-paths:
description: 'Additional paths to add to the cache'
required: false
default: ''
key:
description: 'cache key'
required: true
outputs:
cache-hit:
description: 'Was the cache hit?'
value: ${{ steps.cache.outputs.cache-hit }}


runs:
using: "composite"

steps:
- name: Get pip cache dir
id: pip-cache
run: |
# Determine the path to our Python. It's in venv for our containers
# but just standard $PATH for setup-python pythons.
if [[ -f "/venv/bin/python" ]]; then
echo "dir=$(/venv/bin/python -m pip cache dir)" >> $GITHUB_OUTPUT
elif which python >/dev/null; then
echo "dir=$(python -m pip cache dir)" >> $GITHUB_OUTPUT
fi
shell: bash
- uses: actions/cache@v3.2.5
id: cache
with:
path: |
${{ steps.pip-cache.outputs.dir }}
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/registry/src/
~/.cargo/git/db/
src/rust/target/
${{ inputs.additional-paths }}
key: ${{ inputs.key }}
92 changes: 23 additions & 69 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,11 @@ jobs:
uses: actions/setup-python@v4.5.0
with:
python-version: ${{ matrix.PYTHON.VERSION }}
- uses: actions/cache@v3.2.5
timeout-minutes: 5
- name: Cache rust and pip
uses: ./.github/actions/cache
timeout-minutes: 2
with:
path: |
~/.cache/pip/wheels
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/registry/src/
~/.cargo/git/db/
src/rust/target/
key: ${{ runner.os }}-${{ matrix.PYTHON.VERSION }}-${{ steps.setup-python.outputs.python-version }}-cargo-3-${{ hashFiles('**/Cargo.lock') }}

- name: Clone wycheproof
timeout-minutes: 2
uses: ./.github/actions/wycheproof
Expand Down Expand Up @@ -171,18 +164,11 @@ jobs:
git config --global --add safe.directory $(pwd) # needed for the mtime fix since git doesn't think it owns the files due to being in containers
- name: set mtimes for rust dirs
uses: ./.github/actions/mtime-fix
- uses: actions/cache@v3.2.5
timeout-minutes: 5
- name: Cache rust and pip
uses: ./.github/actions/cache
timeout-minutes: 2
with:
path: |
~/.cache/pip/wheels
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/registry/src/
~/.cargo/git/db/
src/rust/target/
key: ${{ runner.os }}-${{ matrix.IMAGE.IMAGE }}-${{ runner.arch }}-cargo-3-${{ hashFiles('**/Cargo.lock') }}

- name: Clone wycheproof
timeout-minutes: 2
uses: ./.github/actions/wycheproof
Expand Down Expand Up @@ -237,18 +223,11 @@ jobs:
fetch-depth: 0
- name: set mtimes for rust dirs
uses: ./.github/actions/mtime-fix
- uses: actions/cache@v3.2.5
timeout-minutes: 5
- name: Cache rust and pip
uses: ./.github/actions/cache
timeout-minutes: 2
with:
path: |
~/.cache/pip/wheels
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/registry/src/
~/.cargo/git/db/
src/rust/target/
key: ${{ runner.os }}-cargo-3-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.RUST }}

- name: Setup python
uses: actions/setup-python@v4.5.0
with:
Expand Down Expand Up @@ -297,19 +276,14 @@ jobs:
with:
toolchain: ${{ matrix.RUST }}
components: llvm-tools-preview
- uses: actions/cache@v3.2.5
- name: Cache rust and pip
id: cargo-cache
timeout-minutes: 5
uses: ./.github/actions/cache
timeout-minutes: 2
with:
path: |
~/.cache/pip/wheels
~/.cargo/bin/
~/.cargo/registry/cache/
~/.cargo/registry/src/
~/.cargo/git/db/
src/rust/target/
key: ${{ runner.os }}-cargo-3-${{ hashFiles('**/Cargo.lock') }}-rust-${{ steps.rust-toolchain.outputs.cachekey }}-coverage

additional-paths: |
~/.cargo/bin/
- name: Setup python
uses: actions/setup-python@v4.5.0
with:
Expand Down Expand Up @@ -391,16 +365,10 @@ jobs:
fetch-depth: 0
- name: set mtimes for rust dirs
uses: ./.github/actions/mtime-fix
- uses: actions/cache@v3.2.5
timeout-minutes: 5
- name: Cache rust and pip
uses: ./.github/actions/cache
timeout-minutes: 2
with:
path: |
~/Library/Caches/pip/wheels
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/registry/src/
~/.cargo/git/db/
src/rust/target/
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.PYTHON.VERSION }}-cargo-3-${{ hashFiles('**/Cargo.lock') }}

- name: Setup python
Expand Down Expand Up @@ -465,18 +433,11 @@ jobs:
with:
python-version: ${{ matrix.PYTHON.VERSION }}
architecture: ${{ matrix.WINDOWS.ARCH }}
- uses: actions/cache@v3.2.5
timeout-minutes: 5
- name: Cache rust and pip
uses: ./.github/actions/cache
timeout-minutes: 2
with:
path: |
~/AppData/Local/pip/Cache/wheels
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/registry/src/
~/.cargo/git/db/
src/rust/target/
key: ${{ runner.os }}-${{ matrix.WINDOWS.ARCH }}-${{ steps.setup-python.outputs.python-version }}-cargo-3-${{ hashFiles('**/Cargo.lock') }}

- run: python -m pip install -c ci-constraints-requirements.txt "tox>3" requests coverage[toml]
- name: Download OpenSSL
run: |
Expand Down Expand Up @@ -532,18 +493,11 @@ jobs:
fetch-depth: 0
- name: set mtimes for rust dirs
uses: ./.github/actions/mtime-fix
- uses: actions/cache@v3.2.5
timeout-minutes: 5
- name: Cache rust and pip
uses: ./.github/actions/cache
timeout-minutes: 2
with:
path: |
~/.cache/pip/wheels
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/registry/src/
~/.cargo/git/db/
src/rust/target/
key: ${{ runner.os }}-cargo-3-${{ hashFiles('**/Cargo.lock') }}

- name: Setup python
uses: actions/setup-python@v4.5.0
with:
Expand Down

0 comments on commit 2bf2f2c

Please sign in to comment.