Create a gist now

Instantly share code, notes, and snippets.

@bewest /README.md
Last active Feb 28, 2017

What would you like to do?
using travis-ci to build using docpad, and publish to github pages

use travis-ci to publish to github

Demo

docpad

The docpad-plugin-ghpages uses the following information to stitch a new repo with contents of ./out directory onto root of your gh-pages branch:

  • git config user.email
  • git config user.name
  • git config remote.origin.url - uses this url for the git push to your gh-pages branch

It turns out that your github token is a valid username, such that $token@github.com:$user/$repo.git is a valid, authorized git url. Any process that can grab valid values for these three pieces of information will be able to produce new changes in github.com.

Using prebuild.sh to retrieve all three pieces of information from the output travis encrypt allows you to echo the user name and email for debugging, and primes travis for a successful run of docpad deploy-ghpages.

example travis

language: node_js
before_script:
- ./prebuild.sh
script:
- docpad deploy-ghpages
env:
  global:
  - FOO="BAR"
  - GH_REPO="medevice-users/gallery"

Encode tokens

# append a travis secret to .travis.yml
# include some known debuggable strings along with your secret
# commit the result

travis encrypt --add -r user-org-name/repo-name 'GIT_NAME="Your Committer Name [via travis key]" GIT_EMAIL=committer@example.com GH_TOKEN=ahead0fxxxxxxxxxxxxxxxxxxx'

#####
# EOF

If you have a .travis.yml already, this will add a secret variable. Make sure to delete any previous secret, so that the only one available is this one. My brief testing suggests all pieces of information are required, and you'll be glad you can echo some non-sensitive bits from the same serialization for debugging later.

Useful

TL;DR

  • github issues tokens, you can grab one using curl
  • craft a special remote push url, make sure git repo is configured using this url with your token.
  • encrypt several environment variables, some sensitive along with some that are not so that you can echo to debug.

docpad-plugin-ghpages

likely problems

TL;DR

  • send a few variables you feel comfortable echoing for debug
  • make sure you that git config remote.origin.url has output.
  • make sure git is configured with your username and email

Having difficulty getting this working on travis. For some reason, git is not getting the new specially authorized remote url.

Fails with:

Using worker: worker-linux-2-2.bb.travis-ci.org:travis-linux-6

$ export FOO="BAR"
$ export GH_REPO="medevice-users/gallery"
$ export GIT_NAME=[secure]
$ export GIT_EMAIL=[secure]
$ export GH_TOKEN=[secure]
travis_fold:start:git.1
$ git clone --depth=50 --branch=master git://github.com/medevice-users/gallery.git medevice-users/gallery
Cloning into 'medevice-users/gallery'...
remote: Counting objects: 798, done.�[K
[...]
travis_fold:end:install
travis_fold:start:before_script.1
$ export REPO_URL="https://$GH_TOKEN@github.com/$GH_REPO.git"
travis_fold:end:before_script.1
travis_fold:start:before_script.2
$ ./prebuild.sh
HELLO WORLD set up medevice-users/gallery [via travis] for Ben West [via travis] <bewest@gmail.com>
STATUS
# HEAD detached at d797dbf
nothing to commit, working directory clean
remotes pre pre-authorized remote url
old	git://github.com/medevice-users/gallery.git (fetch)
old	git://github.com/medevice-users/gallery.git (push)
travis_fold:end:before_script.2
$ docpad deploy-ghpages
�[32minfo:�[39m Welcome to DocPad v6.46.4
�[32minfo:�[39m Contribute: http://docpad.org/docs/contribute
�[32minfo:�[39m Plugins: cleanurls, coffeescript, eco, ghpages, jade, less, livereload, marked, paged, partials, related, stylus, text
�[32minfo:�[39m Environment: static
�[32minfo:�[39m Deployment to GitHub Pages starting...
�[32minfo:�[39m Generating...
�[32minfo:�[39m Generated 45/45 files in 6.74 seconds
Initialized empty Git repository in /home/travis/build/medevice-users/gallery/out/.git/

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <travis@testing-worker-linux-2-2-16953-linux-6.(none)>) not allowed
�[31merror:�[39m Something went wrong with the action
�[31merror:�[39m An error occured: 
Error: 
*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <travis@testing-worker-linux-2-2-16953-linux-6.(none)>) not allowed

    at ChildProcess.<anonymous> (/home/travis/build/medevice-users/gallery/node_modules/docpad-plugin-ghpages/node_modules/safeps/out/lib/safeps.js:154:21)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:735:16)
    at Socket.<anonymous> (child_process.js:948:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.close (net.js:466:12)

The command "docpad deploy-ghpages" exited with 1.

Done. Your build exited with 1.

Runs equivalent of?:

rough bash translation of ghpages.plugin.coffee

ghpages.plugin.coffee

rootPath="./" # ?
rm -Rm out/.git
( cd $rootPath/out; 
  url=$(git config remote.origin.url)
  lastCommit=$(git log --oneline | head -n 1)
  git init
  git add .
  git commit -m $lastCommit
  git push --force $url master:gh-pages
)

License

If you are wanting to open-source your website, we suggest using the Creative Commons Attribution License for content and the MIT License for code.

#!/bin/bash
echo "BUMP HELLO WORLD set up $GH_REPO [via travis] for $GIT_NAME <${GIT_EMAIL}>"
export REPO_URL="https://$GH_TOKEN@github.com/$GH_REPO.git"
git config --global user.email "$GIT_EMAIL"
git config --global user.name "$GIT_NAME"
git branch -a
echo "STATUS"
git status
git remote rename origin old
echo "remotes pre pre-authorized remote url"
git remote -v
git remote add origin $REPO_URL
git config remote.origin.url $REPO_URL
echo "DEBUG, cd out"
test -d out && (
cd out
echo -n "user.email"
git config user.email
echo -n "user.name"
git config user.name
) || echo "fresh build, no out directory"

using travis ci to publish to github pages

github has made it harder to use several features, gists and cloning in particular. This fixes both:

CLONE_URL=git@gist.github.com:6100033.git

git clone $CLONE_URL travis_github_pages

####
#EOF
Owner

bewest commented Jul 29, 2013

@balupton you might like this.

just noticed it :) github doesn't notify you about gist mentions unfortunately. Retweeted on the DocPad twitter account. Awesome work! 👍

So, this works great for me, but I just noticed the git push command outputs the URL to my git repo, including the private token, in the console output that is available for the public to see on travis-ci.com.

Do you have a way to work around this?

I sent in a pull request with a new quiet config option - set plugins.ghpages.quiet = true in your docpad config file to enable it: docpad/docpad-plugin-ghpages#15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment