This is mostly for my benefit as I always have to look it up - this will push content that's built by your Travis build into the gh-pages
branch of the same repo. It's the simplest way of deploying to Github Pages I've found - it handles switching branch and details like pushing content from a dist
subfolder for you automatically.
-
Install the
gh-pages
CLI tool using NPM:
npm i --save-dev gh-pages
-
Grab a Github access token so Travis can push back up to your repo's
gh-pages
branch:- Go to https://github.com/settings/tokens/new and create a new token with the full
repo
scope.
- Go to https://github.com/settings/tokens/new and create a new token with the full
-
Encrypt the token with Travis so you can use it in your builds (
--add
automatically adds the encrypted data to yourtravis.yml
):
travis encrypt --add -r <org/repo> GITHUB_TOKEN=<token>
- If you don't have
travis
available on your machine, usegem install travis
.
- If you don't have
-
Finally, Travis needs to know how to use the token when pushing. As a step in your
.travis.yml
:
script: ... - git remote set-url origin https://<token's username>:$GITHUB_TOKEN@github.com/<org/repo>.git - gh-pages -d dist
- Add any other args for
gh-pages
as necessary - the above will put all the content in thedist
folder into the root of thegh-pages
branch.
- Add any other args for
...and we're done! Let me know if you found this useful, it'll make my day.
Top comments (2)
I also write a guidance for SSG for use with Travis.
epsi-rns.gitlab.io/devops/2020/02/...
Is this localhost Travis?