Skip to content

Instantly share code, notes, and snippets.

@paradite
Forked from willprice/.travis.yml
Created December 16, 2017 10:01
Show Gist options
  • Save paradite/34e9f10c234283b2603afaad180a4f52 to your computer and use it in GitHub Desktop.
Save paradite/34e9f10c234283b2603afaad180a4f52 to your computer and use it in GitHub Desktop.

Revisions

  1. Will Price revised this gist Aug 17, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions travis_to_github_tutorial.asciidoc
    Original file line number Diff line number Diff line change
    @@ -22,8 +22,8 @@ The main steps of the process:
    == Guided tutorial
    I've got a bunch of asciidoc files inside of https://github.com/MVSE-Outreach/resources that I want to build to save people from having to install asciidoctor or pandoc to regenerate these files.

    First I go to https://github.com/settings/applications and generate a token that I call outreach-resources with the permissions `public_repo`. This secret token needs to be stored somewhere, I don't want it to be revealed inside my `.travis.yml` or on the travis build server. Travis supports encrypted environment variables, so I run the command `echo GH_TOKEN=my_github_token | travis encrypt --add` where you'd replace `my_github_token` with the access token generated earlier.
    First I go to https://github.com/settings/applications and generate a token that I call outreach-resources with the permissions `public_repo`. This secret token needs to be stored somewhere, I don't want it to be revealed inside my `.travis.yml` or on the travis build server. Travis supports encrypted environment variables, so I run the command `echo GH_TOKEN=my_github_token | travis encrypt --add` where you'd replace `my_github_token` with the access token generated earlier; this command stores the encrypted github token inside the `.travis.yml` file.

    Now that I've got an access token available to myself on travis we can't write the script that will push things back to github (checkout `push.sh`). I set up the username and email address of the git user on travis, checkout the branch I wish to push to, add the files I want and commit using the environment variable `$TRAVIS_BUILD_NUMBER` which helps me identify which commits correspond to which builds (totally optional). I finally push this commit back to the repository which takes the form: `https://${GH_TOKEN}@github.com/<user_name>/<repo_name>.git`, here `GH_TOKEN` is substituted inside the build server which acts as a username to the repository with full commit rights!
    Now that I've got an access token available on travis we can write the script that will push things back to github (checkout `push.sh`). I set up the username and email address of the git user on travis, checkout the branch I wish to push to, add the files I want and commit using the environment variable `$TRAVIS_BUILD_NUMBER` which helps me identify which commits correspond to which builds (totally optional). I finally push this commit back to the repository which takes the form: `https://${GH_TOKEN}@github.com/<user_name>/<repo_name>.git`, here `GH_TOKEN` is substituted inside the build server which acts as a username to the repository with full commit rights!

    Travis's build process is instructed by a file inside your repository named `.travis.yml` which contains information on the language of the repository, build comamands, dependencies, post build hooks etc. In my YAML file you can see I'm using the hooks `before_install`, `script` and `after_success`, all of which take a command, or a list of commands and execute them. You'll want to keep the `push.sh` commands outside of the YAML file (i.e. don't get rid of `push.sh` and put them all in `after_success` as `${GH_TOKEN}` won't be substituted).
  2. Will Price revised this gist Aug 17, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions travis_to_github_tutorial.asciidoc
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    = Pushing to github from TravisCI

    == Introduction

    I run several repositories that need documentation compiling to distributable formats (e.g. AsciiDoc to HTML, MD to PDF), rather than having to build and commit every time I want to update the distributables, I'd like to automate this process. This is where I use TravisCI as a build server.
  3. Will Price renamed this gist Aug 17, 2014. 1 changed file with 0 additions and 0 deletions.
  4. Will Price renamed this gist Aug 17, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.asciidoc → travis_to_github_tutorial
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    = Pushing to github from TravisCI
    == Introduction

    I run several repositories that need documentation compiling to distributable formats (e.g. AsciiDoc to HTML, MD to PDF), rather than having to build and commit every time I want to update the distributables, I'd like to automate this process. This is where I use TravisCI as a build server.

    == Requirements
  5. Will Price created this gist Aug 17, 2014.
    12 changes: 12 additions & 0 deletions .travis.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # Ruby is our language as asciidoctor is a ruby gem.
    lang: ruby
    before_install:
    - sudo apt-get install pandoc
    - gem install asciidoctor
    script:
    - make
    after_success:
    - .travis/push.sh
    env:
    global:
    secure: hZJlqgOzA2zIUJSWIka0PylqNaTkfHq+kS48RrHmocrK0vLyCW7ECWrzez2f2RVdTNzPi0b+yJq2uCbFfWjImZqg+XY1I75/CVVdSYMk7PJkYZ/iBDixMYY8CAkRRd5yZft9uZAdZzR4KLCPN18n7qfISv/M9VA8989NKcVyiEU=
    27 changes: 27 additions & 0 deletions gistfile1.asciidoc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    = Pushing to github from TravisCI
    == Introduction
    I run several repositories that need documentation compiling to distributable formats (e.g. AsciiDoc to HTML, MD to PDF), rather than having to build and commit every time I want to update the distributables, I'd like to automate this process. This is where I use TravisCI as a build server.

    == Requirements

    * Github repo with TravisCI support enabled - https://travis-ci.org/profile/<YOUR_GITHUB_USERNAME>, flick the enable switch
    * Github personal access token - https://github.com/settings/applications
    * Travis gem - `sudo gem install travis`

    == Build process
    The main steps of the process:

    . Install software necessary for build
    . Build software
    . Set up git with username, email, and remote
    . Add and commit the files you've built
    . Push these files back to github using your *personal access token*

    == Guided tutorial
    I've got a bunch of asciidoc files inside of https://github.com/MVSE-Outreach/resources that I want to build to save people from having to install asciidoctor or pandoc to regenerate these files.

    First I go to https://github.com/settings/applications and generate a token that I call outreach-resources with the permissions `public_repo`. This secret token needs to be stored somewhere, I don't want it to be revealed inside my `.travis.yml` or on the travis build server. Travis supports encrypted environment variables, so I run the command `echo GH_TOKEN=my_github_token | travis encrypt --add` where you'd replace `my_github_token` with the access token generated earlier.

    Now that I've got an access token available to myself on travis we can't write the script that will push things back to github (checkout `push.sh`). I set up the username and email address of the git user on travis, checkout the branch I wish to push to, add the files I want and commit using the environment variable `$TRAVIS_BUILD_NUMBER` which helps me identify which commits correspond to which builds (totally optional). I finally push this commit back to the repository which takes the form: `https://${GH_TOKEN}@github.com/<user_name>/<repo_name>.git`, here `GH_TOKEN` is substituted inside the build server which acts as a username to the repository with full commit rights!

    Travis's build process is instructed by a file inside your repository named `.travis.yml` which contains information on the language of the repository, build comamands, dependencies, post build hooks etc. In my YAML file you can see I'm using the hooks `before_install`, `script` and `after_success`, all of which take a command, or a list of commands and execute them. You'll want to keep the `push.sh` commands outside of the YAML file (i.e. don't get rid of `push.sh` and put them all in `after_success` as `${GH_TOKEN}` won't be substituted).
    21 changes: 21 additions & 0 deletions push.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/bin/sh

    setup_git() {
    git config --global user.email "[email protected]"
    git config --global user.name "Travis CI"
    }

    commit_website_files() {
    git checkout -b gh-pages
    git add . *.html
    git commit --message "Travis build: $TRAVIS_BUILD_NUMBER"
    }

    upload_files() {
    git remote add origin-pages https://${GH_TOKEN}@github.com/MVSE-outreach/resources.git > /dev/null 2>&1
    git push --quiet --set-upstream origin-pages gh-pages
    }

    setup_git
    commit_website_files
    upload_files