-
Notifications
You must be signed in to change notification settings - Fork 38
Add support for configuration files. #19
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
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5f38074
Let 'append_hash' be set by an environment variable.
ebae8a2
Revert "Let 'append_hash' be set by an environment variable."
676d33f
Let 'append_hash' be set by an environment variable.
3994857
Move '--config-file' out of the args-parsing loop.
44a35e8
Move args-parsing to its own file.
cd03b06
Add tests for environment variables.
68a726c
Add tests for '.env' files.
a1e762a
Replace swath of redundant tests with working arg-parse test.
ca7cac1
Merge branch 'master' into feature/env-files
f1b23e1
Add docs about '-c' requiring it be first arg.
dae280a
Remove superfluous config bits from arg-parsing tests.
b750ac3
Add test for '--message' with spaces in it.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env bats | ||
|
||
source lib/assert.bash | ||
source deploy.sh --source-only | ||
|
||
setup() { | ||
run mktemp -dt deploy_test.XXXX | ||
assert_success | ||
tmp=$output | ||
pushd "$tmp" >/dev/null | ||
} | ||
|
||
teardown() { | ||
popd >/dev/null | ||
rm -rf "$tmp" | ||
} | ||
|
||
set_env_vars() { | ||
# Set environment variables. | ||
export GIT_DEPLOY_USERNAME=env-username | ||
export GIT_DEPLOY_EMAIL=env-email | ||
export GIT_DEPLOY_APPEND_HASH=env-var | ||
} | ||
|
||
write_env_file() { | ||
# Write a '.env' file to override environment variables. | ||
cat <<-EOF > .env | ||
GIT_DEPLOY_EMAIL=dotenv-email | ||
GIT_DEPLOY_APPEND_HASH=env-file | ||
EOF | ||
} | ||
|
||
write_conf_file() { | ||
# Write a config-file to override '.env'. | ||
cat <<-EOF > conf | ||
GIT_DEPLOY_EMAIL=conf-email | ||
GIT_DEPLOY_APPEND_HASH=conf-file | ||
EOF | ||
} | ||
|
||
@test 'Arg-parsing defaults to in-script values.' { | ||
parse_args | ||
assert that "$append_hash" = "true" | ||
} | ||
|
||
@test ' overrides script defaults with environment variables.' { | ||
set_env_vars | ||
|
||
parse_args | ||
assert that "$append_hash" = "env-var" | ||
} | ||
|
||
@test ' overrides environment variables with .env file.' { | ||
set_env_vars | ||
write_env_file | ||
|
||
parse_args | ||
assert that "$append_hash" = "env-file" | ||
} | ||
|
||
@test ' overrides .env with a file specified on the command-line.' { | ||
set_env_vars | ||
write_env_file | ||
write_conf_file | ||
|
||
parse_args --config-file conf | ||
assert that "$append_hash" = "conf-file" | ||
} | ||
|
||
@test ' overrides everything with a command-line option.' { | ||
set_env_vars | ||
write_env_file | ||
write_conf_file | ||
|
||
parse_args --config-file conf --no-hash | ||
assert that "$append_hash" = "false" | ||
} | ||
|
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
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.
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.
did you have a plan for these email and username variables? Otherwise, looks great! I'll merge now.
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.
I have it in my head to set those things using
git config
info, but I haven't gotten to that yet.I was using them to help me figure out why my tests for
append_hash
were failing as well, and neglected to remove them when I got things working. No need to keep them in here, I guess. I'll just re-add them if/when I need them later.