Skip to content

Commit

Permalink
Allow passing build options to Bazel.
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjayVas committed Mar 10, 2021
1 parent bd14169 commit 070005d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/test-bazel-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,25 @@ jobs:
- name: Build and test
uses: ./bazel-build-test
with:
workspace-path: .
workspace-path: .
build-options:
name: Run with build options
runs-on: ubuntu-20.04
steps:
- name: Check out revision
uses: actions/checkout@v2

- name: Init Bazel workspace
run: |
echo 'workspace(name = "dummy_workspace")' > WORKSPACE
echo 'true' > test.sh
chmod u+x test.sh
echo 'sh_test(name = "passing_test", srcs = ["test.sh"])' > BUILD.bazel
- name: Build and test
uses: ./bazel-build-test
with:
workspace-path: .
build-options: |
--show_result=1024
--test_summary=detailed
1 change: 1 addition & 0 deletions .lintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
7 changes: 7 additions & 0 deletions bazel-build-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ inputs:
description: Path of Bazel workspace
required: true
default: .
build-options:
# TODO(actions/toolkit#184): Use list type rather than newline-delimited
# string once it's available.
description: >-
Options to pass to the Bazel build and test commands. Newline-delimited.
required: false
default: ''
runs:
using: node12
main: index.js
Expand Down
15 changes: 9 additions & 6 deletions bazel-build-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ async function run() {
const cachePaths = [outputBase];
await cache.restoreCache(cachePaths, cacheKey, restoreKeys);

const buildOptions = ['--keep_going'].concat(
core.getInput('build-options').split('\n').filter(value => value !== ''));
const testOptions = ['--test_output=errors'].concat(buildOptions);

await exec.exec(
'bazelisk', ['build', '--keep_going', '//...'], {cwd: workspacePath});
'bazelisk', ['build'].concat(buildOptions).concat(['//...']),
{cwd: workspacePath});
const testExitCode = await exec.exec(
'bazelisk', ['test', '--keep_going', '--test_output=errors', '//...'],
'bazelisk', ['test'].concat(testOptions).concat(['//...']),
{cwd: workspacePath, ignoreReturnCode: true});
if (!validTestExitCodes.includes(testExitCode)) {
throw new Error('Testing failed');
Expand All @@ -57,12 +62,10 @@ async function run() {
}
}

async function main() {
(async function() {
try {
await run();
} catch (err) {
core.setFailed(err);
}
}

main();
}());

0 comments on commit 070005d

Please sign in to comment.