From 0c064b5119f945aab1e8299dd2a285e5d18ea861 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 30 Dec 2023 17:58:18 +0100 Subject: [PATCH] Change: [CI] use vcpkg built-in caching mechanism --- .github/workflows/ci-build.yml | 46 ++++++++++++--------------- .github/workflows/release-linux.yml | 33 ++++++++++--------- .github/workflows/release-macos.yml | 22 +++++-------- .github/workflows/release-windows.yml | 25 +++++---------- 4 files changed, 52 insertions(+), 74 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 4da94d2073..d646a3a7bf 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -108,6 +108,14 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Setup vcpkg caching + uses: actions/github-script@v6 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + core.exportVariable('VCPKG_BINARY_SOURCES', 'clear;x-gha,readwrite') + - name: Install dependencies run: | echo "::group::Update apt" @@ -192,18 +200,13 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Prepare cache key - id: key - run: | - echo "image=$ImageOS-$ImageVersion" >> $GITHUB_OUTPUT - - - name: Enable vcpkg cache - uses: actions/cache@v3 + - name: Setup vcpkg caching + uses: actions/github-script@v6 with: - path: /usr/local/share/vcpkg/installed - key: ${{ steps.key.outputs.image }}-vcpkg-${{ matrix.arch }}-1 # Increase the number whenever dependencies are modified - restore-keys: | - ${{ steps.key.outputs.image }}-vcpkg-${{ matrix.arch }} + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + core.exportVariable('VCPKG_BINARY_SOURCES', 'clear;x-gha,readwrite') - name: Prepare vcpkg run: | @@ -272,22 +275,13 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Prepare cache key - id: key - shell: powershell - run: | - # Work around caching failure with GNU tar - New-Item -Type Junction -Path vcpkg -Target c:\vcpkg - - Write-Output "image=$env:ImageOS-$env:ImageVersion" >> $env:GITHUB_OUTPUT - - - name: Enable vcpkg cache - uses: actions/cache@v3 + - name: Setup vcpkg caching + uses: actions/github-script@v6 with: - path: vcpkg/installed - key: ${{ steps.key.outputs.image }}-vcpkg-${{ matrix.arch }}-1 # Increase the number whenever dependencies are modified - restore-keys: | - ${{ steps.key.outputs.image }}-vcpkg-${{ matrix.arch }} + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + core.exportVariable('VCPKG_BINARY_SOURCES', 'clear;x-gha,readwrite') - name: Prepare vcpkg shell: bash diff --git a/.github/workflows/release-linux.yml b/.github/workflows/release-linux.yml index bc65f12079..8a3fec19b5 100644 --- a/.github/workflows/release-linux.yml +++ b/.github/workflows/release-linux.yml @@ -17,11 +17,6 @@ jobs: # manylinux2014 is based on CentOS 7, but already has a lot of things # installed and preconfigured. It makes it easier to build OpenTTD. image: quay.io/pypa/manylinux2014_x86_64 - volumes: - - /usr/local/share/vcpkg:/vcpkg - env: - ImageOS: ${{ env.ImageOS }} - ImageVersion: ${{ env.ImageVersion }} steps: - name: Download source @@ -57,18 +52,13 @@ jobs: - name: Enable Rust cache uses: Swatinem/rust-cache@v2 - - name: Prepare cache key - id: key - run: | - echo "image=$ImageOS-$ImageVersion" >> $GITHUB_OUTPUT - - - name: Enable vcpkg cache - uses: actions/cache@v3 + - name: Setup vcpkg caching + uses: actions/github-script@v6 with: - path: /vcpkg/installed - key: ${{ steps.key.outputs.image }}-vcpkg-release-1 # Increase the number whenever dependencies are modified - restore-keys: | - ${{ steps.key.outputs.image }}-vcpkg-release + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + core.exportVariable('VCPKG_BINARY_SOURCES', 'clear;x-gha,readwrite') - name: Install dependencies run: | @@ -132,7 +122,16 @@ jobs: # We use vcpkg for our dependencies, to get more up-to-date version. echo "::group::Install vcpkg and dependencies" - # Make Python3 available for other packages. + git clone https://github.com/microsoft/vcpkg /vcpkg + + ( + cd /vcpkg + ./bootstrap-vcpkg.sh -disableMetrics + ) + + # Make Python3 available for other packages. This needs to be done + # first, as otherwise dependencies fail to build because Python3 is + # not available. /vcpkg/vcpkg install python3 ln -sf /vcpkg/installed/x64-linux/tools/python3/python3.[0-9][0-9] /usr/bin/python3 diff --git a/.github/workflows/release-macos.yml b/.github/workflows/release-macos.yml index 53f326c419..631584bc98 100644 --- a/.github/workflows/release-macos.yml +++ b/.github/workflows/release-macos.yml @@ -32,6 +32,14 @@ jobs: - name: Enable Rust cache uses: Swatinem/rust-cache@v2 + - name: Setup vcpkg caching + uses: actions/github-script@v6 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + core.exportVariable('VCPKG_BINARY_SOURCES', 'clear;x-gha,readwrite') + - name: Install dependencies env: HOMEBREW_NO_AUTO_UPDATE: 1 @@ -47,20 +55,6 @@ jobs: cargo install dump_syms echo "::endgroup::" - - name: Prepare cache key - id: key - run: | - echo "image=$ImageOS-$ImageVersion" >> $GITHUB_OUTPUT - - - name: Enable vcpkg cache - uses: actions/cache@v3 - with: - path: /usr/local/share/vcpkg/installed - key: ${{ steps.key.outputs.image }}-vcpkg-release-1 # Increase the number whenever dependencies are modified - restore-keys: | - ${{ steps.key.outputs.image }}-vcpkg-release - ${{ steps.key.outputs.image }}-vcpkg-x64 - - name: Prepare vcpkg run: | vcpkg install \ diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml index 4b883675bd..3f7658083d 100644 --- a/.github/workflows/release-windows.yml +++ b/.github/workflows/release-windows.yml @@ -45,6 +45,14 @@ jobs: - name: Enable Rust cache uses: Swatinem/rust-cache@v2 + - name: Setup vcpkg caching + uses: actions/github-script@v6 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + core.exportVariable('VCPKG_BINARY_SOURCES', 'clear;x-gha,readwrite') + - name: Install dependencies shell: bash run: | @@ -56,23 +64,6 @@ jobs: cargo install dump_syms echo "::endgroup::" - - name: Prepare cache key - id: key - shell: powershell - run: | - # Work around caching failure with GNU tar - New-Item -Type Junction -Path vcpkg -Target c:\vcpkg - - Write-Output "image=$env:ImageOS-$env:ImageVersion" >> $env:GITHUB_OUTPUT - - - name: Enable vcpkg cache - uses: actions/cache@v3 - with: - path: vcpkg/installed - key: ${{ steps.key.outputs.image }}-vcpkg-${{ matrix.arch }}-1 # Increase the number whenever dependencies are modified - restore-keys: | - ${{ steps.key.outputs.image }}-vcpkg-${{ matrix.arch }} - - name: Prepare vcpkg shell: bash run: |