Skip to content

Instantly share code, notes, and snippets.

@stipsan
Last active November 5, 2017 16:44
Show Gist options
  • Save stipsan/bbf4adcdafd9eabfa6a9a42397a1c1b9 to your computer and use it in GitHub Desktop.
Save stipsan/bbf4adcdafd9eabfa6a9a42397a1c1b9 to your computer and use it in GitHub Desktop.
Publish to gh pages from circleci with zero config
#!/usr/bin/env bash
set -o errexit
copy_contents() {
local source="$1"
status "Copying contents from $source"
if [[ ! "$dryrun" == "1" ]]; then
(cd "$source" >/dev/null && tar c .) | tar xv
else
_ "(cd \"$source\" >/dev/null && tar c .) | tar xv"
fi
}
# Runs the deployment
run() {
if [ ! -d "$source" ]; then
echo "Source is not a directory: $source"
exit 1
fi
local tmpdir="$(mktemp -d)"
if [[ "$force" == "1" ]]; then
_ cd "$tmpdir"
_ git init
_ git checkout -b "$branch"
_ rm -rf _next
copy_contents "$source"
_ git add -A .
git_commit
git_push --force
else
_ cd "$tmpdir"
_ git clone "$repo" . -b "$branch" || ( \
_ git init && \
_ git checkout -b "$branch")
_ rm -rf _next
copy_contents "$source"
_ git add -A .
git_commit || true
git_push
fi
_ rm -rf "$tmpdir"
status_ "Done"
}
git_commit() {
_ git config user.name "CircleCI"
_ git config user.email "[email protected]"
_ git commit -m "$message"
}
git_push() {
_ git push "${repo}" "$branch" "$@"
}
status() {
echo -e "\n\033[34m==>\033[0;1m" "$@\033[0m"
}
status_() {
echo -e "\033[33;1m==>\033[0m" "$@"
}
_() {
echo ""
status_ "$@"
if [[ ! "$dryrun" == "1" ]]; then "$@"; fi
}
#
# Defaults
#
force=0
dryrun=0
repospec="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}"
source="docs"
message="Update"
: ${branch:="gh-pages"}
if [ -z "$source" ]; then
exit 1
fi
source="`pwd -LP`/$source"
repo="https://github.com/${repospec}.git"
run
{
"name": "git-update-ghpages",
"description": "Update GitHub pages from the command line",
"version": "1.3.0",
"author": "Rico Sta. Cruz <[email protected]>",
"bin": {
"git-update-ghpages": "git-update-ghpages"
},
"bugs": {
"url": "https://github.com/rstacruz/git-update-ghpages/issues"
},
"homepage": "https://github.com/rstacruz/git-update-ghpages#readme",
"keywords": [
"deploy",
"git",
"github",
"github pages",
"pages"
],
"license": "MIT",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/rstacruz/git-update-ghpages.git"
},
"scripts": {
"test": "make -s test"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment