Skip to content

Commit

Permalink
Add support for configuration files.
Browse files Browse the repository at this point in the history
 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 X1011#14.
  • Loading branch information
Matt Pearson committed Dec 10, 2015
1 parent eab82b6 commit 938f8f1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
33 changes: 21 additions & 12 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@
set -o errexit #abort if any command fails

main() {
deploy_directory=${GIT_DEPLOY_DIR:-dist}
deploy_branch=${GIT_DEPLOY_BRANCH:-gh-pages}

#if no user identity is already set in the current git environment, use this:
default_username=${GIT_DEPLOY_USERNAME:-deploy.sh}
default_email=${GIT_DEPLOY_EMAIL:-}
# Set args from a local environment file.
if [ -e ".env" ]; then
source .env
fi

#repository to deploy to. must be readable and writable.
repo=${GIT_DEPLOY_REPO:-origin}

#append commit hash to the end of message by default
append_hash=true

# Parse arg flags
while : ; do
if [[ $1 = "-v" || $1 = "--verbose" ]]; then
Expand All @@ -29,10 +21,27 @@ main() {
elif [[ $1 = "-n" || $1 = "--no-hash" ]]; then
append_hash=false
shift
elif [[ ( $1 = "-c" || $1 = "--config-file" ) ]]; then
source "$2"
shift 2
else
break
fi
done

# Set default options
deploy_directory=${GIT_DEPLOY_DIR:-dist}
deploy_branch=${GIT_DEPLOY_BRANCH:-gh-pages}

#if no user identity is already set in the current git environment, use this:
default_username=${GIT_DEPLOY_USERNAME:-deploy.sh}
default_email=${GIT_DEPLOY_EMAIL:-}

#repository to deploy to. must be readable and writable.
repo=${GIT_DEPLOY_REPO:-origin}

#append commit hash to the end of message by default
append_hash=true

enable_expanded_output

Expand Down
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ Download the script (`wget https://github.com/X1011/git-directory-deploy/raw/mas
- **default_username**, **default_email**: identity to use for git commits if none is set already. Useful for CI servers.
- **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.**

You can also define any of variables using environment variables and configuration files:

- `GIT_DEPLOY_DIR`
- `GIT_DEPLOY_BRANCH`
- `GIT_DEPLOY_REPO`

The script will set these variables in this order of preference:

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

Whatever values set later in this list will override those set earlier.

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

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

### options
`-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.

`-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: '.

`-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`.
Expand Down

0 comments on commit 938f8f1

Please sign in to comment.