Skip to content

Use a single shared cache for all CI workflows #1506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 98 additions & 11 deletions .github/actions/setup-go/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ inputs:
go-version:
description: Go version range to set up.
default: '>=1.24.0'
cache-name:
description: Name of scoped cache for this set up.
default: 'cache'
create:
description: Create the cache
default: 'false'
lint-cache:
description: Restore the golangci-lint cache
default: 'false'

runs:
using: composite

steps:
- name: Install Go
id: install-go
Expand All @@ -19,18 +23,101 @@ runs:
go-version: ${{ inputs.go-version }}
cache: false

# There is more code downloaded and built than is covered by '**/go.sum',
# so give each job its own cache to try and not end up sharing the wrong
# cache between jobs, and hash the Herebyfile and golancgi-lint version.
# Avoid hardcoding the cache keys more than once.
- name: Get cache info
shell: bash
id: cache-info
env:
MODULES_KEY: go-modules-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml', '**/.dprint.jsonc') }}
LINT_KEY: golangci-lint-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml', '**/.dprint.jsonc') }}
BUILD_KEY: go-build-cache-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}
run: |
echo "modules-key=$MODULES_KEY" >> $GITHUB_OUTPUT
echo "lint-key=$LINT_KEY" >> $GITHUB_OUTPUT
echo "build-key=$BUILD_KEY" >> $GITHUB_OUTPUT
echo "GOLANGCI_LINT_CACHE=$RUNNER_TEMP/golangci-lint-cache" >> $GITHUB_ENV

- if: ${{ inputs.create != 'true' }}
name: Restore Go modules
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
key: unused-key-${{ github.run_id }}
restore-keys: ${{ steps.cache-info.outputs.modules-key }}-
path: |
~/go/pkg/mod

- if: ${{ inputs.create != 'true' }}
name: Restore Go build cache
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
key: unused-key-${{ github.run_id }}
restore-keys: ${{ steps.cache-info.outputs.build-key }}-
path: |
~/.cache/go-build
~/Library/Caches/go-build
~/AppData/Local/go-build

- if: ${{ inputs.create != 'true' && inputs.lint-cache == 'true' }}
name: Restore golangci-lint cache
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
key: unused-key-${{ github.run_id }}
restore-keys: ${{ steps.cache-info.outputs.lint-key }}-
path: ${{ env.GOLANGCI_LINT_CACHE }}

- name: Set mtimes
shell: bash
run: |
find . -type f ! -path ./.git/\*\* | go run github.com/slsyy/mtimehash/cmd/[email protected] || true
find . -type d ! -path ./.git/\*\* -exec touch -d '1970-01-01T00:00:01Z' {} + || true

# All steps below are only run if the cache is being created.

- if: ${{ inputs.create == 'true' }}
shell: bash
run: npm ci

- if: ${{ inputs.create == 'true' }}
shell: bash
run: npx hereby build

- if: ${{ inputs.create == 'true' }}
shell: bash
run: npx hereby test

- if: ${{ inputs.create == 'true' }}
shell: bash
run: npx hereby lint

- if: ${{ inputs.create == 'true' }}
shell: bash
run: npx hereby lint --noembed

- name: Go cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
- if: ${{ inputs.create == 'true' }}
shell: bash
run: npx dprint check

- if: ${{ inputs.create == 'true' }}
name: Save Go modules
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
key: ts-setup-go-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml') }}-${{ github.workflow }}-${{ inputs.cache-name }}
restore-keys: |
ts-setup-go-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml') }}-${{ github.workflow }}-
key: ${{ steps.cache-info.outputs.modules-key }}
path: |
~/go/pkg/mod

- if: ${{ inputs.create == 'true' }}
name: Save Go build cache
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
key: ${{ steps.cache-info.outputs.build-key }}-${{ github.run_id }}
path: |
~/.cache/go-build
~/Library/Caches/go-build
~/AppData/Local/go-build

- if: ${{ inputs.create == 'true' }}
name: Save golangci-lint cache
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
key: ${{ steps.cache-info.outputs.lint-key }}-${{ github.run_id }}
path: ${{ env.GOLANGCI_LINT_CACHE }}
18 changes: 1 addition & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
- uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
- uses: ./.github/actions/setup-go
with:
cache-name: build

# Avoid duplicate PR annotations.
- name: Disable PR annotations
Expand Down Expand Up @@ -112,8 +110,6 @@ jobs:
node-version: 'lts/*'
- uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
- uses: ./.github/actions/setup-go
with:
cache-name: test

# Avoid duplicate PR annotations.
- if: ${{ ! matrix.config.main }}
Expand Down Expand Up @@ -200,7 +196,7 @@ jobs:
- uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
- uses: ./.github/actions/setup-go
with:
cache-name: lint${{ (matrix.config.noembed && '-noembed') || ''}}
lint-cache: 'true'

# Avoid duplicate PR annotations.
- if: ${{ ! matrix.config.main }}
Expand All @@ -222,8 +218,6 @@ jobs:
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
- uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
- uses: ./.github/actions/setup-go
with:
cache-name: format

- run: npm ci

Expand All @@ -240,8 +234,6 @@ jobs:
node-version: '>=22.16.0'
- uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
- uses: ./.github/actions/setup-go
with:
cache-name: generate

- run: npm ci

Expand All @@ -261,8 +253,6 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: ./.github/actions/setup-go
with:
cache-name: tidy

- run: go mod tidy -diff
- run: go -C ./_tools mod tidy -diff
Expand All @@ -276,8 +266,6 @@ jobs:
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
- uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
- uses: ./.github/actions/setup-go
with:
cache-name: smoke

# Avoid duplicate PR annotations.
- name: Disable PR annotations
Expand All @@ -302,8 +290,6 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: ./.github/actions/setup-go
with:
cache-name: misc

- run: go -C ./_tools run ./cmd/checkmodpaths $PWD

Expand All @@ -316,8 +302,6 @@ jobs:
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
- uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
- uses: ./.github/actions/setup-go
with:
cache-name: baselines

- run: npm ci

Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ jobs:
with:
# Updated to 1.25.0-rc.1 to improve compilation time
go-version: '>=1.25.0-rc.1'
cache-name: copilot-setup-steps
lint-cache: 'true'
- run: npm i -g @playwright/[email protected]
- run: npm ci
# pull dprint caches before network access is blocked
- run: npx hereby check:format || true
# cache build and lint operations
- run: npx hereby build || true
- run: npx hereby lint || true
49 changes: 49 additions & 0 deletions .github/workflows/create-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Create CI cache

on:
workflow_dispatch:
push:
branches:
- main
schedule:
# Run every day at 10:00 UTC / 03:00 PST
- cron: '0 10 * * *'

permissions:
contents: read

# Ensure scripts are run with pipefail. See:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
defaults:
run:
shell: bash

jobs:
cache:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
go-version:
- '>=1.24.0'

include:
# Temporary for the Copilot setup steps
- os: ubuntu-latest
go-version: '>=1.25.0-rc.1'

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
- uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable
- uses: ./.github/actions/setup-go
with:
go-version: ${{ matrix.go-version }}
create: 'true'
Loading