2023-03-20 11:05:08 -04:00
name : Setup bazel
description : Setup Bazel for CI builds and tests
inputs :
useCache :
2023-06-23 06:12:32 -04:00
description : "Cache Bazel artifacts. Use 'true' to enable with rw, 'readonly' to download, 'log' to disable cache but upload logs, and 'false' to disable."
2023-03-20 11:05:08 -04:00
default : "false"
required : true
buildBuddyApiKey :
description : "BuildBuddy API key for caching Bazel artifacts"
required : false
runs :
using : "composite"
steps :
- name : Check inputs
shell : bash
run : |
echo "::group::Check inputs"
2023-06-23 06:12:32 -04:00
if [[ "${{ inputs.useCache }}" != "true" && "${{ inputs.useCache }}" != "readonly" && "${{ inputs.useCache }}" != "logs" && "${{ inputs.useCache }}" != "false" ]]; then
2023-03-20 11:05:08 -04:00
echo "Invalid value for 'useCache' input: '${{ inputs.useCache }}'. Must be 'true', 'readonly', or 'false'."
exit 1
fi
2023-06-23 06:12:32 -04:00
if [[ "${{ inputs.useCache }}" == "true" || "${{ inputs.useCache }}" == "readonly" || "${{ inputs.useCache }}" == "logs" ]] && [[ -z "${{ inputs.buildBuddyApiKey }}" ]]; then
2023-03-20 11:05:08 -04:00
echo "BuildBuddy API key is required when cache is enabled."
exit 1
fi
echo "::endgroup::"
2023-03-21 05:06:32 -04:00
2023-05-19 09:55:41 -04:00
- name : Configure Bazel (general)
shell : bash
env :
WORKSPACE : ${{ github.workspace }}
run : |
echo "::group::Configure Bazel"
cat <<EOF >> "${WORKSPACE}/.bazeloverwriterc"
2023-08-15 04:34:42 -04:00
# general
common --color=yes
common --terminal_columns=143
common --build_metadata=ROLE=CI
common --show_progress_rate_limit=5
common --curses=yes
common --verbose_failures
common --announce_rc
# test related
2023-05-19 09:55:41 -04:00
test --show_timestamps
test --keep_going
2023-08-15 04:34:42 -04:00
# remote cache / execution related
common --bes_timeout=600s
common --experimental_remote_build_event_upload=minimal
common --experimental_remote_cache_compression
common --nolegacy_important_outputs
common --noremote_upload_local_results
common --remote_timeout=3600
2023-05-19 09:55:41 -04:00
EOF
echo "::endgroup::"
2023-03-21 05:06:32 -04:00
2023-05-19 09:55:41 -04:00
- name : Configure Bazel (rw)
2023-03-20 11:05:08 -04:00
shell : bash
if : inputs.useCache == 'true' || inputs.useCache == 'readonly'
env :
BUILDBUDDY_ORG_API_KEY : ${{ inputs.buildBuddyApiKey }}
2023-05-19 09:55:41 -04:00
WORKSPACE : ${{ github.workspace }}
2023-03-20 11:05:08 -04:00
run : |
echo "::group::Configure Bazel"
2023-05-19 09:55:41 -04:00
cat <<EOF >> "${WORKSPACE}/.bazeloverwriterc"
2023-08-15 04:34:42 -04:00
common --bes_results_url=https://app.buildbuddy.io/invocation/
common --bes_backend=grpcs://remote.buildbuddy.io
common --remote_cache=grpcs://remote.buildbuddy.io
common --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_ORG_API_KEY}
2023-03-20 11:05:08 -04:00
EOF
echo "::endgroup::"
2023-03-21 05:06:32 -04:00
2023-03-20 11:05:08 -04:00
- name : Configure Bazel (readonly)
shell : bash
2023-06-23 06:12:32 -04:00
if : inputs.useCache == 'readonly'
2023-06-09 10:59:19 -04:00
env :
WORKSPACE : ${{ github.workspace }}
2023-03-20 11:05:08 -04:00
run : |
echo "::group::Configure Bazel (readonly)"
2023-08-15 04:34:42 -04:00
echo "common --remote_upload_local_results=false" >> "${WORKSPACE}/.bazeloverwriterc"
2023-03-20 11:05:08 -04:00
echo "::endgroup::"
2023-03-21 05:06:32 -04:00
2023-06-23 06:12:32 -04:00
- name : Configure Bazel (logs)
shell : bash
if : inputs.useCache == 'logs'
env :
BUILDBUDDY_ORG_API_KEY : ${{ inputs.buildBuddyApiKey }}
WORKSPACE : ${{ github.workspace }}
run : |
echo "::group::Configure Bazel"
cat <<EOF >> "${WORKSPACE}/.bazeloverwriterc"
2023-08-15 04:34:42 -04:00
common --bes_results_url=https://app.buildbuddy.io/invocation/
common --bes_backend=grpcs://remote.buildbuddy.io
common --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_ORG_API_KEY}
2023-06-23 06:12:32 -04:00
EOF
echo "::endgroup::"
2023-06-09 10:59:19 -04:00
- name : Disable disk cache on GitHub Actions runners
shell : bash
env :
WORKSPACE : ${{ github.workspace }}
if : startsWith(runner.name , 'GitHub Actions')
run : |
echo "::group::Configure Bazel (disk cache)"
2023-08-15 04:34:42 -04:00
echo "common --disk_cache=" >> "${WORKSPACE}/.bazeloverwriterc"
echo "common --repository_cache=" >> "${WORKSPACE}/.bazeloverwriterc"
2023-06-09 10:59:19 -04:00
echo "::endgroup::"
2023-03-20 11:05:08 -04:00
- name : Check bazel version
shell : bash
run : bazel version