From 3a68bda91027adb7f34b29d26115f4be8d691593 Mon Sep 17 00:00:00 2001 From: Red Daly Date: Sun, 19 Mar 2023 09:25:29 -0700 Subject: [PATCH 1/2] Add github action to run bazel build //generator/... --- .github/workflows/ci.bazelrc | 13 +++++ .github/workflows/ci.yaml | 96 ++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 .github/workflows/ci.bazelrc create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.bazelrc b/.github/workflows/ci.bazelrc new file mode 100644 index 0000000..a21ece4 --- /dev/null +++ b/.github/workflows/ci.bazelrc @@ -0,0 +1,13 @@ +# This file contains Bazel settings to apply on CI only. +# It is referenced with a --bazelrc option in the call to bazel in ci.yaml + +# Debug where options came from +build --announce_rc +# This directory is configured in GitHub actions to be persisted between runs. +build --disk_cache=~/.cache/bazel +build --repository_cache=~/.cache/bazel-repo +# Don't rely on test logs being easily accessible from the test runner, +# though it makes the log noisier. +test --test_output=errors +# Allows tests to run bazelisk-in-bazel, since this is the cache folder used +test --test_env=XDG_CACHE_HOME diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..1c0988d --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,96 @@ +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, es6] + pull_request: + branches: [main, es6] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +concurrency: + # Cancel previous actions from the same PR: https://stackoverflow.com/a/72408109 + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + # matrix-prep-* steps generate JSON used to create a dynamic actions matrix. + # 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-bazelversion: + # Prepares the 'bazelversion' axis of the test matrix + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - id: bazel_from_bazelversion + run: echo "bazelversion=$(head -n 1 .bazelversion)" >> $GITHUB_OUTPUT + # bazel 5 testing disabled for now due to + # https://github.com/aspect-build/bazel-lib/issues/392 + # - id: bazel_5 + # run: echo "bazelversion=5.3.2" >> $GITHUB_OUTPUT + outputs: + # Will look like [""] + bazelversions: ${{ toJSON(steps.*.outputs.bazelversion) }} + + test: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + needs: + - matrix-prep-bazelversion + + # Run bazel test in each workspace with each version of Bazel supported + strategy: + fail-fast: false + matrix: + bazelversion: ${{ fromJSON(needs.matrix-prep-bazelversion.outputs.bazelversions) }} + folder: + - "." + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + # Cache build and external artifacts so that the next ci build is incremental. + # Because github action caches cannot be updated after a build, we need to + # store the contents of each build in a unique cache key, then fall back to loading + # it on the next ci run. We use hashFiles(...) in the key and restore-keys- with + # the prefix to load the most recent cache for the branch on a cache miss. You + # should customize the contents of hashFiles to capture any bazel input sources, + # although this doesn't need to be perfect. If none of the input sources change + # then a cache hit will load an existing cache and bazel won't have to do any work. + # In the case of a cache miss, you want the fallback cache to contain most of the + # previously built artifacts to minimize build time. The more precise you are with + # hashFiles sources the less work bazel will have to do. + - name: Mount bazel caches + uses: actions/cache@v3 + with: + path: | + ~/.cache/bazel + ~/.cache/bazel-repo + key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }} + restore-keys: bazel-cache- + + - name: Configure Bazel version + working-directory: ${{ matrix.folder }} + run: echo "${{ matrix.bazelversion }}" > .bazelversion + + - name: Check for test.sh + # Checks for the existence of test.sh in the folder. Downstream steps can use + # steps.has_test_sh.outputs.files_exists as a conditional. + id: has_test_sh + uses: andstor/file-existence-action@v1 + with: + files: '${{ matrix.folder }}/test.sh' + + - name: bazel build //generator/... + env: + # Bazelisk will download bazel to here, ensure it is cached between runs. + XDG_CACHE_HOME: ~/.cache/bazel-repo + working-directory: ${{ matrix.folder }} + run: bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc --bazelrc=.bazelrc build //generator/... From c9cced1ba2521a82987059f744fac2f14d91b7a5 Mon Sep 17 00:00:00 2001 From: Red Daly Date: Sun, 19 Mar 2023 09:32:53 -0700 Subject: [PATCH 2/2] Update Github CI build. --- .github/workflows/ci.yaml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1c0988d..2cce537 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -36,7 +36,7 @@ jobs: # Will look like [""] bazelversions: ${{ toJSON(steps.*.outputs.bazelversion) }} - test: + bazel-build: # The type of runner that the job will run on runs-on: ubuntu-latest @@ -80,17 +80,9 @@ jobs: working-directory: ${{ matrix.folder }} run: echo "${{ matrix.bazelversion }}" > .bazelversion - - name: Check for test.sh - # Checks for the existence of test.sh in the folder. Downstream steps can use - # steps.has_test_sh.outputs.files_exists as a conditional. - id: has_test_sh - uses: andstor/file-existence-action@v1 - with: - files: '${{ matrix.folder }}/test.sh' - - name: bazel build //generator/... env: # Bazelisk will download bazel to here, ensure it is cached between runs. XDG_CACHE_HOME: ~/.cache/bazel-repo working-directory: ${{ matrix.folder }} - run: bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc --bazelrc=.bazelrc build //generator/... + run: bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc --bazelrc=.github/workflows/ci.bazelrc build //generator/...