Repository navigation
116 lines (107 loc) · 4.25 KB
/
Copy pathdependency-cache.yml
File metadata and controls
116 lines (107 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Bazel dependency cache
on:
push:
branches: [master]
paths:
- MODULE.bazel
- Cargo.lock
- pnpm-lock.yaml
- .bazelversion
- .bazelrc
- scripts/bazel/downloader.cfg
- .github/actions/setup-bazel/**
- .github/workflows/dependency-cache.yml
workflow_dispatch:
inputs:
offline:
description: Verify restored dependencies with Bazel downloads disabled
type: boolean
default: false
permissions:
contents: read
concurrency:
group: bazel-dependency-cache-${{ github.ref }}
cancel-in-progress: false
jobs:
helpers:
name: Cache launcher helpers
outputs:
cache-key: ${{ steps.bazel.outputs.launcher-cache-key }}
runs-on: ubuntu-latest
timeout-minutes: 15
env:
OFFLINE: ${{ inputs.offline == true }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./.github/actions/setup-bazel
id: bazel
with:
release-download-token: ${{ github.token }}
cache-key: dependency-helpers
cache-save: ${{ inputs.offline != true }}
verify-launcher-cache: ${{ inputs.offline == true }}
- &resolve-helpers
name: Resolve launcher helpers for every supported platform
id: fetch
run: |
set -euo pipefail
targets=()
for stub in runfiles finalize; do
for platform in aarch64_linux aarch64_macos aarch64_windows s390x_linux x86_64_linux x86_64_macos x86_64_windows; do
targets+=("@@hermetic_launcher++non_module_dependencies+${stub}_stub_${platform}//file:file")
done
done
options=()
if [[ "$OFFLINE" == true ]]; then
options+=(--repository_disable_download)
fi
bazel build "${options[@]}" "${targets[@]}"
# Only a successful build of every target establishes a complete archive.
# A warm workload cache can already contain every blob on the
# first run; the immutable helper key must still be published then.
- name: Publish complete launcher helpers
if: success() && github.ref == 'refs/heads/master' && inputs.offline != true && steps.bazel.outputs.launcher-cache-hit != 'true' && steps.bazel.outputs.launcher-cache-key != ''
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ steps.bazel.outputs.repository-cache-path }}
key: ${{ steps.bazel.outputs.launcher-cache-key }}
- name: Preserve partially fetched launcher dependencies
if: failure() && !cancelled() && steps.fetch.outcome == 'failure' && steps.bazel.outputs.repository-cache-key != ''
uses: ./.github/actions/setup-bazel/save
with:
path: ${{ steps.bazel.outputs.repository-cache-path }}
key: ${{ steps.bazel.outputs.repository-cache-key }}
restored-entries: ${{ steps.bazel.outputs.repository-cache-entries }}
verify:
name: Verify restored dependency cache
needs: helpers
if: inputs.offline != true && github.ref == 'refs/heads/master'
permissions:
contents: read
actions: write
runs-on: ubuntu-latest
timeout-minutes: 15
env:
OFFLINE: "true"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./.github/actions/setup-bazel
with:
cache-key: dependency-helpers-verification
repository-cache-key: ${{ needs.helpers.outputs.cache-key }}
cache-save: "false"
verify-launcher-cache: "true"
- *resolve-helpers
- name: Retire incomplete legacy Linux cache snapshots
if: github.ref == 'refs/heads/master'
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
gh cache list --repo "$GITHUB_REPOSITORY" --ref refs/heads/master \
--key setup-bazel-1-linux-x64-repository- --limit 100 --json id,key \
--jq '.[] | select(.key | test("^setup-bazel-1-linux-x64-repository-[0-9a-f]{64}$")) | .id' \
> "$RUNNER_TEMP/legacy-dependency-caches"
while IFS= read -r id; do
gh cache delete "$id" --repo "$GITHUB_REPOSITORY"
done < "$RUNNER_TEMP/legacy-dependency-caches"