Skip to content

Commit 205a851

Browse files
author
Matt Pearson
committed
Add support for configuration files.
1. If `.env` exists in the current path, it gets sourced. 2. If `-c $FILE` or `--config-file $FILE` is specified, `$FILE` gets sourced. Values set earlier get overriden by those set later. Fixes part of #14.
1 parent eab82b6 commit 205a851

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

deploy.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ main() {
1515
#append commit hash to the end of message by default
1616
append_hash=true
1717

18+
# Set args from a local env file
19+
if [ -e ".env" ]; then
20+
source .env
21+
fi
22+
1823
# Parse arg flags
1924
while : ; do
2025
if [[ $1 = "-v" || $1 = "--verbose" ]]; then
@@ -29,6 +34,9 @@ main() {
2934
elif [[ $1 = "-n" || $1 = "--no-hash" ]]; then
3035
append_hash=false
3136
shift
37+
elif [[ ( $1 = "-c" || $1 = "--config-file" ) ]]; then
38+
source "$2"
39+
shift 2
3240
else
3341
break
3442
fi

readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ Download the script (`wget https://github.com/X1011/git-directory-deploy/raw/mas
1212
- **default_username**, **default_email**: identity to use for git commits if none is set already. Useful for CI servers.
1313
- **repo**: repository to deploy to. Must be readable and writable. The default of "origin" will not work on Travis CI, since it uses the read-only git protocol. In that case, it is recommended to store a [GitHub token](https://help.github.com/articles/creating-an-access-token-for-command-line-use) in a [secure environment variable](http://docs.travis-ci.com/user/environment-variables/#Secure-Variables) and use it in an HTTPS URL like this: <code>repo=https://$GITHUB_TOKEN@github\.com/<i>user</i>/<i>repo</i>.git</code> **Warning: there is currently [an issue](https://github.com/X1011/git-directory-deploy/issues/7) where the repo URL may be output if an operation fails.**
1414

15+
You can also define any of variables in configuration files. The script will set variables from these sources in this order:
16+
17+
1. Defaults set in the script itself.
18+
* `.env` file in the path where you're running the script.
19+
* File specified on the command-line (see the `-c` option below).
20+
21+
Whatever values set later in this timeline will override those set earlier.
22+
1523
## run
1624
Do this every time you want to deploy, or have your CI server do it.
1725

@@ -22,6 +30,8 @@ Do this every time you want to deploy, or have your CI server do it.
2230
5. run `./deploy.sh`
2331

2432
### options
33+
`-c`, `--config-file`: specify a file that overrides the script's default configuration, or those values set in `.env`. The syntax for this file should be normal `var=value` declarations.
34+
2535
`-m`, `--message <message>`: specify message to be used for the commit on `deploy_branch`. By default, the message is the title of the source commit, prepended with 'publish: '.
2636

2737
`-n`, `--no-hash`: don't append the hash of the source commit to the commit message on `deploy_branch`. By default, the hash will be appended in a new paragraph, regardless of whether a message was specified with `-m`.

0 commit comments

Comments
 (0)