@@ -25,59 +25,78 @@ inputs:
2525 type : boolean
2626 required : false
2727 default : true
28+ bazel-version :
29+ description : ' Version of Bazel to use:'
30+ type : string
31+ required : false
32+ default : ' '
2833
2934permissions :
3035 actions : write
3136 contents : read
3237
38+ env :
39+ debug : ${{inputs.debug || runner.debug}}
40+ bazel-cache : ~/.cache/bazel
41+
3342runs :
3443 using : ' composite'
3544 steps :
36- - name : Read .bazelversion
37- id : read-version
45+ - name : Set environment variables
3846 shell : bash
47+ SHELLOPTS : ${{env.debug && 'xtrace' || ''}}
3948 run : |
40- if [[ ! -f ".bazelversion" ]]; then
41- echo "::error::.bazelversion file not found in repository root."
49+ version=""
50+ if [[ -n "${{inputs.bazel-version}}" ]]; then
51+ version="${{inputs.bazel-version}}"
52+ elif [[ -f ".bazelversion" ]]; then
53+ version="$(cat .bazelversion | tr -d ' \n\r')"
54+ else
55+ echo "::error::Bazel version has not been specified."
4256 exit 1
4357 fi
44- echo "version=$(cat .bazelversion | tr -d ' \n\r') " >> "$GITHUB_OUTPUT "
58+ echo "bazelversion=${version} " >> "$GITHUB_ENV "
4559
4660 - name : Install Bazelisk
4761 env :
48- BAZELISK_SHOW_PROGRESS : ${{inputs .debug == 'true' }}
62+ BAZELISK_SHOW_PROGRESS : ${{env .debug}}
4963 shell : bash
5064 run : npm install @bazel/bazelisk
5165
66+ # Explanation of the following caches:
67+ #
68+ # Bazelisk cache: stores copies of Bazel downloaded by Bazelisk. The copies
69+ # are stored in subdirs coded by hash numbers, and thus this cache can be
70+ # shared between workflows.
71+ #
72+ # Bazel --repository_cache: stores the raw downloaded files (like .zip,
73+ # .tar.gz) specified by repository rules like http_archive. This can also
74+ # be shared between workflows.
75+ #
76+ # Bazel --disk_cache: stores the compiled outputs of build actions, such as
77+ # compiled object files (.o), linked libraries (.so, .dll), binaries, & test
78+ # results. This is also sharable between workflows.
79+
5280 - name : Set up cache for Bazelisk
5381 uses : actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
5482 with :
83+ # Bazelisk doesn't have an option to control this cache location.
5584 path : ~/.cache/bazelisk
56- key : bazelisk-v1-${{runner.os}}-${{steps.read-version.outputs.version}}
57- restore-keys : bazelisk-v1-${{runner.os}}-
85+ key : bazelisk-cache
5886
5987 - name : Set up Bazel repository cache
6088 uses : actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
6189 with :
62- path : ~/.cache/bazel/repository_cache
63- # yamllint disable-line rule:line-length
64- key : bazel-repo-v1-${{runner.os}}-${{hashFiles('**/WORKSPACE', '**/BUILD', '**/BUILD.tpl', '**/*.bzl')}}
65- restore-keys : bazel-repo-v1-${{runner.os}}-
66-
67- - name : Set up Bazel external repositories cache
68- uses : actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
69- with :
70- path : ~/.cache/bazel/output_base/external
71- # yamllint disable-line rule:line-length
72- key : bazel-external-v1-${{runner.os}}-${{hashFiles('**/WORKSPACE', '**/BUILD', '**/BUILD.tpl', '**/*.bzl')}}
73- restore-keys : bazel-external-v1-${{runner.os}}-
90+ path : ${{env.bazel-cache}}/repository_cache
91+ key : bazel-repo-${{env.bazelversion}}
92+ restore-keys : bazel-repo-
7493
7594 - name : Set up Bazel disk cache
7695 uses : actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
7796 with :
78- path : ~/.cache/ bazel/disk_cache
79- key : bazel-disk-v1- ${{runner.os}}-${{github.ref}}-${{github.sha}}
80- restore-keys : bazel-disk-v1- ${{runner.os}}-${{github.ref}}-
97+ path : ${{env. bazel-cache}} /disk_cache
98+ key : bazel-disk-${{runner.os}}-${{runner.arch }}-${{github.ref}}-${{github.sha}}
99+ restore-keys : bazel-disk-${{runner.os}}-${{runner.arch }}-${{github.ref}}-
81100
82101 - name : Determine the number of processors we can use
83102 shell : bash
@@ -88,18 +107,19 @@ runs:
88107 echo "num_cpus=$(getconf _NPROCESSORS_ONLN)" >> "$GITHUB_ENV"
89108 fi
90109
91- - name : Make additions to .bazelrc for the cache configuration
110+ - name : Add configuration settings to .bazelrc
92111 shell : bash
93112 run : |
94113 {
95- echo "startup --output_base=~/.cache/ bazel/output_base"
96- echo "build --disk_cache=~/.cache/ bazel/disk_cache"
97- echo "build --repository_cache=~/.cache/ bazel/repository_cache"
114+ echo "startup --output_base=${{env. bazel-cache}} /output_base"
115+ echo "build --disk_cache=${{env. bazel-cache}} /disk_cache"
116+ echo "build --repository_cache=${{env. bazel-cache}} /repository_cache"
98117 echo "build --jobs=${{env.num_cpus}}"
118+ echo "test --cache_test_results=no"
99119 } >> .bazelrc
100120
101121 - name : Print configuration information
102- if : inputs .debug == 'true'
122+ if : env .debug
103123 shell : bash
104124 run : |
105125 bazelisk --version
0 commit comments