-
-
Notifications
You must be signed in to change notification settings - Fork 168
Portability additions #11
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
Merged
brikis98
merged 23 commits into
gruntwork-io:master
from
housni:feature/portability-additions
Nov 28, 2018
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
bd0ec4e
Changed shebang to be more portable.
housni 4453b38
Made scripts shellcheck compatible
housni 717a3d9
Updated docs to match previous commits
housni 999bd45
Added back note about `readonly` variables.
brikis98 0f9ec24
'list' should also be an array
housni 871d7a7
Merge branch 'feature/portability-additions' of github-housni.com:hou…
housni 12e1f23
Moved docker-compose.yml to root and removed unused Dockerfile
housni 4d90070
Changed shebang to be more portable.
housni 4751c7a
Integrated shellcheck into CI.
housni 9d391b4
Shellcheck runs from root so source paths should be relative to root.
housni a7e9f4b
Fixed mount path
housni 97ca6f9
Added bootstrap.sh along with docs for it
housni e097be8
Removing set -e since that option should be handled by bootstrap.sh
housni 21fe73a
Separated bats and shellcheck tests. Mounting to /usr/local/src/bash-…
housni 5cdb8bb
CircleCI now confirms to Docker Compose
housni 1c9d8d6
Better code and quoting variables
housni cf1efa8
Reverting previous change. Using @ here is valid in this context.
housni 855e325
Removed less eager splitting via IFS on the request of @brikis98
housni 29e7542
Grammar fix
housni 7053dc7
Using bootstrap.sh to set some options
housni a151c11
Using local Dockerfiles for all tests
housni 5e22924
Merge branch 'master' into feature/portability-additions
housni 108dd13
Remove reference to old image
brikis98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
shellcheck: | ||
machine: true | ||
steps: | ||
- checkout | ||
- run: docker-compose up shellcheck | ||
bats: | ||
# We need to run Docker Compose with privileged settings, which isn't supported by CircleCI's Docker executor, so | ||
# we have to use the machine executor instead. | ||
machine: true | ||
steps: | ||
- checkout | ||
- run: | | ||
cd test | ||
docker-compose up | ||
- run: docker-compose up bats | ||
workflows: | ||
version: 2 | ||
checks: | ||
jobs: | ||
- shellcheck | ||
- bats |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env bash | ||
|
||
# shellcheck source=./modules/bash-commons/src/os.sh | ||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../modules/bash-commons/src/bootstrap.sh" | ||
|
||
function run_shellcheck { | ||
local -r format="${1}" | ||
shift | ||
local -i exit_code | ||
local -a results | ||
|
||
shellcheck --version | ||
echo | ||
|
||
printf "Shellcheck is scanning some files (%s):\n" "$#" | ||
printf " %s\n" "$@" | ||
echo | ||
|
||
set +e | ||
IFS=$'\n' \ | ||
read -ra results <<< \ | ||
"$(shellcheck \ | ||
--exclude=SC1117 \ | ||
--external-sources \ | ||
--format="$format" \ | ||
"$@" 2>&1 | ||
)" | ||
exit_code=$? | ||
set -e | ||
|
||
case "$exit_code" in | ||
0) | ||
echo "All files successfully scanned with no issues" | ||
;; | ||
|
||
1) | ||
printf "All files successfully scanned with some issues (%s):\n" ${#results[@]} | ||
printf " %s\n" "${results[@]}" | ||
exit $exit_code | ||
;; | ||
|
||
2) | ||
printf "Some files could not be processed (%s):\n" ${#results[@]} | ||
printf " %s\n" "${results[@]}" | ||
exit $exit_code | ||
;; | ||
|
||
3) | ||
echo "ShellCheck was invoked with bad syntax:" | ||
printf " %s\n" "${results[@]}" | ||
exit $exit_code | ||
;; | ||
|
||
4) | ||
echo "ShellCheck was invoked with bad options:" | ||
printf " %s\n" "${results[@]}" | ||
exit $exit_code | ||
;; | ||
|
||
*) | ||
echo "Unrecognized exit code '$exit_code' returned from shellcheck" | ||
set -x | ||
exit 1 | ||
|
||
esac | ||
} | ||
|
||
# Runs shellcheck against shell scripts and displays results. | ||
# | ||
# format {1}: Shellcheck format options, either one of "tty", "gcc", "checkstyle" | ||
# or "json". Default is "gcc". | ||
# filename {2}: If not given, it will search for all files whose first line | ||
# begin with a shebang like "#!/usr/bin/env bash". | ||
# If given a string of space separated files, only those files | ||
# will be scanned. | ||
function main { | ||
local -a check_files | ||
local -r format="${1:-gcc}" | ||
local filename="${2:-}" | ||
local line | ||
|
||
# If `CIRCLE_WORKING_DIRECTORY` is not set, assume the project root dir. | ||
if [[ -z "${CIRCLE_WORKING_DIRECTORY:-}" ]]; then | ||
CIRCLE_WORKING_DIRECTORY="$( | ||
readlink -f \ | ||
"$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." | ||
)" | ||
fi | ||
|
||
if [[ -z "$filename" ]]; then | ||
# Since no filenames are provided, look for files based on shebang. | ||
while read -r filename; do | ||
set +e | ||
IFS= read -rd '' line < <(head -n 1 "$filename") | ||
set -e | ||
|
||
if [[ "$line" =~ ^#!/usr/bin/env\ +bash ]]; then | ||
check_files+=( "$filename" ) | ||
fi | ||
done < <(find "$CIRCLE_WORKING_DIRECTORY" -path ./.git -prune -o -type f -print) | ||
else | ||
check_files=( "$filename" ) | ||
fi | ||
|
||
run_shellcheck "$format" "${check_files[@]}" | ||
} | ||
|
||
main "$@" | ||
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FROM bash:3.2 | ||
|
||
# TODO: labels here. See: http://label-schema.org/rc1/ | ||
|
||
ARG SHELLCHECK_VERSION=stable | ||
ARG SHELLCHECK_FORMAT=gcc | ||
|
||
# Install dependencies. | ||
RUN set -e; \ | ||
apk --update add \ | ||
git \ | ||
outils-sha512 \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& rm /var/cache/apk/* | ||
|
||
# Install shellcheck. | ||
RUN set -e; \ | ||
mkdir -p ~/stage \ | ||
&& wget "https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" \ | ||
&& wget "https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz.sha512sum" \ | ||
&& sha512 -c shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz.sha512sum \ | ||
&& tar --xz -xvf shellcheck-"${SHELLCHECK_VERSION}".linux.x86_64.tar.xz \ | ||
&& cp shellcheck-"${SHELLCHECK_VERSION}"/shellcheck /usr/bin/ \ | ||
&& shellcheck --version \ | ||
&& rm -rf ~/stage | ||
|
||
WORKDIR /usr/local/src/bash-commons | ||
COPY ./.circleci/ /usr/local/src/bash-commons/.circleci/ | ||
|
||
CMD ["bash"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: '3' | ||
services: | ||
shellcheck: | ||
build: | ||
context: ./ | ||
dockerfile: Dockerfile.shellcheck | ||
volumes: | ||
- ./:/usr/local/src/bash-commons | ||
working_dir: /usr/local/src/bash-commons/.circleci | ||
command: ./shellcheck.sh | ||
bats: | ||
build: | ||
context: ./ | ||
dockerfile: Dockerfile.bats | ||
volumes: | ||
# Mount all the files so you have "hot reload" of all changes from the host | ||
- ./:/usr/local/src/bash-commons | ||
working_dir: /usr/local/src/bash-commons | ||
command: bats test | ||
# Necessary so we can run a mock EC2 metadata service on port 80 on a special IP | ||
privileged: true | ||
ports: | ||
# For moto | ||
- "5000:5000" | ||
# For ec2-metadata-mock | ||
- "8111:8111" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.