2023-10-04 07:55:38 -04:00
name : Setup bazel and Nix
description : Setup Bazel and Nix for CI builds and tests
2023-03-20 11:05:08 -04:00
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
2023-10-04 07:55:38 -04:00
id : check_inputs
2023-03-20 11:05:08 -04:00
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
2023-10-04 07:55:38 -04:00
if command -v nix; then
echo "nixPreinstalled=true" | tee -a "$GITHUB_OUTPUT"
else
echo "nixPreinstalled=false" | tee -a "$GITHUB_OUTPUT"
fi
if command -v bazel; then
echo "bazelPreinstalled=true" | tee -a "$GITHUB_OUTPUT"
else
echo "bazelPreinstalled=false" | tee -a "$GITHUB_OUTPUT"
fi
if [[ -f /etc/NIXOS ]]; then
echo "nixOS=true" | tee -a "$GITHUB_OUTPUT"
else
echo "nixOS=false" | tee -a "$GITHUB_OUTPUT"
fi
if [[ "$RUNNER_OS" == "Linux" ]]; then
echo "os=linux" | tee -a "$GITHUB_OUTPUT"
elif [[ "$RUNNER_OS" == "Windows" ]]; then
echo "os=windows" | tee -a "$GITHUB_OUTPUT"
elif [[ "$RUNNER_OS" == "macOS" ]]; then
echo "os=darwin" | tee -a "$GITHUB_OUTPUT"
else
echo "$RUNNER_OS not supported"
exit 1
fi
if [[ "$RUNNER_ARCH" == "X64" ]]; then
echo "arch=amd64" | tee -a "$GITHUB_OUTPUT"
elif [[ "$RUNNER_ARCH" == "ARM64" ]]; then
echo "arch=arm64" | tee -a "$GITHUB_OUTPUT"
else
echo "$RUNNER_ARCH not supported"
exit 1
fi
echo "::endgroup::"
- name : Install nix
if : steps.check_inputs.outputs.nixPreinstalled == 'false'
uses : cachix/install-nix-action@6ed004b9ccb68dbc28e7c85bee15fa93dbd214ac # v22
2023-10-12 10:11:02 -04:00
- name : Set $USER if not set
shell : bash
run : |
echo "::group::Set \$USER if not set"
if [[ -z "$USER" ]]; then
echo "USER=$(id -un)" | tee -a "$GITHUB_ENV"
fi
echo "::endgroup::"
- uses : cachix/cachix-action@6a9a34cdd93d0ae4b4b59fd678660efb08109f2f # v12
with :
name : katexochen
extraPullNames : nix-community
2023-10-04 07:55:38 -04:00
- name : Install Bazelisk
if : steps.check_inputs.outputs.bazelPreinstalled == 'false' && steps.check_inputs.outputs.nixOS == 'false'
shell : bash
env :
OS : ${{ steps.check_inputs.outputs.os }}
ARCH : ${{ steps.check_inputs.outputs.arch }}
run : |
echo "::group::Install Bazelisk"
curl -fsSLo /usr/local/bin/bazel "https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/bazelisk-${OS}-${ARCH}"
chmod +x /usr/local/bin/bazel
2023-03-20 11:05:08 -04:00
echo "::endgroup::"
2023-03-21 05:06:32 -04:00
2023-10-09 05:00:22 -04:00
- name : Free up space (Ubuntu)
shell : bash
if : startsWith(runner.name, 'GitHub Actions') && runner.os == 'Linux'
run : |
echo "::group::Free up space (Ubuntu)"
echo "Available storage (before):"
df -h
2023-10-12 08:07:59 -04:00
sudo apt-get update || true
sudo apt-get remove -y '^dotnet-.*' || true
sudo apt-get remove -y '^llvm-.*' || true
sudo apt-get remove -y 'php.*' || true
sudo apt-get remove -y '^mongodb-.*' || true
sudo apt-get remove -y '^mysql-.*' || true
2023-10-09 05:00:22 -04:00
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
2023-10-12 08:07:59 -04:00
sudo apt-get autoremove -y || true
sudo apt-get clean || true
2023-10-09 05:00:22 -04:00
echo "Available storage (after):"
df -h
echo "::endgroup::"
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-18 09:12:21 -04:00
import %workspace%/bazel/bazelrc/ci.bazelrc
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
if : inputs.useCache == 'true' || inputs.useCache == 'readonly'
2023-10-04 07:55:38 -04:00
shell : bash
2023-03-20 11:05:08 -04:00
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-08-18 09:12:21 -04:00
cquery --bes_results_url=
cquery --bes_backend=
cquery --remote_cache=
query --bes_results_url=
query --bes_backend=
query --remote_cache=
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)
2023-06-23 06:12:32 -04:00
if : inputs.useCache == 'readonly'
2023-10-04 07:55:38 -04:00
shell : bash
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)
if : inputs.useCache == 'logs'
2023-10-04 07:55:38 -04:00
shell : bash
2023-06-23 06:12:32 -04:00
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-08-18 09:12:21 -04:00
cquery --bes_results_url=
cquery --bes_backend=
query --bes_results_url=
query --bes_backend=
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
2023-10-04 07:55:38 -04:00
if : startsWith(runner.name , 'GitHub Actions')
2023-06-09 10:59:19 -04:00
shell : bash
env :
WORKSPACE : ${{ github.workspace }}
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::"