travis-ci / terraform-config

Terraform bits and bytes
MIT License
125 stars 41 forks source link

runtests not validating all bash scripts #185

Closed edmorley closed 7 years ago

edmorley commented 7 years ago

I was looking for prior art for the testing of Terraform configs, which led to me borrowing parts of the runtests script in this repo for mozilla-platform-ops/devservices-aws/pull/55.

However whilst working on that I noticed that the current implementation only searches for scripts with the shebang #!/usr/bin/env bash - and whilst that's the best practice shebang, it's not unknown for people to use #!/bin/bash, #!/usr/bin/bash or variants with sh instead of bash.

And in fact, there are scripts in this repo that use these alternative shebangs: https://github.com/travis-infrastructure/terraform-config/search?q="%2Fbin%2Fbash"

I'd recommend using this instead: git grep -El '^#!/.+\b(bash|sh)\b' (note the extended regex param)

Testing briefly against this repo using the new regex results in failures in the previously unchecked files - which I was going to open a PR to resolve, but some of the failures are due to variables set by Terraform that shellcheck can't see - so not sure how you'd want to handle that.

Note also that newer versions of shellcheck appears to find more issues in the rest of the repo too (initially I was testing locally with a newer version than that used in the current Travis run) - might be worth updating at some point.

edmorley commented 7 years ago

Ah I forgot to paste an example failing job: https://travis-ci.org/edmorley/terraform-config/builds/251412172

edmorley commented 7 years ago

Note also that newer versions of shellcheck appears to find more issues in the rest of the repo too ... - might be worth updating at some point.

In case it saves anyone time in the future (since it confused me for a bit this morning for mozilla-platform-ops/devservices-aws#55)...

If switching from the custom built binaries in the travis-blue-public S3 bucket to the ones produced upstream (such as https://storage.googleapis.com/shellcheck/shellcheck-v0.4.6.linux.x86_64.tar.xz), make sure to add --strip-components=1 to the tar invocation, otherwise the shellcheck binary ends up in a subdirectory and so not on PATH, which is easy to miss since then the older preinstalled shellcheck binary in /usr/bin/local is silently used instead.

meatballhat commented 7 years ago

Resolved via #209