Skip to content

Commit

Permalink
ci: add path to go.sum to actions/setup-go
Browse files Browse the repository at this point in the history
I just noticed that actions/setup-go complains about the missing
go.sum file:

>  Restore cache failed: Dependencies file is not found in /home/runner/work/sys/sys. Supported file pattern: go.sum

Apparently this happens because of two reasons:

 1. actions/checkout should be run _before actions/setup-go.

 2. There's no top-level go.sum file.

The first problem is easy to fix.

As for the second one, documentation[1] suggests using a wild card in
such cases, but using neither "*/go.sum" nor "**/go.sum" works, as not
all modules have go.sum, and so it fails with the following error:

> Restore cache failed: Some specified paths were not resolved, unable to cache dependencies.

Alas, we have to add an extra step to list the available go.sum files.
The alternative would be listing them all, which is maintainers' nightmare.

(The contents of these files are used as an input when calculating the
cache checksum, essentially meaning if any of these files are changed,
the cache will be invalidated.)

[1]: https://github.com/actions/setup-go/blob/main/README.md#caching-dependency-files-and-build-outputs

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Sep 21, 2024
1 parent 4a1fbfe commit 649e3be
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ jobs:
platform: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, windows-latest, macos-12, macos-14]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Find go.sum files
id: gosum
shell: bash
run: |
echo 'files<<EOF' >> "$GITHUB_OUTPUT"
git ls-files '*/go.sum' >> "$GITHUB_OUTPUT"
echo 'EOF' >> "$GITHUB_OUTPUT"
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
cache-dependency-path: ${{ steps.gosum.outputs.files }}
- if: ${{ matrix.go-version == '1.18.x' }}
run: |
# This corresponds with the list in Makefile:1, but omits the "userns"
Expand Down

0 comments on commit 649e3be

Please sign in to comment.