Skip to content

Commit df15333

Browse files
author
Matt Pearson
committed
Use environment variables in config. files.
This is instead of setting the script's private variables directly. We need to `source .env` before setting in-script defaults. If an environment variable is defined in `.env`, it will then still override the script's defaults.
1 parent 205a851 commit df15333

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

deploy.sh

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

44
main() {
5+
# Set args from a local environment file.
6+
if [ -e ".env" ]; then
7+
source .env
8+
fi
9+
510
deploy_directory=${GIT_DEPLOY_DIR:-dist}
611
deploy_branch=${GIT_DEPLOY_BRANCH:-gh-pages}
712

@@ -14,11 +19,6 @@ main() {
1419

1520
#append commit hash to the end of message by default
1621
append_hash=true
17-
18-
# Set args from a local env file
19-
if [ -e ".env" ]; then
20-
source .env
21-
fi
2222

2323
# Parse arg flags
2424
while : ; do

readme.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ 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:
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:
1622

1723
1. Defaults set in the script itself.
24+
* Environment variables.
1825
* `.env` file in the path where you're running the script.
1926
* File specified on the command-line (see the `-c` option below).
2027

21-
Whatever values set later in this timeline will override those set earlier.
28+
Whatever values set later in this list will override those set earlier.
2229

2330
## run
2431
Do this every time you want to deploy, or have your CI server do it.

0 commit comments

Comments
 (0)