Skip to content

Commit 3a68bda

Browse files
committed
Add github action to run bazel build //generator/...
1 parent 885b9cd commit 3a68bda

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

.github/workflows/ci.bazelrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file contains Bazel settings to apply on CI only.
2+
# It is referenced with a --bazelrc option in the call to bazel in ci.yaml
3+
4+
# Debug where options came from
5+
build --announce_rc
6+
# This directory is configured in GitHub actions to be persisted between runs.
7+
build --disk_cache=~/.cache/bazel
8+
build --repository_cache=~/.cache/bazel-repo
9+
# Don't rely on test logs being easily accessible from the test runner,
10+
# though it makes the log noisier.
11+
test --test_output=errors
12+
# Allows tests to run bazelisk-in-bazel, since this is the cache folder used
13+
test --test_env=XDG_CACHE_HOME

.github/workflows/ci.yaml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: CI
2+
3+
# Controls when the action will run.
4+
on:
5+
# Triggers the workflow on push or pull request events but only for the main branch
6+
push:
7+
branches: [main, es6]
8+
pull_request:
9+
branches: [main, es6]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
concurrency:
15+
# Cancel previous actions from the same PR: https://stackoverflow.com/a/72408109
16+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
# matrix-prep-* steps generate JSON used to create a dynamic actions matrix.
21+
# Insanely complex for how simple this requirement is inspired from
22+
# https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional
23+
24+
matrix-prep-bazelversion:
25+
# Prepares the 'bazelversion' axis of the test matrix
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v3
29+
- id: bazel_from_bazelversion
30+
run: echo "bazelversion=$(head -n 1 .bazelversion)" >> $GITHUB_OUTPUT
31+
# bazel 5 testing disabled for now due to
32+
# https://github.com/aspect-build/bazel-lib/issues/392
33+
# - id: bazel_5
34+
# run: echo "bazelversion=5.3.2" >> $GITHUB_OUTPUT
35+
outputs:
36+
# Will look like ["<version from .bazelversion>"]
37+
bazelversions: ${{ toJSON(steps.*.outputs.bazelversion) }}
38+
39+
test:
40+
# The type of runner that the job will run on
41+
runs-on: ubuntu-latest
42+
43+
needs:
44+
- matrix-prep-bazelversion
45+
46+
# Run bazel test in each workspace with each version of Bazel supported
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
bazelversion: ${{ fromJSON(needs.matrix-prep-bazelversion.outputs.bazelversions) }}
51+
folder:
52+
- "."
53+
54+
# Steps represent a sequence of tasks that will be executed as part of the job
55+
steps:
56+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
57+
- uses: actions/checkout@v3
58+
59+
# Cache build and external artifacts so that the next ci build is incremental.
60+
# Because github action caches cannot be updated after a build, we need to
61+
# store the contents of each build in a unique cache key, then fall back to loading
62+
# it on the next ci run. We use hashFiles(...) in the key and restore-keys- with
63+
# the prefix to load the most recent cache for the branch on a cache miss. You
64+
# should customize the contents of hashFiles to capture any bazel input sources,
65+
# although this doesn't need to be perfect. If none of the input sources change
66+
# then a cache hit will load an existing cache and bazel won't have to do any work.
67+
# In the case of a cache miss, you want the fallback cache to contain most of the
68+
# previously built artifacts to minimize build time. The more precise you are with
69+
# hashFiles sources the less work bazel will have to do.
70+
- name: Mount bazel caches
71+
uses: actions/cache@v3
72+
with:
73+
path: |
74+
~/.cache/bazel
75+
~/.cache/bazel-repo
76+
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
77+
restore-keys: bazel-cache-
78+
79+
- name: Configure Bazel version
80+
working-directory: ${{ matrix.folder }}
81+
run: echo "${{ matrix.bazelversion }}" > .bazelversion
82+
83+
- name: Check for test.sh
84+
# Checks for the existence of test.sh in the folder. Downstream steps can use
85+
# steps.has_test_sh.outputs.files_exists as a conditional.
86+
id: has_test_sh
87+
uses: andstor/file-existence-action@v1
88+
with:
89+
files: '${{ matrix.folder }}/test.sh'
90+
91+
- name: bazel build //generator/...
92+
env:
93+
# Bazelisk will download bazel to here, ensure it is cached between runs.
94+
XDG_CACHE_HOME: ~/.cache/bazel-repo
95+
working-directory: ${{ matrix.folder }}
96+
run: bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc --bazelrc=.bazelrc build //generator/...

0 commit comments

Comments
 (0)