2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-11-26 13:30:30 +00:00
bazel-lib/.github/workflows/ci.yaml

178 lines
8 KiB
YAML
Raw Permalink Normal View History

2021-11-08 14:20:26 +00:00
name: CI
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main, 1.x]
pull_request:
branches: [main, 1.x]
2021-11-08 14:20:26 +00:00
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
concurrency:
# Cancel previous actions from the same PR or branch except 'main' branch.
# See https://docs.github.com/en/actions/using-jobs/using-concurrency and https://docs.github.com/en/actions/learn-github-actions/contexts for more info.
group: concurrency-group::${{ github.workflow }}::${{ github.event.pull_request.number > 0 && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}${{ github.ref_name == 'main' && format('::{0}', github.run_id) || ''}}
cancel-in-progress: ${{ github.ref_name != 'main' }}
2021-11-08 14:20:26 +00:00
jobs:
# matrix-prep-* steps dynamically generate a bit of JSON depending on whether our action has
# access to repository secrets. When running on a pull_request from a fork, the author is
# untrusted so the secret will be absent. Insanely complex for how simple this requirement is...
# inspired from
# https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional
matrix-prep-config:
# Prepares the 'config' axis of the test matrix
runs-on: ubuntu-latest
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
steps:
- id: local
run: echo "config=local" >> $GITHUB_OUTPUT
- id: rbe
run: echo "config=rbe" >> $GITHUB_OUTPUT
# Don't run RBE if there is no API key which is the case on forks
if: ${{ env.BUILDBUDDY_API_KEY != '' }}
outputs:
# Will look like '["local", "rbe"]'
configs: ${{ toJSON(steps.*.outputs.config) }}
matrix-prep-bazelversion:
# Prepares the 'bazelversion' axis of the test matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: bazel_7
2024-05-14 01:00:26 +00:00
run: echo "bazelversion=$(head -n 1 .bazelversion)" >> $GITHUB_OUTPUT
- id: bazel_6
run: echo "bazelversion=6.5.0" >> $GITHUB_OUTPUT
outputs:
2024-05-14 01:00:26 +00:00
# Will look like '["<version from .bazelversion>", ...]'
bazelversions: ${{ toJSON(steps.*.outputs.bazelversion) }}
matrix-prep-os:
# Prepares the 'os' axis of the test matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: linux
run: echo "os=ubuntu-latest" >> $GITHUB_OUTPUT
- id: macos
run: echo "os=macos-latest" >> $GITHUB_OUTPUT
# Only run on main branch (or PR branches that contain 'macos') to minimize macOS minutes (billed at 10X)
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
2023-09-25 20:13:49 +00:00
if: ${{ github.ref == 'refs/heads/main' || contains(github.head_ref, 'macos') }}
- id: windows
run: echo "os=windows-latest" >> $GITHUB_OUTPUT
# Only run on main branch (or PR branches that contain 'windows') to minimize Windows minutes (billed at 2X)
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
if: ${{ github.ref == 'refs/heads/main' || contains(github.head_ref, 'windows') }}
outputs:
# Will look like ["ubuntu-latest", "macos-latest", "windows-latest"]
os: ${{ toJSON(steps.*.outputs.os) }}
2021-11-08 14:20:26 +00:00
test:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}
needs:
- matrix-prep-config
- matrix-prep-bazelversion
- matrix-prep-os
2021-11-08 14:20:26 +00:00
strategy:
fail-fast: false
matrix:
config: ${{ fromJSON(needs.matrix-prep-config.outputs.configs) }}
bazelversion: ${{ fromJSON(needs.matrix-prep-bazelversion.outputs.bazelversions) }}
os: ${{ fromJSON(needs.matrix-prep-os.outputs.os) }}
2024-05-14 01:00:26 +00:00
bzlmod: [1, 0]
folder:
- "."
- "e2e/copy_action"
- "e2e/copy_to_directory"
- "e2e/coreutils"
- "e2e/external_copy_to_directory"
2023-03-10 17:37:57 +00:00
- "e2e/smoke"
- "e2e/write_source_files"
exclude:
# Don't test MacOS with RBE to minimize MacOS minutes (billed at 10X)
- config: rbe
os: macos-latest
# Don't test MacOS with Bazel 7 to minimize MacOS minutes (billed at 10X)
2024-01-08 00:12:05 +00:00
- bazelversion: 7.0.0
os: macos-latest
# Don't test Windows with RBE to minimize Windows minutes (billed at 2X)
- config: rbe
os: windows-latest
2023-06-14 01:36:53 +00:00
# Don't test Windows with Bazel 7 to minimize Windows minutes (billed at 2X)
2024-01-08 00:12:05 +00:00
- bazelversion: 7.0.0
2023-06-14 01:36:53 +00:00
os: windows-latest
2021-11-08 14:20:26 +00:00
steps:
- uses: actions/checkout@v4
2022-01-21 16:48:43 +00:00
- name: Mount bazel caches
uses: actions/cache@v4
2021-11-08 14:20:26 +00:00
with:
2022-01-21 16:48:43 +00:00
path: |
2022-08-04 00:05:22 +00:00
~/.cache/bazel
~/.cache/bazel-repo
2024-01-08 00:12:05 +00:00
key: bazel-cache-${{ matrix.os }}-${{ matrix.bazelversion }}-${{ matrix.folder }}-${{ matrix.bzlmodEnabled }}-${{ matrix.config }}-${{ hashFiles('.bazelrc', '.bazelversion', '.bazeliskrc', '**/BUILD', '**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel', 'WORKSPACE.bzlmod', 'MODULE.bazel', 'MODULE.bazel.lock') }}
restore-keys: bazel-cache-${{ matrix.os }}-${{ matrix.bazelversion }}-${{ matrix.folder }}-${{ matrix.bzlmodEnabled }}-${{ matrix.config }}-
- name: Configure Bazel version
working-directory: ${{ matrix.folder }}
2024-05-14 01:00:26 +00:00
shell: bash
run: |
2024-05-14 01:00:26 +00:00
# Overwrite the .bazelversion instead of using USE_BAZEL_VERSION so that Bazelisk
# still bootstraps Aspect CLI from configuration in .bazeliskrc. Aspect CLI will
# then use .bazelversion to determine which Bazel version to use.
echo "${{ matrix.bazelversion }}" > .bazelversion
2024-05-14 01:00:26 +00:00
# Delete all the version specific bazelrc files that are used for local development
# since the version we're testing against is dynamic. These are just symlinks and the
# root .bazelrc brings these in with try-imports. In this CI workflows, we explicitly
# bring in the version specific bazelrc file with --bazelrc when we invoke bazel.
rm ${GITHUB_WORKSPACE//\\/\/}/.aspect/bazelrc/local/*.bazelrc
- name: Write rbe credentials
if: ${{ matrix.config == 'rbe' }}
working-directory: ${{ matrix.folder }}
run: |
touch $HOME/.bazelrc
chmod 0600 $HOME/.bazelrc
echo "build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" > $HOME/.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
2021-11-08 14:20:26 +00:00
- name: bazel test //...
working-directory: ${{ matrix.folder }}
2024-05-14 01:00:26 +00:00
shell: bash
run: |
BAZEL_VERSION=${{ matrix.bazelversion }}
2024-05-14 01:00:26 +00:00
bazel \
--bazelrc=${GITHUB_WORKSPACE//\\/\/}/.aspect/bazelrc/bazel${BAZEL_VERSION::1}.bazelrc \
--bazelrc=${GITHUB_WORKSPACE//\\/\/}/.aspect/bazelrc/ci.bazelrc \
--bazelrc=${GITHUB_WORKSPACE//\\/\/}/.github/workflows/ci.bazelrc \
test \
--config=${{ matrix.config }} \
--test_tag_filters=-skip-on-bazel${BAZEL_VERSION::1} \
--build_tag_filters=-skip-on-bazel${BAZEL_VERSION::1} \
--enable_bzlmod=${{ matrix.bzlmod }} \
//...
env:
2024-05-14 01:00:26 +00:00
XDG_CACHE_HOME: ~/.cache/xdg-cache # bazelisk will download bazel to here
- name: integration tests
# Don't run integration tests on Windows since they are bash scripts and Windows runs Powershell
2024-05-14 01:00:26 +00:00
if: matrix.folder == '.' && matrix.os != 'windows-latest'
# Find all shell scripts within e2e, echo the filename, execute, fail on error
run: find e2e/*.sh -maxdepth 1 -type f -exec sh -c 'echo "\n\n------------------------------- $0 -------------------------------" && BZLMOD_FLAG=${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} "$0" || kill $PPID' \{\} \;
- name: verify bcr patches
2024-05-14 01:00:26 +00:00
if: matrix.bzlmod == 1 && matrix.os == 'ubuntu-latest'
run: patch --dry-run -p1 < .bcr/patches/*.patch