Skip to content

Commit 938f8f1

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 938f8f1

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

deploy.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@
22
set -o errexit #abort if any command fails
33

44
main() {
5-
deploy_directory=${GIT_DEPLOY_DIR:-dist}
6-
deploy_branch=${GIT_DEPLOY_BRANCH:-gh-pages}
7-
8-
#if no user identity is already set in the current git environment, use this:
9-
default_username=${GIT_DEPLOY_USERNAME:-deploy.sh}
10-
default_email=${GIT_DEPLOY_EMAIL:-}
5+
# Set args from a local environment file.
6+
if [ -e ".env" ]; then
7+
source .env
8+
fi
119

12-
#repository to deploy to. must be readable and writable.
13-
repo=${GIT_DEPLOY_REPO:-origin}
14-
15-
#append commit hash to the end of message by default
16-
append_hash=true
17-
1810
# Parse arg flags
1911
while : ; do
2012
if [[ $1 = "-v" || $1 = "--verbose" ]]; then
@@ -29,10 +21,27 @@ main() {
2921
elif [[ $1 = "-n" || $1 = "--no-hash" ]]; then
3022
append_hash=false
3123
shift
24+
elif [[ ( $1 = "-c" || $1 = "--config-file" ) ]]; then
25+
source "$2"
26+
shift 2
3227
else
3328
break
3429
fi
3530
done
31+
32+
# Set default options
33+
deploy_directory=${GIT_DEPLOY_DIR:-dist}
34+
deploy_branch=${GIT_DEPLOY_BRANCH:-gh-pages}
35+
36+
#if no user identity is already set in the current git environment, use this:
37+
default_username=${GIT_DEPLOY_USERNAME:-deploy.sh}
38+
default_email=${GIT_DEPLOY_EMAIL:-}
39+
40+
#repository to deploy to. must be readable and writable.
41+
repo=${GIT_DEPLOY_REPO:-origin}
42+
43+
#append commit hash to the end of message by default
44+
append_hash=true
3645

3746
enable_expanded_output
3847

readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ 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 using environment variables and configuration files:
16+
17+
- `GIT_DEPLOY_DIR`
18+
- `GIT_DEPLOY_BRANCH`
19+
- `GIT_DEPLOY_REPO`
20+
21+
The script will set these variables in this order of preference:
22+
23+
1. Defaults set in the script itself.
24+
* Environment variables.
25+
* `.env` file in the path where you're running the script.
26+
* File specified on the command-line (see the `-c` option below).
27+
28+
Whatever values set later in this list will override those set earlier.
29+
1530
## run
1631
Do this every time you want to deploy, or have your CI server do it.
1732

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

2439
### options
40+
`-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.
41+
2542
`-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: '.
2643

2744
`-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)