Skip to content

Commit

Permalink
CI: Save bootstrap cache right after bootrap
Browse files Browse the repository at this point in the history
This avoids caching a corrupted cache in cases where a job modifies the
environment (e.g. the Darwin job hiding zap-cli). It also makes the cache
available slightly sooner.

Also add plumbing for splitting caches over buildjet and github backends.
  • Loading branch information
ksperling-apple committed Mar 27, 2024
1 parent b05de16 commit 77b367a
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions .github/actions/bootstrap/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,67 @@ inputs:
outputs:
cache-hit:
description: "Bootstrap environment was restored from cache"
value: ${{ fromJSON(steps.bootstrap-cache.outputs.outputs).cache-hit }} # retry returns all outputs in `outputs`
value: ${{ fromJSON(steps.restore.outputs.outputs).cache-hit }} # retry returns all outputs in `outputs`

runs:
using: "composite"
steps:
- name: Calculate bootstrap cache key
id: bootstrap-cache-key
- name: Determine bootstrap cache configuration
id: prepare
shell: bash
run: |
# Calculate bootstrap cache key
# In addition to the various setup files, the work directory matters as well,
# because the bootstrapped Pigweed environment contains absolute paths.
echo "Calculating bootstrap cache key for '$PWD'"
FILES_HASH="${{ hashFiles('scripts/setup/*', 'third_party/pigweed/**') }}"
FINAL_HASH="$(echo "$PWD:$FILES_HASH" | shasum -a 256 | cut -d' ' -f1)"
echo "Calculated bootstrap cache key for '$PWD': $FINAL_HASH"
echo "hash=$FINAL_HASH" >> "$GITHUB_OUTPUT"
echo key="${RUNNER_OS}-${RUNNER_ARCH}-${{ inputs.platform }}-${FINAL_HASH}" | tee -a "$GITHUB_OUTPUT"
- uses: Wandalen/[email protected]
name: Bootstrap from cache
id: bootstrap-cache
# Define cache paths in one place (composite actions don't support a top-level env)
echo paths=".environment build_overrides/pigweed_environment.gni" | tee -a "$GITHUB_OUTPUT"
# Split caches across backends
case "$RUNNER_OS" in
macOS) echo backend=actions;;
*) echo backend=buildjet;;
esac | tee -a "$GITHUB_OUTPUT"
- name: Bootstrap from cache
id: restore
uses: Wandalen/[email protected]
continue-on-error: true
with:
action: buildjet/cache@v4
action: ${{ steps.prepare.outputs.backend }}/cache/restore@v4
attempt_limit: 3
attempt_delay: 2000
with: |
key: ${{ runner.os }}-${{ runner.arch }}-${{ inputs.platform }}-${{ steps.bootstrap-cache-key.outputs.hash}}
path: |
.environment
build_overrides/pigweed_environment.gni
key: ${{ steps.prepare.outputs.key }}
path: ${{ steps.prepare.outputs.paths }}
- name: Run bootstrap
if: fromJSON(steps.bootstrap-cache.outputs.outputs).cache-hit != 'true'
if: ${{ fromJSON(steps.restore.outputs.outputs).cache-hit != 'true' }}
env:
PW_NO_CIPD_CACHE_DIR: Y
PW_NO_CIPD_CACHE_DIR: 1
PW_ENVSETUP_NO_BANNER: 1
shell: bash
run: source scripts/bootstrap.sh -p all,${{ inputs.platform }}

- name: Uploading bootstrap logs
- name: Save bootstrap cache
uses: Wandalen/[email protected]
if: ${{ fromJSON(steps.restore.outputs.outputs).cache-hit != 'true' }}
continue-on-error: true
with:
action: ${{ steps.prepare.outputs.backend }}/cache/save@v4
attempt_limit: 3
attempt_delay: 2000
with: |
key: ${{ steps.prepare.outputs.key }}
path: ${{ steps.prepare.outputs.paths }}
- name: Upload bootstrap logs
uses: actions/upload-artifact@v4
if: always() && !env.ACT && fromJSON(steps.bootstrap-cache.outputs.outputs).cache-hit != 'true'
if: ${{ always() && !env.ACT && fromJSON(steps.restore.outputs.outputs).cache-hit != 'true' }}
with:
name: ${{ inputs.bootstrap-log-name }}
path: |
Expand Down

0 comments on commit 77b367a

Please sign in to comment.