diff --git a/.github/actions/cache-query-compilation/action.yml b/.github/actions/cache-query-compilation/action.yml index b93e4f6c790d..9ca35e012186 100644 --- a/.github/actions/cache-query-compilation/action.yml +++ b/.github/actions/cache-query-compilation/action.yml @@ -14,11 +14,35 @@ outputs: runs: using: composite steps: - - name: Cache the query compilation caches - uses: ./.github/actions/incremental-cache + # calculate the merge-base with main, in a way that works both on PRs and pushes to main. + - name: Calculate merge-base + shell: bash + if: ${{ github.event_name == 'pull_request' }} + env: + BASE_BRANCH: ${{ github.base_ref }} + run: | + MERGE_BASE=$(git cat-file commit $GITHUB_SHA | grep '^parent ' | head -1 | cut -f 2 -d " ") + echo "merge_base=$MERGE_BASE" >> $GITHUB_ENV + - name: Restore read-only cache (PR) + if: ${{ github.event_name == 'pull_request' }} + uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6 + with: + path: '**/.cache' + read-only: true + key: ${{ inputs.key }}-pr-${{ github.sha }} + restore-keys: | + ${{ inputs.key }}-${{ github.base_ref }}-${{ env.merge_base }} + ${{ inputs.key }}-${{ github.base_ref }}- + ${{ inputs.key }}-main- + - name: Fill cache (push) + if: ${{ github.event_name != 'pull_request' }} + uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6 with: path: '**/.cache' - key: codeql-compile-${{ inputs.key }} + key: ${{ inputs.key }}-${{ github.ref_name }}-${{ github.sha }} # just fill on main + restore-keys: | # restore the latest cache if the exact cache is unavailable, to speed up compilation. + ${{ inputs.key }}-${{ github.ref_name }}- + ${{ inputs.key }}-main- - name: Fill compilation cache directory id: fill-compilation-dir shell: bash diff --git a/.github/actions/incremental-cache/action.yml b/.github/actions/incremental-cache/action.yml deleted file mode 100644 index 2ea627198860..000000000000 --- a/.github/actions/incremental-cache/action.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Setup an incremental cache -description: Special cache wrapper to be run on pull requests and pushes, that will try to restore - a cache as close as possible to the merge base - -inputs: - path: - description: 'The path to cache' - required: true - key: - description: 'The cache key to use - should be unique to the workflow' - required: true - -runs: - using: composite - steps: - # calculate the merge-base with main, in a way that works both on PRs and pushes to main. - - name: Calculate merge-base - shell: bash - if: ${{ github.event_name == 'pull_request' }} - env: - BASE_BRANCH: ${{ github.base_ref }} - run: | - MERGE_BASE=$(git cat-file commit $GITHUB_SHA | grep '^parent ' | head -1 | cut -f 2 -d " ") - echo "merge_base=$MERGE_BASE" >> $GITHUB_ENV - - name: Restore read-only cache (PR) - if: ${{ github.event_name == 'pull_request' }} - uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6 - with: - path: ${{ inputs.path }} - read-only: true - key: ${{ inputs.key }}-pr-${{ github.sha }} - restore-keys: | - ${{ inputs.key }}-${{ github.base_ref }}-${{ env.merge_base }} - ${{ inputs.key }}-${{ github.base_ref }}- - ${{ inputs.key }}-main- - - name: Fill cache (push) - if: ${{ github.event_name != 'pull_request' }} - uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6 - with: - path: ${{ inputs.path }} - key: ${{ inputs.key }}-${{ github.ref_name }}-${{ github.sha }} # just fill on main - restore-keys: | # restore the latest cache if the exact cache is unavailable, to speed up compilation. - ${{ inputs.key }}-${{ github.ref_name }}- - ${{ inputs.key }}-main- diff --git a/swift/actions/build-and-test/action.yml b/swift/actions/build-and-test/action.yml index 14f8107dc0fa..386bd4d5a19d 100644 --- a/swift/actions/build-and-test/action.yml +++ b/swift/actions/build-and-test/action.yml @@ -7,21 +7,43 @@ runs: - uses: actions/setup-python@v4 with: python-version-file: 'swift/.python-version' - - name: Mount bazel cache - uses: ./.github/actions/incremental-cache + # FIXME: this is copy-pasted from .github/actions/cache-query-compilation, but we cannot factor it out to a common + # composite action because of https://github.com/actions/runner/issues/2009 (cache fails to save in the post action + # phase because its inputs were lost in the meantime) + # calculate the merge-base with main, in a way that works both on PRs and pushes to main. + - name: Calculate merge-base + shell: bash + if: ${{ github.event_name == 'pull_request' }} + env: + BASE_BRANCH: ${{ github.base_ref }} + run: | + MERGE_BASE=$(git cat-file commit $GITHUB_SHA | grep '^parent ' | head -1 | cut -f 2 -d " ") + echo "merge_base=$MERGE_BASE" >> $GITHUB_ENV + - name: Restore read-only cache (PR) + if: ${{ github.event_name == 'pull_request' }} + uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6 with: - path: bazel-repository-cache - key: bazel-cache-${{ runner.os }}-${{ runner.arch }} - - name: Mount bazel disk cache - uses: ./.github/actions/incremental-cache + path: 'bazel-cache' + read-only: true + key: bazel-pr-${{ github.sha }} + restore-keys: | + bazel-${{ github.base_ref }}-${{ env.merge_base }} + bazel-${{ github.base_ref }}- + bazel-main- + - name: Fill cache (push) + if: ${{ github.event_name != 'pull_request' }} + uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6 with: - path: bazel-disk-cache - key: bazel-disk-cache-${{ runner.os }}-${{ runner.arch }} - - name: Configure bazel cache + path: 'bazel-cache' + key: bazel-${{ github.ref_name }}-${{ github.sha }} # just fill on main + restore-keys: | # restore the latest cache if the exact cache is unavailable, to speed up compilation. + bazel-${{ github.ref_name }}- + bazel-main- + - name: Configure bazel shell: bash run: | - mkdir bazel-repository-cache bazel-disk-cache - echo build --repository_cache=bazel-repository-cache --disk_cache=bazel-disk-cache > local.bazelrc + mkdir -p bazel-cache/{repository,disk} + echo build --repository_cache=bazel-cache/repository --disk_cache=bazel-cache/disk > local.bazelrc echo test --test_output=errors >> local.bazelrc - name: Print unextracted entities shell: bash @@ -51,5 +73,6 @@ runs: if: ${{ github.event_name != 'pull_request' }} shell: bash run: | - find bazel-repository-cache bazel-disk-cache -atime +0 -type f -delete - du -sh bazel-repository-cache bazel-disk-cache + du -sh bazel-cache/* + find bazel-cache -atime +0 -type f -delete + du -sh bazel-cache/*