From 070005db730d752bf9f302ac4244e29434971415 Mon Sep 17 00:00:00 2001 From: Sanjay Vasandani Date: Tue, 9 Mar 2021 17:06:35 -0800 Subject: [PATCH] Allow passing build options to Bazel. --- .github/workflows/test-bazel-build-test.yml | 23 ++++++++++++++++++++- .lintignore | 1 + bazel-build-test/action.yml | 7 +++++++ bazel-build-test/index.js | 15 ++++++++------ 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 .lintignore diff --git a/.github/workflows/test-bazel-build-test.yml b/.github/workflows/test-bazel-build-test.yml index d813732..98c9280 100644 --- a/.github/workflows/test-bazel-build-test.yml +++ b/.github/workflows/test-bazel-build-test.yml @@ -72,4 +72,25 @@ jobs: - name: Build and test uses: ./bazel-build-test with: - workspace-path: . \ No newline at end of file + 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 \ No newline at end of file diff --git a/.lintignore b/.lintignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.lintignore @@ -0,0 +1 @@ +node_modules/ diff --git a/bazel-build-test/action.yml b/bazel-build-test/action.yml index f69ab40..0f017c3 100644 --- a/bazel-build-test/action.yml +++ b/bazel-build-test/action.yml @@ -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 diff --git a/bazel-build-test/index.js b/bazel-build-test/index.js index 2f29c20..088f537 100644 --- a/bazel-build-test/index.js +++ b/bazel-build-test/index.js @@ -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'); @@ -57,12 +62,10 @@ async function run() { } } -async function main() { +(async function() { try { await run(); } catch (err) { core.setFailed(err); } -} - -main(); +}());