diff --git a/.github/actions/setup-vcpkg/action.yml b/.github/actions/setup-vcpkg/action.yml new file mode 100644 index 00000000..65292cb2 --- /dev/null +++ b/.github/actions/setup-vcpkg/action.yml @@ -0,0 +1,44 @@ +name: Set up vcpkg +description: Set up vcpkg with a persistent binary cache and download retries. + +inputs: + cache-key: + description: Matrix configuration (compiler, standard, format, and build variant). + required: true + +runs: + using: composite + steps: + - name: Configure caching and download retries + id: config + shell: bash + env: + # vcpkg quotes {url} and {dst} itself, including paths containing spaces. + # Retry individual downloads, including DNS errors, rather than builds. + X_VCPKG_ASSET_SOURCES: >- + x-script,curl --fail --location --retry 2 --retry-all-errors + --retry-delay 10 --connect-timeout 30 --output {dst} {url} + run: | + cache_dir="${RUNNER_TEMP//\\//}/vcpkg-binary-cache" + mkdir -p "$cache_dir" + echo "VCPKG_BINARY_SOURCES=clear;files,$cache_dir,readwrite" >> "$GITHUB_ENV" + echo "X_VCPKG_ASSET_SOURCES=$X_VCPKG_ASSET_SOURCES" >> "$GITHUB_ENV" + echo "cache-path=$cache_dir" >> "$GITHUB_OUTPUT" + echo "vcpkg-revision=$(git rev-parse HEAD:vcpkg)" >> "$GITHUB_OUTPUT" + echo "image-version=${ImageVersion:-unknown}" >> "$GITHUB_OUTPUT" + + # run-vcpkg requires binaryCachePath to exist before the action starts. + - uses: lukka/run-vcpkg@v11 + with: + binaryCachePath: ${{ steps.config.outputs.cache-path }} + + - name: Cache vcpkg binaries + uses: actions/cache@v4 + with: + path: ${{ steps.config.outputs.cache-path }} + # Separate matrix jobs to avoid competing to save different package sets. + # A new runner image may change the compiler and therefore package ABIs. + key: vcpkg-v1-${{ runner.os }}-${{ runner.arch }}-${{ inputs.cache-key }}-${{ steps.config.outputs.image-version }}-${{ steps.config.outputs.vcpkg-revision }}-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'CMakeLists.txt', 'cmake/**') }} + # vcpkg validates package ABIs when reusing an older dependency cache. + restore-keys: | + vcpkg-v1-${{ runner.os }}-${{ runner.arch }}-${{ inputs.cache-key }}-${{ steps.config.outputs.image-version }}- diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 219f2bc0..82807af9 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -2,9 +2,6 @@ name: linux on: [ push, pull_request ] -env: - VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" - jobs: linux: strategy: @@ -65,14 +62,10 @@ jobs: with: submodules: recursive fetch-depth: 0 - - name: Export GitHub Actions cache environment variables - uses: actions/github-script@v7 + - name: Set up vcpkg + uses: ./.github/actions/setup-vcpkg with: - script: | - core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); - core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); - - name: Run vcpkg - uses: lukka/run-vcpkg@v11 + cache-key: ${{ github.job }}-${{ matrix.compiler }}-${{ matrix.compiler-version }}-cxx${{ matrix.cxx }}-${{ matrix.format }} - name: Install dependencies run: | sudo apt update diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index 8c2e4da2..2f5fba43 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -2,9 +2,6 @@ name: macos on: [ push, pull_request ] -env: - VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" - jobs: macos-clang: strategy: @@ -23,14 +20,10 @@ jobs: with: submodules: recursive fetch-depth: 0 - - name: Export GitHub Actions cache environment variables - uses: actions/github-script@v7 + - name: Set up vcpkg + uses: ./.github/actions/setup-vcpkg with: - script: | - core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); - core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); - - name: Run vcpkg - uses: lukka/run-vcpkg@v11 + cache-key: ${{ matrix.os }}-${{ matrix.format }} - name: Install bison run: brew install bison openssl@3 - name: Install ninja diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index 27dc497f..8b4af4ad 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -2,9 +2,6 @@ name: windows on: [ push, pull_request ] -env: - VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" - jobs: windows-msvc: strategy: @@ -22,14 +19,11 @@ jobs: with: submodules: recursive fetch-depth: 0 - - name: Export GitHub Actions cache environment variables - uses: actions/github-script@v7 - with: - script: | - core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); - core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); - uses: ilammy/msvc-dev-cmd@v1 - - uses: lukka/run-vcpkg@v11 + - name: Set up vcpkg + uses: ./.github/actions/setup-vcpkg + with: + cache-key: ${{ github.job }}-${{ matrix.format }} - name: Compile benchmarks if: matrix.format == 'benchmarks' run: | @@ -91,14 +85,11 @@ jobs: with: submodules: recursive fetch-depth: 0 - - name: Export GitHub Actions cache environment variables - uses: actions/github-script@v7 - with: - script: | - core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); - core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); - uses: ilammy/msvc-dev-cmd@v1 - - uses: lukka/run-vcpkg@v11 + - name: Set up vcpkg + uses: ./.github/actions/setup-vcpkg + with: + cache-key: ${{ github.job }}-${{ matrix.format }} - name: Compile tests (JSON) if: matrix.format == 'JSON' run: |