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 018d80a commit b7ca41e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
43 changes: 29 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
pull_request_target:

permissions:
actions: write
contents: read
packages: write

Expand Down Expand Up @@ -86,24 +87,36 @@ jobs:
restore-keys: |
depends-sources-
- name: Cache dependencies
uses: actions/cache@v4
- name: Restore depends cache
id: cache-restore-deps
uses: actions/cache/restore@v4
with:
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ runner.os }}-depends-${{ matrix.build_target }}-${{ hashFiles('depends/packages/*') }}
restore-keys: |
${{ runner.os }}-depends-${{ matrix.build_target }}-${{ hashFiles('depends/packages/*') }}
${{ runner.os }}-depends-${{ matrix.build_target }}

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

- name: Upload built depends
uses: actions/upload-artifact@v4
- name: Delete depends 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 }}"
env:
GH_TOKEN: ${{ github.token }}

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

build:
name: Build
Expand Down Expand Up @@ -146,11 +159,13 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Download built depends
uses: actions/download-artifact@v4
- name: Restore depends cache
uses: actions/cache/restore@v4
with:
name: depends-${{ matrix.depends_on }}
path: depends/${{ matrix.host }}
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ runner.os }}-depends-${{ matrix.build_target }}-${{ 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 @@ -150,6 +150,15 @@ RUN cd /tmp && \
/tmp/llvm.sh ${LLVM_VERSION} && \
rm -rf /tmp/llvm.sh

# 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 b7ca41e

Please sign in to comment.