Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use setup-bazel action #13

Merged
merged 7 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions .github/workflows/bazel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# This assumes the repo calling the workflow has at least these files:
# - .github/workflows/ci.bazelrc
# - .bazelrc
#
# This workflow uses https://github.com/p0deje/setup-bazel to prepare the cache folders.
# Caching may be disabled by setting `mount_bazel_caches` to false.

on:
# Make this workflow reusable, see
Expand Down Expand Up @@ -48,13 +51,12 @@ on:
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.
Whether to enable caching in the p0deje/setup-bazel action.
type: boolean

jobs:
# matrix-prep-* steps generate JSON used to create a dynamic actions matrix.
# Insanely complex for how simple this requirement is inspired from
# Inspired from
# https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional

matrix-prep-os:
Expand Down Expand Up @@ -113,30 +115,11 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

# Cache build 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.
# We do not cache downloaded external artifacts as these are generally
# faster to download again than to fetch them from the GitHub actions
# cache.
- name: Mount bazel caches
uses: actions/cache@v3
if: ${{ inputs.mount_bazel_caches }}
# TODO: change to bazel-contrib after it moves
- uses: p0deje/setup-bazel@0.6.0
with:
path: |
~/.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 }}-
repository-cache: ${{ inputs.mount_bazel_caches }}
bazelrc: common --announce_rc --color=yes --enable_bzlmod=${{ matrix.bzlmodEnabled }}

- name: Configure Bazel version
working-directory: ${{ matrix.folder }}
Expand All @@ -157,10 +140,7 @@ jobs:

- name: Test
working-directory: ${{ matrix.folder }}
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
run: ${{ inputs.bazel_test_command }}

- name: Run ./test.sh
# Run if there is a test.sh file in the folder
Expand Down
34 changes: 13 additions & 21 deletions .github/workflows/release_ruleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
# 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.
# This workflow uses https://github.com/p0deje/setup-bazel to prepare the cache folders.
# Caching may be disabled by setting `mount_bazel_caches` to false.

on:
# Make this workflow reusable, see
Expand Down Expand Up @@ -37,11 +35,11 @@ on:
mount_bazel_caches:
default: true
description: |
Additional startup flags to pass to the 'bazel test //...' invocation
Whether to enable caching in the p0deje/setup-bazel action.
type: boolean
prerelease:
default: true
description: Indicator of whether or not is a prerelease
description: Indicator of whether or not this is a prerelease.
type: boolean

jobs:
Expand All @@ -50,31 +48,25 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Mount bazel caches
uses: actions/cache@v3
if: ${{ inputs.mount_bazel_caches }}

# TODO: change to bazel-contrib after it moves
- uses: p0deje/setup-bazel@0.6.0
with:
path: |
~/.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-
disk-cache: ${{ inputs.mount_bazel_caches }}
external-cache: ${{ inputs.mount_bazel_caches }}
repository-cache: ${{ inputs.mount_bazel_caches }}

- 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/xdg-cache-home

- name: Release
uses: softprops/action-gh-release@v1
with:
Expand Down