Skip to content

Commit

Permalink
Finer grain cache.
Browse files Browse the repository at this point in the history
- only consider the current workflow file (and not all of them) to
rebuild a cache.
- fix action files that were not taken into account for the key
- allow for workflows to specialize the cache (useful in case of
matrix)
  • Loading branch information
vrabaud committed May 27, 2024
1 parent 25cedb2 commit d743f23
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
21 changes: 18 additions & 3 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,42 @@ inputs:
use-rust:
description: 'Whether rust is used'
default: false
extra-key:
description: 'Extra cache key to use in the cache name. Useful when several caches are used in one workflow.'
default: ''
outputs:
ext-cache-hit:
value: ${{ steps.cache-ext.outputs.cache-hit }}
runs:
using: "composite"
steps:
- name: Find workflow path
env:
WORKFLOW_REF: ${{ github.workflow_ref }}
id: workflow-info
run: |
# Remove repository path.
END=(${WORKFLOW_REF/*.github/.github})
# Remove branch reference starting with @.
MIDDLE=(${END/%@*/})
echo "Current workflow path is: ${MIDDLE}"
echo "path=${MIDDLE}" >> "$GITHUB_OUTPUT"
shell: bash
- name: Cache all of cargo
if: ${{ inputs.use-rust }}
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
continue-on-error: true
with:
path: ~/.cargo
key: cargo-registry-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('CMakeLists.txt', 'cmake/Modules/Findrav1e.cmake', 'cmake/Modules/LocalRav1e.cmake', 'ext/rav1e.cmd') }}-${{ github.job }}
key: cargo-registry-${{ runner.os }}-${{ runner.arch }}-${{ github.job }}-${{ inputs.extra-key }}-${{ hashFiles('.github/action/**', steps.workflow-info.outputs.path, 'CMakeLists.txt', 'cmake/Modules/Findrav1e.cmake', 'cmake/Modules/LocalRav1e.cmake', 'ext/rav1e.cmd') }}
- name: Cache external dependencies in ext
id: cache-ext
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ext
key: ext-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/workflows/*', 'ext/*.cmd', 'ext/*.sh') }}-${{ github.job }}
key: ext-${{ runner.os }}-${{ runner.arch }}-${{ github.job }}-${{ inputs.extra-key }}-${{ hashFiles('.github/action/**', steps.workflow-info.outputs.path, 'ext/*.cmd', 'ext/*.sh') }}
- name: Cache external dependencies in build/_deps
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: build/_deps
key: deps-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/workflows/*', 'CMakeLists.txt', 'cmake/Modules/*') }}-${{ github.job }}
key: deps-${{ runner.os }}-${{ runner.arch }}-${{ github.job }}-${{ inputs.extra-key }}-${{ hashFiles('.github/action/**', steps.workflow-info.outputs.path, 'CMakeLists.txt', 'cmake/Modules/*') }}
2 changes: 2 additions & 0 deletions .github/workflows/ci-mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
ninja:p
zlib:p
- uses: ./.github/actions/cache
with:
extra-key: ${{ matrix.sys }}
- name: Print cmake version
run: cmake --version

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-unix-static-av2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
- uses: ./.github/actions/cache
with:
use-rust: true
extra-key: ${{ matrix.also-enable-av1-codecs }}
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@802fa1a2c4e212495c05bf94dba2704a92a472be # v2.0.2
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci-unix-static-sanitized.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
run: brew install aom dav1d imagemagick libpng
- uses: ./.github/actions/cache
id: cache
with:
extra-key: ${{ matrix.sanitizer }}
- name: Build aom
if: steps.cache.outputs.ext-cache-hit != 'true'
working-directory: ./ext
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-unix-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
- uses: ./.github/actions/cache
with:
use-rust: true
extra-key: ${{ matrix.build-type }}
- name: Setup cmake
if: runner.os == 'Linux'
uses: jwlawson/actions-setup-cmake@802fa1a2c4e212495c05bf94dba2704a92a472be # v2.0.2
Expand Down

0 comments on commit d743f23

Please sign in to comment.