|
| 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 | + bazel-build: |
| 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: bazel build //generator/... |
| 84 | + env: |
| 85 | + # Bazelisk will download bazel to here, ensure it is cached between runs. |
| 86 | + XDG_CACHE_HOME: ~/.cache/bazel-repo |
| 87 | + working-directory: ${{ matrix.folder }} |
| 88 | + run: bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc --bazelrc=.github/workflows/ci.bazelrc build //generator/... |
0 commit comments