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

Add CI #1

Merged
merged 4 commits into from
Feb 18, 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
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ build --sandbox_default_allow_network=false
# Docs: https://bazel.build/reference/command-line-reference#flag--host_jvm_args
startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1

# Enable runfiles symlink tree for rules_jest.
# Docs: https://bazel.build/reference/command-line-reference#flag--enable_runfiles
build --enable_runfiles

# This bazelrc file can be used for user-specific custom build settings.
try-import %workspace%/.user.bazelrc
25 changes: 25 additions & 0 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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

# Announce all announces command options read from the bazelrc file(s) when starting up at the
# beginning of each Bazel invocation. This is very useful on CI to be able to inspect what Bazel rc
# settings are being applied on each run.
# Docs: https://bazel.build/docs/user-manual#announce-rc
build --announce_rc

# Directories caches by GitHub actions
common:local --disk_cache=~/.cache/bazel-disk-cache
common --repository_cache=~/.cache/bazel-repository-cache

# Output test errors to stderr so users don't have to `cat` or open test failure log files when test
# fail. This makes the log noiser in exchange for reducing the time-to-feedback on test failures for
# users.
# Docs: https://bazel.build/docs/user-manual#test-output
test --test_output=errors

# Bazel-in-bazel support
test --test_env=XDG_CACHE_HOME

# Use colors to highlight output on the screen. Set to `no` if your CI does not display colors.
# Docs: https://bazel.build/docs/user-manual#color
build --color=yes
65 changes: 65 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

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:
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'windows-latest', 'macos-latest']

steps:
- 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@v4
with:
path: |
~/.cache/bazel-disk-cache
~/.cache/bazel-repository-cache
~/.cache/xdg-cache
key: >-
bazel-cache-${{ matrix.os }}-
${{ hashFiles('.bazelrc', '.bazelversion', '**/BUILD', '**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel', 'WORKSPACE.bzlmod', 'MODULE.bazel', 'MODULE.bazel.lock') }}
restore-keys: |
bazel-cache-${{ matrix.os }}-

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

- name: bazel test //...
run: bazel --bazelrc=.github/workflows/ci.bazelrc test //...
env:
ASPECT_RULES_JS_FROZEN_PNPM_LOCK: 1
# bazelisk will download bazel to here
XDG_CACHE_HOME: ~/.cache/xdg-cache
4 changes: 4 additions & 0 deletions examples/calculator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ cc_library(

jest_test(
name = "calculator_test",
args = [
"--runTestsByPath",
"%s/calculator.test.js" % package_name(),
],
data = [
":bindings",
":calculator.test.js",
Expand Down
4 changes: 4 additions & 0 deletions examples/hello_world/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ node_extension(

jest_test(
name = "hello_world_test",
args = [
"--runTestsByPath",
"%s/hello_world.test.js" % package_name(),
],
data = [
":hello_world",
":hello_world.test.js",
Expand Down