From ec849e0899015e6c24db893354a73f7ff866ea53 Mon Sep 17 00:00:00 2001 From: Nicholas Dudfield Date: Tue, 25 Mar 2025 14:09:24 +0700 Subject: [PATCH] [CONAN] cache build directory too --- .github/workflows/macos-ga.yml | 15 ++++++++++----- .github/workflows/nix-ga.yml | 15 +++++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/workflows/macos-ga.yml b/.github/workflows/macos-ga.yml index 350b4b5a4..525a45c9d 100644 --- a/.github/workflows/macos-ga.yml +++ b/.github/workflows/macos-ga.yml @@ -111,18 +111,23 @@ jobs: ~/.conan2 key: ${{ steps.cache-restore.outputs.cache-primary-key }} + # Add this step to generate a safe branch name + - name: Generate safe branch name + id: safe-branch + run: | + # Replace characters that aren't allowed in cache keys + SAFE_BRANCH=$(echo "${{ github.ref_name }}" | tr -c 'a-zA-Z0-9_.-' '-') + echo "name=${SAFE_BRANCH}" >> $GITHUB_OUTPUT + # After your cache restore for Conan but before the build step - name: Restore build directory cache id: build-cache-restore uses: actions/cache/restore@v4 with: path: ${{ env.build_dir }} - # Primary key without SHA - much higher hit probability - key: ${{ runner.os }}-build-${{ matrix.configuration }}-${{ github.ref_name }}-${{ hashFiles('**/conanfile.txt', '**/conanfile.py') }} + key: ${{ runner.os }}-build-${{ matrix.configuration }}-${{ steps.safe-branch.outputs.name }}-${{ hashFiles('**/conanfile.txt', '**/conanfile.py') }} restore-keys: | - # Same branch, different dependencies - ${{ runner.os }}-build-${{ matrix.configuration }}-${{ github.ref_name }}- - # Same configuration, any branch + ${{ runner.os }}-build-${{ matrix.configuration }}-${{ steps.safe-branch.outputs.name }}- ${{ runner.os }}-build-${{ matrix.configuration }}- # Build still calls the install dependency installation every time diff --git a/.github/workflows/nix-ga.yml b/.github/workflows/nix-ga.yml index 1769c2101..cab32d681 100644 --- a/.github/workflows/nix-ga.yml +++ b/.github/workflows/nix-ga.yml @@ -109,18 +109,21 @@ jobs: ${{ matrix.cc }} --version ${{ matrix.cxx }} --version - # After your Conan cache restore but before the build step + - name: Generate safe branch name + id: safe-branch + run: | + # Replace characters that aren't allowed in cache keys + SAFE_BRANCH=$(echo "${{ github.ref_name }}" | tr -c 'a-zA-Z0-9_.-' '-') + echo "name=${SAFE_BRANCH}" >> $GITHUB_OUTPUT + - name: Restore build directory cache id: build-cache-restore uses: actions/cache/restore@v4 with: path: ${{ env.build_dir }} - # Primary key without SHA - much higher hit probability - key: ${{ runner.os }}-build-${{ matrix.compiler }}-${{ matrix.configuration }}-${{ github.ref_name }}-${{ hashFiles('**/conanfile.txt', '**/conanfile.py') }} + key: ${{ runner.os }}-build-${{ matrix.compiler }}-${{ matrix.configuration }}-${{ steps.safe-branch.outputs.name }}-${{ hashFiles('**/conanfile.txt', '**/conanfile.py') }} restore-keys: | - # Same branch, different dependencies - ${{ runner.os }}-build-${{ matrix.compiler }}-${{ matrix.configuration }}-${{ github.ref_name }}- - # Same compiler/config, any branch + ${{ runner.os }}-build-${{ matrix.compiler }}-${{ matrix.configuration }}-${{ steps.safe-branch.outputs.name }}- ${{ runner.os }}-build-${{ matrix.compiler }}-${{ matrix.configuration }}- - name: Build