Skip to content

feat: add cache prefix #358

Open
Open
@ernado

Description

Description:
Add cache key prefix, like that:

- name: Install Go
  uses: actions/setup-go@v4
  with:
    go-version: '1.20'
    cache: true
    cache-prefix: 'test-${{ matrix.arch }}-${{ matrix.flags }}-'

Justification:
Cache from multiple workflows can be mixed.
For example, there can be a workflow that only downloads dependencies.
This will produce cache without .cache/go-build, which will be used by
another workflows, effectively disabling build cache.

This was the cause in #357

Are you willing to submit a PR?

I don't know typescript well, but I'm learning.

Workaround

Use actions/cache@v3 manually, something like that:

name: manual

on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      cache_name: manual

    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-go@v4
        with:
          go-version: "1.20.x"
          cache: false

      - name: Get Go environment
        run: |
          echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV
          echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV

      - name: Set up cache
        uses: actions/cache@v3
        with:
          path: |
            ${{ env.cache }}
            ${{ env.modcache }}
          key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
          restore-keys: |
            ${{ env.cache_name }}-${{ runner.os }}-go-

      - run: go env GOCACHE
      - run: go build -v

Cons
Cache configuration options can possibly lead to feature bloat, so feel free to decline this feature proposal.

Metadata

Assignees

Labels

feature requestNew feature or request to improve the current logic

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions