Skip to content

Instantly share code, notes, and snippets.

@maxpou
Last active March 20, 2023 04:02
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maxpou/bc3eb944aa727d352f85bc0ce8bc082c to your computer and use it in GitHub Desktop.
Save maxpou/bc3eb944aa727d352f85bc0ce8bc082c to your computer and use it in GitHub Desktop.
Auto deploy on GitHub Pages when commit on master (with TravisCI)

Auto deploy on GitHub Pages when commit on master (with TravisCI)

Repo side

  1. touch .travis.yml
  2. Copy paste the following
language: node_js
node_js: stable

cache:
  directories:
    - node_modules

before_deploy:
  - "npm run build"

deploy:
  provider: pages
  skip_cleanup: true
  github_token: $GITHUB_TOKEN
  local_dir: dist
  on:
    branch: master

Github Side

  1. On github go here: https://github.com/settings/tokens
  2. Generate new token with all repo access (first checkbox)
  3. token name: (i.e. the repo name)
  4. Copy the token (string in the green background)

Travis-ci.org side

  1. Add your repository
  2. in https://travis-ci.org/{user}/{reponame}, go to more option menu, then settings.
  3. add new environment variable - Display value in build log must be switch off!

What's happened?

Now on every push to master (merge, PR...), travis will launch the command npm run build (feel free to change it!). It will put the build under the dist folder (see local_dir value in yml file). Then this folder is pushed to a branch called gh-pages (stand for github pages).

Go to the repo settings you will see something related to gh-pages.

The app should be available under this URI: {user}.github.io/{repo-name}/ or www.your-domain/{repo} if you setup a CNAME.

@pot-code
Copy link

pot-code commented Nov 20, 2019

The travis CI keeps failing due to the experimental GitHub pages deploying feature, as it prints missing github_token, but I do have added the token variable in .travis.yml and environment variable is settled in repository setting.

Updated: add edge: true to deploy config

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