From 1a6c912b710779558d543f021f1ccafc30c4113d Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 20 Sep 2024 17:46:46 -0700 Subject: [PATCH] ci: add path to go.sum to actions/setup-go 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 --- .github/workflows/test.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a204003..3e3a0969 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,12 +11,20 @@ jobs: run: shell: bash steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Find go.sum files + id: gosum + shell: bash + run: | + echo 'files<> "$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 }} - name: Set PACKAGES env if: ${{ matrix.go-version == '1.18.x' }} run: |