Publish Content To Github Pages with Travis
How to Setup?
gh-pages Branch to the Repository
Github Pages usually shows the content of the special branch named
gh-pages. Use following commands to create it:
git checkout -b gh-pages git push origin gh-pages
Allow Travis to Make Changes
Travis is not allowed to modify your Github repository per se. We need to give it a correct rights explicitly - via tokens.
https://travis-ci.org/<github-profile>/<repository-name> and Activate repository. Select More options → Settings and under Environment variables add new one:
- Name: GITHUB_TOKEN
- Value: generated token
You don't have to be afraid of exposing the token to the public - it's securely hidden from the logs unless you purposely set it otherwise.
In the root of your project's directory create
.travis.yml file with the following content:
language: php php: 7.1 install: - composer install script: - vendor/bin/statie generate source deploy: provider: pages skip_cleanup: true github_token: $GITHUB_TOKEN local_dir: output on: branch: master
Such configuration will install all dependencies and generate output on every commit you push (also on every pull request) to the repository, but publish it only when changes are made upon the
master branch (specified in the last row).
Notice the usage of the variable
$GITHUB_TOKEN we just created - this adds Travis rights to make changes. Now the Travis is able to push to your Github repository for you!
Push a new change to your project or run a build from the Travis Dashboard and visit
https://<github-profile>.github.io/<repository-name> to see generated output.