From 71456287235f4ada8ba4cf306ac4770f0ddecc09 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 12 Mar 2023 10:58:08 +0100 Subject: [PATCH] Speed up CI. (#142918) --- .github/workflows/cache.yml | 11 ++++++----- .github/workflows/ci.yml | 30 +++++++++++++++++++++--------- cmd/lib/ci_matrix.rb | 3 +++ cmd/lib/generate-matrix.rb | 14 ++++++++++---- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/.github/workflows/cache.yml b/.github/workflows/cache.yml index 2aa8aa2ade..d785b904e6 100644 --- a/.github/workflows/cache.yml +++ b/.github/workflows/cache.yml @@ -19,10 +19,11 @@ jobs: if: startsWith(github.repository, 'Homebrew/') strategy: matrix: - os: - - macos-11.0 + runner: + - macos-11 + - macos-12 - ubuntu-latest - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.runner }} steps: - name: Set up Homebrew id: set-up-homebrew @@ -35,8 +36,8 @@ jobs: uses: actions/cache@v3 with: path: ${{ steps.set-up-homebrew.outputs.gems-path }} - key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }} - restore-keys: ${{ runner.os }}-rubygems- + key: ${{ matrix.runner }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }} + restore-keys: ${{ matrix.runner }}-rubygems- - name: Install Homebrew Gems id: gems diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a10782c71..44577fb7fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: generate-matrix: outputs: matrix: ${{ steps.generate-matrix.outputs.matrix }} - runs-on: ubuntu-latest + runs-on: macos-latest steps: - name: Set up Homebrew id: set-up-homebrew @@ -79,7 +79,7 @@ jobs: if ! rm /usr/local/share/man/man1/al.1 || \ ! sudo rm /etc/paths.d/mono-commands || \ - ! sudo rm -r /Library/Frameworks/Mono.framework || \ + ! sudo rm -r /Library/Frameworks/Mono.framework || \ ! sudo pkgutil --forget com.xamarin.mono-MDK.pkg; then echo '::warning::Uninstalling Mono is no longer necessary.' fi @@ -100,39 +100,51 @@ jobs: if: runner.os == 'macOS' - name: Cache Homebrew Gems + id: cache uses: actions/cache@v3 with: path: ${{ steps.set-up-homebrew.outputs.gems-path }} - key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }} - restore-keys: ${{ runner.os }}-rubygems- + key: ${{ matrix.runner }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }} + restore-keys: ${{ matrix.runner }}-rubygems- - name: Install Homebrew Gems id: gems run: brew install-bundler-gems + if: steps.cache.outputs.cache-hit != 'true' - name: Run brew readall ${{ matrix.tap }} id: readall run: brew readall '${{ matrix.tap }}' - if: always() && steps.gems.outcome == 'success' + if: > + always() && + contains(fromJSON('["success", "skipped"]'), steps.gems.outcome) && + !matrix.skip_readall - name: Run brew style ${{ matrix.tap }} run: brew style '${{ matrix.tap }}' - if: always() && steps.readall.outcome == 'success' && !matrix.cask + if: > + always() && + contains(fromJSON('["success", "skipped"]'), steps.readall.outcome) && + !matrix.cask - name: Run brew fetch --cask ${{ matrix.cask.token }} id: fetch run: | brew fetch --cask --retry --force '${{ matrix.cask.path }}' timeout-minutes: 30 - if: always() && steps.readall.outcome == 'success' && matrix.cask + if: > + always() && + contains(fromJSON('["success", "skipped"]'), steps.readall.outcome) && + matrix.cask - name: Run brew audit --cask${{ (matrix.cask && ' ') || ' --tap ' }}${{ matrix.cask.token || matrix.tap }} id: audit run: | - brew audit --cask ${{ join(matrix.audit_args, ' ') }}${{ (matrix.cask && ' --signing ') || ' --tap ' }}'${{ matrix.cask.token || matrix.tap }}' + brew audit --cask ${{ join(matrix.audit_args, ' ') }}${{ (matrix.cask && ' ') || ' --tap ' }}'${{ matrix.cask.token || matrix.tap }}' timeout-minutes: 30 if: > - always() && steps.readall.outcome == 'success' && + always() && + contains(fromJSON('["success", "skipped"]'), steps.readall.outcome) && (!matrix.cask || steps.fetch.outcome == 'success') && !matrix.skip_audit diff --git a/cmd/lib/ci_matrix.rb b/cmd/lib/ci_matrix.rb index d7a8fc27e0..86cf8fed0d 100644 --- a/cmd/lib/ci_matrix.rb +++ b/cmd/lib/ci_matrix.rb @@ -112,6 +112,8 @@ module CiMatrix audit_args = ["--online"] audit_args << "--new-cask" if changed_files[:added_files].include?(path) + audit_args << "--signing" + audit_exceptions = [] # TODO: Replace with `except`. @@ -144,6 +146,7 @@ module CiMatrix }, audit_args: audit_args, skip_install: labels.include?("ci-skip-install"), + skip_readall: false, runner: runner[:name], } end diff --git a/cmd/lib/generate-matrix.rb b/cmd/lib/generate-matrix.rb index d343d8305f..326f42dd18 100755 --- a/cmd/lib/generate-matrix.rb +++ b/cmd/lib/generate-matrix.rb @@ -18,9 +18,10 @@ tap = Tap.fetch(ENV.fetch("GITHUB_REPOSITORY")) runner = CiMatrix.random_runner[:name] syntax_job = { - name: "syntax", - tap: tap.name, - runner: runner, + name: "syntax", + tap: tap.name, + runner: runner, + skip_readall: false, } matrix = [syntax_job] @@ -32,8 +33,13 @@ unless labels.include?("ci-syntax-only") # If casks were changed, skip `audit` for whole tap. syntax_job[:skip_audit] = true + # If casks were cahnged, skip `readall` in the syntax job. + syntax_job[:skip_readall] = true + # The syntax job only runs `style` at this point, which should work on Linux. - syntax_job[:runner] = "ubuntu-latest" + # Running on macOS is currently faster though, since `homebrew/cask` and + # `homebrew/core` are already tapped on macOS CI machines. + # syntax_job[:runner] = "ubuntu-latest" end matrix += cask_jobs