Publish Content To Github Pages with Travis

The best way to use Statie is to have a website on Github repository, use Github Pages and Travis to host and update generated content for you.

How to Setup?

Add 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.

On Github go to SettingsDeveloper SettingsPersonal Access TokensGenerate New Token and select repo scope. Give it a recognisable name and copy generated token afterwards.

Visit https://travis-ci.org/<github-profile>/<repository-name> and Activate repository. Select More optionsSettings 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.

GITHUB_TOKEN is hidden from the log

Configure Travis

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).

You can read more about building pull requests or deploying to Github Pages in the official documentation.

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.