Skip to content

Commit 3f2b9f6

Browse files
committed
make repository configurable
1 parent 0702b60 commit 3f2b9f6

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

deploy.sh

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,35 @@ deploy_branch=gh-pages
88
default_username=deploy.sh
99
default_email=
1010

11+
#repository to deploy to. must be readable and writable.
12+
repo=origin
13+
1114
if [[ $1 = "-v" || $1 = "--verbose" ]]; then
12-
#echo expanded commands as they are executed
13-
set -o xtrace
15+
verbose=true
1416
fi
1517

18+
#echo expanded commands as they are executed (for debugging)
19+
function enable_expanded_output {
20+
if [ $verbose ]; then
21+
set -o xtrace
22+
set +o verbose
23+
fi
24+
}
25+
26+
#this is used to avoid outputting the repo URL, which may contain a secret token
27+
function disable_expanded_output {
28+
if [ $verbose ]; then
29+
set +o xtrace
30+
set -o verbose
31+
fi
32+
}
33+
34+
enable_expanded_output
35+
1636
commit_title=`git log -n 1 --format="%s" HEAD`
1737
commit_hash=`git log -n 1 --format="%H" HEAD`
1838

19-
set_user_id() {
39+
function set_user_id {
2040
if [[ -z `git config user.name` ]]; then
2141
git config user.name "$default_username"
2242
fi
@@ -32,7 +52,9 @@ if ! git diff --exit-code --quiet --cached; then
3252
exit 1
3353
fi
3454

35-
git fetch --force origin $deploy_branch:$deploy_branch
55+
disable_expanded_output
56+
git fetch --force $repo $deploy_branch:$deploy_branch
57+
enable_expanded_output
3658

3759
#make deploy_branch the current branch
3860
git symbolic-ref HEAD refs/heads/$deploy_branch
@@ -43,16 +65,19 @@ git --work-tree "$deploy_directory" reset --mixed --quiet
4365
git --work-tree "$deploy_directory" add --all
4466

4567
set +o errexit
46-
git --work-tree "$deploy_directory" diff --exit-code --quiet HEAD
47-
diff=$?
68+
diff=$(git --work-tree "$deploy_directory" diff --exit-code --quiet HEAD)$?
4869
set -o errexit
4970
case $diff in
5071
0) echo No changes to files in $deploy_directory. Skipping commit.;;
5172
1)
5273
set_user_id
5374
git --work-tree "$deploy_directory" commit -m \
5475
"publish: $commit_title"$'\n\n'"generated from commit $commit_hash"
55-
git push origin $deploy_branch
76+
77+
disable_expanded_output
78+
#--quiet is important here to avoid outputting the repo URL, which may contain a secret token
79+
git push --quiet $repo $deploy_branch
80+
enable_expanded_output
5681
;;
5782
*)
5883
echo git diff exited with code $diff. Aborting.

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
This is a script for deploying generated files to a git branch, such as when building a single-page app using [Yeoman](http://yeoman.io) and deploying to [GitHub Pages](http://pages.github.com). Unlike the [git-subtree approach](http://yeoman.io/deployment.html), it does not require the generated files be committed to the source branch. It keeps a linear history on the deploy branch and does not make superfluous commits or deploys when the generated files do not change.
22

3+
For an example of use, see [X1011/verge-mobile-bingo](https://github.com/X1011/verge-mobile-bingo).
4+
35
## configuration
46
Edit these variables at the top of the script to fit your project:
57

68
- **deploy_directory**: root of the tree of files to deploy
79
- **deploy_branch**: branch to commit files to and push to origin
810
- **default_username**, **default_email**: identity to use for git commits if none is set already. Useful for CI servers.
11+
- **repo**: (optional) 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://about.travis-ci.org/docs/user/build-configuration/#Secure-environment-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>
912

1013
## setup
1114
This could be implemented in the script, but I don’t feel like doing it. Replace "dist" with your deploy_directory and "gh-pages" with your deploy_branch.

0 commit comments

Comments
 (0)