Skip to content

Commit

Permalink
ci: use actions/cache for restore/save cache, gh for deleting cache
Browse files Browse the repository at this point in the history
`actions/cache` does not allow for updating the cache, so we need to
delete the old cache and save a new one in order to keep reusing the
key.
  • Loading branch information
kwvg committed Nov 19, 2024
1 parent 2cf863b commit ea8b0ff
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
40 changes: 27 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,36 @@ jobs:
restore-keys: |
depends-sources-
- name: Cache dependencies
uses: actions/cache@v4
- name: Restore dependencies cache
id: cache-restore-deps
uses: actions/cache/restore@v4
with:
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ runner.os }}-depends-${{ matrix.depends_name }}-${{ hashFiles('depends/packages/*') }}
restore-keys: |
${{ runner.os }}-depends-${{ matrix.depends_name }}-${{ hashFiles('depends/packages/*') }}
${{ runner.os }}-depends-${{ matrix.depends_name }}

- name: Build dependencies
run: env HOST=${{ matrix.host }} ${{ matrix.dep_opts }} make -j$(nproc) -C depends

- name: Upload built depends
uses: actions/upload-artifact@v4
- name: Delete dependencies cache
id: cache-delete-deps
if: ${{ steps.cache-restore-deps.outputs.cache-hit }}
continue-on-error: true
run: |
git config --global --add safe.directory "$(pwd)"
gh cache delete "${{ steps.cache-restore-deps.outputs.cache-primary-key }}" --confirm
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Save dependencies cache
id: cache-save-deps
uses: actions/cache/save@v4
with:
name: depends-${{ matrix.depends_name }}
path: depends/${{ matrix.host }}
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ steps.cache-restore-deps.outputs.cache-primary-key }}

build:
name: ${{ matrix.build_target }}
Expand Down Expand Up @@ -157,11 +169,13 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Download built depends
uses: actions/download-artifact@v4
- name: Restore dependencies cache
uses: actions/cache/restore@v4
with:
name: depends-${{ matrix.depends_name }}
path: depends/${{ matrix.host }}
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ runner.os }}-depends-${{ matrix.depends_name }}-${{ hashFiles('depends/packages/*') }}

- name: Determine PR Base SHA
id: vars
Expand Down
9 changes: 9 additions & 0 deletions contrib/containers/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ RUN \
update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix; \
exit 0

# Install GitHub CLI for GitHub Actions usage
RUN \
mkdir -p -m 755 /etc/apt/keyrings \
&& wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg > /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" > /etc/apt/sources.list.d/github-cli.list; \
apt-get update && apt-get install $APT_ARGS gh \
&& rm -rf /var/lib/apt/lists/*;

RUN \
mkdir -p /src/dash && \
mkdir -p /cache/ccache && \
Expand Down

0 comments on commit ea8b0ff

Please sign in to comment.