From daf3622df3d80fcda7b67ca8d42dd59bdc479994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Wed, 21 Jun 2023 11:35:32 +0200 Subject: [PATCH] ci: fix caching for golangci-lint --- .github/workflows/dev_builds.yml | 21 ++++++++++++++++++--- .github/workflows/pull_requests.yml | 23 +++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dev_builds.yml b/.github/workflows/dev_builds.yml index 1db18811b0..5eebf5a961 100644 --- a/.github/workflows/dev_builds.yml +++ b/.github/workflows/dev_builds.yml @@ -25,19 +25,34 @@ jobs: arch_os: [ 'linux_amd64' ] steps: - uses: actions/checkout@v3 + - name: Setup go uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} - cache-dependency-path: '**/go.sum' + cache: false + + - name: Get GOCACHE and GOMODCACHE + run: | + echo "GOMODCACHE=$(go env GOMODCACHE)" >> "$GITHUB_ENV" + echo "GOCACHE=$(go env GOCACHE)" >> "$GITHUB_ENV" + + - uses: actions/cache/restore@v3 + with: + path: | + ${{ env.GOMODCACHE }}/cache + ${{ env.GOCACHE }} + key: go-test-${{ env.GO_VERSION }}-${{matrix.arch_os}}-${{ hashFiles('pkg/**/go.sum', 'otelcolbuilder/.otelcol-builder.yaml') }} + restore-keys: | + go-test-${{ env.GO_VERSION }}-${{matrix.arch_os}}- - uses: actions/cache@v3 with: path: | /home/runner/.cache/golangci-lint - key: ${{matrix.arch_os}}-golangcilint-${{ hashFiles('**/go.sum') }} + key: golangci-lint-${{ env.GO_VERSION }}-${{matrix.arch_os}}-${{ hashFiles('pkg/**/go.sum', 'otelcolbuilder/.otelcol-builder.yaml') }} restore-keys: | - ${{matrix.arch_os}}-golangcilint- + golangci-lint-${{ env.GO_VERSION }}-${{matrix.arch_os}}- - name: Install golangci-lint run: make install-golangci-lint diff --git a/.github/workflows/pull_requests.yml b/.github/workflows/pull_requests.yml index 9f1ee63151..e8f919f015 100644 --- a/.github/workflows/pull_requests.yml +++ b/.github/workflows/pull_requests.yml @@ -260,16 +260,31 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} - cache-dependency-path: '**/go.sum' + cache: false + + - name: Get GOCACHE and GOMODCACHE + if: steps.changed-files.outputs.any_changed == 'true' + run: | + echo "GOMODCACHE=$(go env GOMODCACHE)" >> "$GITHUB_ENV" + echo "GOCACHE=$(go env GOCACHE)" >> "$GITHUB_ENV" - - uses: actions/cache@v3 + - uses: actions/cache/restore@v3 if: steps.changed-files.outputs.any_changed == 'true' + with: + path: | + ${{ env.GOMODCACHE }}/cache + ${{ env.GOCACHE }} + key: go-test-${{ env.GO_VERSION }}-${{matrix.arch_os}}-${{ hashFiles('pkg/**/go.sum', 'otelcolbuilder/.otelcol-builder.yaml') }} + restore-keys: | + go-test-${{ env.GO_VERSION }}-${{matrix.arch_os}}- + + - uses: actions/cache/restore@v3 with: path: | /home/runner/.cache/golangci-lint - key: ${{matrix.arch_os}}-golangcilint-${{ hashFiles('**/go.sum') }} + key: golangci-lint-${{ env.GO_VERSION }}-${{matrix.arch_os}}-${{ hashFiles('pkg/**/go.sum', 'otelcolbuilder/.otelcol-builder.yaml') }} restore-keys: | - ${{matrix.arch_os}}-golangcilint- + golangci-lint-${{ env.GO_VERSION }}-${{matrix.arch_os}}- - name: Install golangci-lint if: steps.changed-files.outputs.any_changed == 'true'