Skip to content

Commit

Permalink
Add target-patterns to bazel-built-test action. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjayVas committed Mar 11, 2021
1 parent 6b13049 commit f3883ad
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
29 changes: 28 additions & 1 deletion .github/workflows/test-bazel-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,31 @@ jobs:
workspace-path: .
build-options: |
--show_result=1024
--test_summary=detailed
--test_summary=detailed
target-patterns:
name: Run with target pattern
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_1.sh
echo 'true' > test_2.sh
echo 'false' > test_to_ignore.sh
chmod u+x test_1.sh
chmod u+x test_2.sh
chmod u+x test_to_ignore.sh
echo 'sh_test(name = "passing_test_1", srcs = ["test_1.sh"])' > BUILD.bazel
echo 'sh_test(name = "passing_test_2", srcs = ["test_2.sh"])' >> BUILD.bazel
echo 'sh_test(name = "test_to_ignore", srcs = ["test_to_ignore.sh"])' >> BUILD.bazel
- name: Build and test
uses: ./bazel-build-test
with:
workspace-path: .
target-patterns: |
passing_test_1
passing_test_2
4 changes: 4 additions & 0 deletions bazel-build-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ inputs:
Whether to restore any previously saved Bazel workspace cache. Boolean.
required: false
default: true
target-patterns:
description: Bazel targets to build and test. Newline-delimited.
required: false
default: '//...'
runs:
using: node12
main: index.js
Expand Down
22 changes: 13 additions & 9 deletions bazel-build-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,28 @@ async function run() {
const buildOptions = ['--keep_going'].concat(
core.getInput('build-options').split('\n').filter(value => value !== ''));
const testOptions = ['--test_output=errors'].concat(buildOptions);
const targetPatterns =
core.getInput('target-patterns').split('\n').filter(value => value !== '');

await exec.exec(
'bazelisk', ['build'].concat(buildOptions).concat(['//...']),
'bazelisk', ['build'].concat(buildOptions).concat(targetPatterns),
{cwd: workspacePath});
const testExitCode = await exec.exec(
'bazelisk', ['test'].concat(testOptions).concat(['//...']),
'bazelisk', ['test'].concat(testOptions).concat(targetPatterns),
{cwd: workspacePath, ignoreReturnCode: true});
if (!validTestExitCodes.includes(testExitCode)) {
throw new Error('Testing failed');
}

try {
await cache.saveCache(cachePaths, cacheKey);
} catch (err) {
if (err.name === cache.ReserveCacheError.name) {
core.warning(err);
} else {
throw err;
if (targetPatterns.includes("//...")) {
try {
await cache.saveCache(cachePaths, cacheKey);
} catch (err) {
if (err.name === cache.ReserveCacheError.name) {
core.warning(err);
} else {
throw err;
}
}
}
}
Expand Down

0 comments on commit f3883ad

Please sign in to comment.