-
Notifications
You must be signed in to change notification settings - Fork 12
Add support for extended and recursive globs #42
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 support for extended and recursive globs #42
Conversation
Ensures that Bash version 4 is at least 4 before enabling it.
Also adds tests to validate that these options behave as expected.
Matching shell options against versions is good but since only two options are exposed through the plugin config, we only need to check for extglob and globstar.
|
Noticed that there's no CI wired up to this plugin (which is really funny in context), but the tests passed for me when I ran them locally: I'll try running these in a bit against my fork. |
|
Hey @mckern! This is really good! 🎉 We only noticed two things:
Thanks! |
|
@pzeballos can-do. I'll push up some commits after lunch. Thanks for taking a look.
|
Environment variables defined as boolean values in the spec will be cast to "1" or "0", so we should evaluate for value instead of just evaluating for presence. This also adds test cases, exercising what happens when each option is explicitly disable.
Previous fix was operating under a false assumption; after doing a little debugging, the Buildkite Agent expresses these values as the strings "true" or "false". Our test should take that into account. This is implied by json-schema.org's guidlines for boolean values but it is not made clear in the Buildkite plugin documentation.
It looks like the values of these options are passed through literally as environment variables with no casting whatsoever done. So we need to accommodate for "true" and "1" and case insensitivity when figuring out if shopts should be set. There's some test cases to flex the negative scenarios, as well as the positive.
|
@pzeballos test cases for enabled and disabled are updated and logic now accommodates the soft nature of booleans as expressed via Bash environment variables. Regarding resetting |
indeed, it was that. We'll review your update and let you know. Thanks for the quick turnaround @mckern! |
Co-authored-by: Pol <pzeballos@users.noreply.github.com>
Co-authored-by: Pol <pzeballos@users.noreply.github.com>
`extglob` was introduced in Bash 2, which had its last release in 2002. It's a pretty safe target, so we don't need a note about it.
Instead of testing against a version lookup, we can just try setting the shopt directly and handling the failure ourselves. It's a little more brute-force but it's also a little bit less dependent on internal Bash variables. The nature of shopts means we can't directly test them without overriding so much code that we're essentially using a function to exercise a test (not the other way around). But there's ample comments describing the important details, like "no major platform ships bash 3 except macOS".
Instead of directly exposing implementation details by using Bash shopts as config keys, use the nicer `extended_glob` and `recursive_glob` keys. Evaluating for the expected variables moves out into the main script body, and casting the variable values to boolean values is now its own function. Setting either value will also now emit an explicit message to stdout, underneath their own (de-emphasized) build-phase grouping. A test has been added to validate that expected behavior still applies when both options are enabled at the same time.
toote
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great... but we have fixed the tests in the master branch, which means your tests are now failing (the same way they should have been failing before).
I tried making the change myself but I didn't have permissions to do so. After the mergeback from this is the diff:
diff --git a/tests/run.bats b/tests/run.bats
index cabec31..c1fdad6 100644
--- a/tests/run.bats
+++ b/tests/run.bats
@@ -43,7 +43,7 @@ load '/usr/local/lib/bats/load.bash'
export BUILDKITE_PLUGIN_SHELLCHECK_FILES="**/*.sh"
stub docker \
- "run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck:stable --color=always \"tests/testdata/recursive/subdir/stub.sh tests/testdata/test.sh tests/testdata/subdir/llamas.sh tests/testdata/subdir/shell with space.sh\"' : echo testing stub.sh test.sh llamas.sh shell with space.sh"
+ "run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck:stable --color=always tests/testdata/recursive/subdir/stub.sh tests/testdata/subdir/llamas.sh tests/testdata/subdir/shell\ with\ a\ space.sh tests/testdata/test.sh : echo testing stub.sh test.sh llamas.sh shell with space.sh"
run "$PWD/hooks/command"
@@ -59,7 +59,7 @@ load '/usr/local/lib/bats/load.bash'
export BUILDKITE_PLUGIN_SHELLCHECK_FILES="tests/testdata/subdir/*.+(sh|bash)"
stub docker \
- "run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck:stable --color=always \"tests/testdata/subdir/llamas.sh tests/testdata/subdir/shell with space.sh tests/testdata/subdir/stub.bash\"' : echo testing llamas.sh shell with space.sh stub.bash"
+ "run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck:stable --color=always tests/testdata/subdir/llamas.sh tests/testdata/subdir/shell\ with\ a\ space.sh tests/testdata/subdir/stub.bash : echo testing llamas.sh shell with space.sh stub.bash"
run "$PWD/hooks/command"
@@ -106,7 +106,7 @@ load '/usr/local/lib/bats/load.bash'
export BUILDKITE_PLUGIN_SHELLCHECK_FILES="**/*.+(sh|bash)"
stub docker \
- "run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck:stable --color=always \"tests/testdata/recursive/subdir/stub.bash tests/testdata/subdir/stub.bash tests/testdata/recursive/subdir/stub.sh tests/testdata/test.sh tests/testdata/subdir/llamas.sh tests/testdata/subdir/shell with space.sh\"' : echo testing stub.sh test.sh llamas.sh shell with space.sh"
+ "run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck:stable --color=always tests/testdata/recursive/subdir/stub.bash tests/testdata/recursive/subdir/stub.sh tests/testdata/subdir/llamas.sh tests/testdata/subdir/shell\ with\ a\ space.sh tests/testdata/subdir/stub.bash tests/testdata/test.sh : echo testing stub.sh test.sh llamas.sh shell with space.sh"
run "$PWD/hooks/command"
Actually, it is wired, but turned off for third-party forks |
Co-authored-by: Matías A. Bellone <matias.bellone@builkite.com>
|
@toote thanks for the heads up; I applied your diff and committed it with you as co-author. |
toote
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worked like a charm :)
pzeballos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contributions and bearing with us! 🙏🏻
Ran into #35, and recursion would be extremely useful for my org. So I've added it.
I figure that
extglobandglobstarare pretty safe shopts since Bash 4 came out in 2009, but I've left some "safety valves" to ensure that we don't try to set those options against Bash 3 if we run into it.Oh, I also ran
shfmtandshellcheckagainst my work, so if there's little bits of whitespace drift those were introduced by tooling and they're safe.