diff --git a/.github/actions/setup-go/action.yml b/.github/actions/setup-go/action.yml index 1bf1db92b0..863bec5a3a 100644 --- a/.github/actions/setup-go/action.yml +++ b/.github/actions/setup-go/action.yml @@ -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 @@ -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/mtimehash@v1.0.0 || 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 }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 54555d8a12..fdf3184856 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 }} @@ -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 }} @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 222d1f5108..010101eca4 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -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/mcp@0.0.28 - 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 diff --git a/.github/workflows/create-cache.yml b/.github/workflows/create-cache.yml new file mode 100644 index 0000000000..e15554e10f --- /dev/null +++ b/.github/workflows/create-cache.yml @@ -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'