Skip to content

Commit

Permalink
chore: update for testing Bazel 7 as primary and Bazel 6 as secondary (
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored Feb 21, 2024
1 parent ca6324c commit 8344aa7
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 34 deletions.
48 changes: 29 additions & 19 deletions .github/workflows/bazel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on:
By default, we don't test non-linux with Bazel 6 to minimize macOS and Windows minutes
since they are billed at 10X and 2X respectively:
https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
Note: independent of this setting, we don't create MacOS/Windows matrix entries for pull requests
unless they come from a specially-named branch. See logic below.
type: string
Expand All @@ -37,6 +37,20 @@ on:
exclude_windows:
description: Don't run any tests on Windows
type: boolean
bazel_test_command:
default: "bazel test //..."
description: |
Bazel test command that may be overridden to set custom flags and targets.
The `--enable_bzlmod={true,false}`, `--disk_cache=~/.cache/bazel-disk-cache`,
and `--repository_cache=~/.cache/bazel-repository-cache` flags are
automatically appended to the command.
type: string
mount_bazel_caches:
default: true
description: |
Whether or not to mount the `~/.cache/bazel-disk-cache`, `~/.cache/bazel-repository-cache`,
and `~/.cache/xdg-cache-home` folders using the `actions/cache@v3` GitHub Action.
type: boolean

jobs:
# matrix-prep-* steps generate JSON used to create a dynamic actions matrix.
Expand Down Expand Up @@ -66,7 +80,7 @@ jobs:
# Prepares the 'bazelversion' axis of the test matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
# NB: we assume this is Bazel 7
- id: bazel_from_bazelversion
run: echo "bazelversion=$(head -n 1 .bazelversion)" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -115,11 +129,14 @@ jobs:
# cache.
- name: Mount bazel caches
uses: actions/cache@v3
if: ${{ inputs.mount_bazel_caches }}
with:
path: |
~/.cache/bazel
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
restore-keys: bazel-cache-
~/.cache/bazel-disk-cache
~/.cache/bazel-repository-cache
~/.cache/xdg-cache-home
key: bazel-cache-${{ matrix.os }}-${{ matrix.bazelversion }}-${{ matrix.folder }}-${{ matrix.bzlmodEnabled }}-${{ 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 }}-

- name: Configure Bazel version
working-directory: ${{ matrix.folder }}
Expand All @@ -133,31 +150,24 @@ jobs:
with:
files: "${{ matrix.folder }}/test.sh"

- name: Set bzlmod flag
# Store the --enable_bzlmod flag that we add to the test command below
# only when we're running bzlmod in our test matrix.
id: set_bzlmod_flag
if: matrix.bzlmodEnabled
run: echo "bzlmod_flag=--enable_bzlmod" >> $GITHUB_OUTPUT

# See https://github.com/bazel-contrib/publish-to-bcr#including-patches
- name: verify bcr patches
if: matrix.bzlmodEnabled && hashFiles('.bcr/patches/*.patch') != ''
run: patch --dry-run -p1 < .bcr/patches/*.patch

- name: bazel test //...
env:
# Bazelisk will download bazel to here.
XDG_CACHE_HOME: ~/.cache/bazel-repo
- name: Test
working-directory: ${{ matrix.folder }}
run: bazel --bazelrc=${{ github.workspace }}/.github/workflows/ci.bazelrc --bazelrc=.bazelrc test ${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} //...
run: ${{ inputs.bazel_test_command }} --enable_bzlmod=${{ matrix.bzlmodEnabled }} --disk_cache=~/.cache/bazel-disk-cache --repository_cache=~/.cache/bazel-repository-cache
env:
# Bazelisk will download bazel to here
XDG_CACHE_HOME: ~/.cache/xdg-cache-home

- name: ./test.sh
- name: Run ./test.sh
# Run if there is a test.sh file in the folder
# Don't run integration tests on Windows since they are bash scripts and Windows runs Powershell
if: steps.has_test_sh.outputs.files_exists == 'true' && ! startsWith(matrix.os, 'windows')
working-directory: ${{ matrix.folder }}
shell: bash
# Run the script potentially setting BZLMOD_FLAG=--enable_bzlmod. All test.sh
# scripts that run bazel directly should make use of this variable.
run: BZLMOD_FLAG=${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} ./test.sh
run: BZLMOD_FLAG=--enable_bzlmod=${{ matrix.bzlmodEnabled }} ./test.sh
63 changes: 48 additions & 15 deletions .github/workflows/release_ruleset.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Reusable workflow that can be referenced by repositories in their .github/workflows/release.yaml.
# Reusable workflow that can be referenced by repositories in their `.github/workflows/release.yaml`.
# See example usage in https://github.com/bazel-contrib/rules-template/blob/main/.github/workflows/release.yaml
#
# This assumes the repo calling the workflow has at least these files:
# - .github/workflows/release_prep.sh
# - .github/workflows/ci.bazelrc
# - .bazelrc
# By default this workflows calls `.github/workflows/release_prep.sh` as the command to prepare
# the release. This can be customized with the `release_prep_command` attribute. Release notes are
# expected to be outputted to stdout from the release prep command.
#
# This workflow automatically configures the disk_cache and repository_cache directories to
# `~/.cache/bazel-disk-cache` and `~/.cache/bazel-repo-cache` respectively. It also sets the XDG_CACHE_HOME
# env to `~/.cache/xdg-cache-home` which is used by bazelisk when downloading Bazel. GitHub Actions caching
# is configured for these directories. Caching may be disabled by setting `mount_bazel_caches` to false.

on:
# Make this workflow reusable, see
Expand All @@ -17,6 +21,24 @@ on:
Newline-delimited globs of paths to assets to upload for release.
See https://github.com/softprops/action-gh-release#inputs
type: string
release_prep_command:
default: .github/workflows/release_prep.sh
description: |
Command to run to prepare the release and generate release notes.
Release notes are expected to be outputted to stdout.
type: string
bazel_test_command:
default: "bazel test //..."
description: |
Bazel test command that may be overridden to set custom flags and targets.
The --disk_cache=~/.cache/bazel-disk-cache --repository_cache=~/.cache/bazel-repository-cache flags are
automatically appended to the command.
type: string
mount_bazel_caches:
default: true
description: |
Additional startup flags to pass to the 'bazel test //...' invocation
type: boolean
prerelease:
default: true
description: Indicator of whether or not is a prerelease
Expand All @@ -27,21 +49,32 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Mount bazel caches
uses: actions/cache@v3
if: ${{ inputs.mount_bazel_caches }}
with:
path: |
~/.cache/bazel
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
restore-keys: bazel-cache-
- name: bazel test //...
~/.cache/bazel-disk-cache
~/.cache/bazel-repository-cache
~/.cache/xdg-cache-home
key: bazel-cache-release-${{ hashFiles('.bazelrc', '.bazelversion', '.bazeliskrc', '**/BUILD', '**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel', 'WORKSPACE.bzlmod', 'MODULE.bazel', 'MODULE.bazel.lock') }}
restore-keys: bazel-cache-release-
- name: Test
run: ${{ inputs.bazel_test_command }} --disk_cache=~/.cache/bazel-disk-cache --repository_cache=~/.cache/bazel-repository-cache
env:
# Bazelisk will download bazel to here
XDG_CACHE_HOME: ~/.cache/xdg-cache-home
- name: Build release artifacts and prepare release notes
run: |
if [ ! -f "${{ inputs.release_prep_command }}" ]; then
echo "ERROR: create a ${{ inputs.release_prep_command }} release prep script or configure a different release prep command with the release_prep_command attribute"
exit 1
fi
${{ inputs.release_prep_command }} ${{ env.GITHUB_REF_NAME }} > release_notes.txt
env:
# Bazelisk will download bazel to here.
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test //...
- name: Prepare release notes and artifacts
run: .github/workflows/release_prep.sh ${{ env.GITHUB_REF_NAME }} > release_notes.txt
# Bazelisk will download bazel to here
XDG_CACHE_HOME: ~/.cache/xdg-cache-home
- name: Release
uses: softprops/action-gh-release@v1
with:
Expand Down
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See CONTRIBUTING.md for instructions.
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

# Run hooks on commit stage
default_stages: [commit]

# Use a slightly older version of node by default
# as the default uses a very new version of GLIBC
default_language_version:
node: 16.18.0

repos:
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.1.0"
hooks:
- id: prettier
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# How to Contribute

## Formatting

Files should be formatted with prettier.
We suggest using a pre-commit hook to automate this.
First [install pre-commit](https://pre-commit.com/#installation),
then run

```shell
pre-commit install
```

0 comments on commit 8344aa7

Please sign in to comment.