First set out your build scripts In your package.json scripts and install the gh-pages npm module
"build": "gatsby build",
"test": "echo \"no test specified\" && exit 0",
"preDeploy": "gatsby build --prefix-paths",
"deploy": "npm run preDeploy && gh-pages -d public"
Connect Travis CI to your repo and in the repo settings add an enviroment var call GITHUB_TOKEN with the value of your github token from: Setting > developer settings > Personal access tokens here create a token for Travis.
Then add the following file to your repo:
.travis.yml
language: node_js
node_js:
- "stable"
cache:
directories:
- node_modules
deploy:
provider: pages
skip-cleanup: true
github-token: $GITHUB_TOKEN
local_dir: public
keep-history: true
on:
branch: master
before_script:
- "npm i -g gatsby"
- "npm i"
script:
- "npm run test"
after_success:
- "npm run deploy"
Thanks for that snippet, this is a great way to start! I have a few comments on the caching:
node_modules
entry..cache
andpublic
. I've tested this myself and this seems to bring faster builds reliably.