Skip to content

Instantly share code, notes, and snippets.

@backspace
Forked from MariadeAnton/hi-satellite.md
Last active October 4, 2017 08:36
Show Gist options
  • Save backspace/3574a7f564b7a595ae7611807bfa9d06 to your computer and use it in GitHub Desktop.
Save backspace/3574a7f564b7a595ae7611807bfa9d06 to your computer and use it in GitHub Desktop.
Travis CI Demo Examples - GitHub Universe 2017

Travis CI - GitHub Universe 2017

A Tessa A Travis

Menu

Why?

image

Travis Build Status Badge

Travis PR checks

Getting up and running

Best Practices

  • Configure your build to match your production environment. Set up the language you use, and the services, databases and tools that you normally use.

  • Set up Notifications πŸ”” β†’ Fix broken builds as soon as possible. Ensure that you're always developing on a known stable branch.

  • Automate deployment ✨

  • Setting up a deployment pipeline πŸš€ Check out Build Stages

Some workflows tips and tricks!

Fork, activate and start building! πŸŽ‰

You can fork any of the :octocat: repositories below, go to your profile page, activate it, start committing to GitHub and see your Travis builds running.

Build Stages

πŸ“– You can find information and examples in our Build Stages Docs.

Building a multi-platform release with Travis and Docker

This example tests a Rust binary on multiple targeted platforms using Docker, and if the tests pass, release it to GitHub Releases. Demo credit goes to the fantastic @joecorcoran - thank you!

  • :octocat: https://github.com/joecorcoran/travis-docker-demo

  • Build Status

    .travis.yml file used:

    language: rust
    
    services: docker
    
    branches:
      only:
        - master
    
    # Install tools for running tests
    install:
      - cargo install cross
    
    # Setup jobs per platform
    jobs:
      include:
        # 64-bit tests
        - &test
          stage: test
          script: cross test --target $TARGET
          env: TARGET=x86_64-unknown-linux-gnu
        # 32-bit tests
        - <<: *test
          env: TARGET=i686-unknown-linux-gnu
        # 64-bit release
        - &deploy
          stage: deploy
          env: TARGET=x86_64-unknown-linux-gnu
          script: skip
          before_deploy:
            - cross build --release --target $TARGET
            - cp target/$TARGET/release/travis-docker-demo .
            - tar czf travis-docker-demo-$TARGET-$TRAVIS_BUILD_NUMBER.tar.gz travis-docker-demo
            - TRAVIS_TAG=build-$TRAVIS_BUILD_NUMBER
          deploy:
            api_key:
              secure: "..."
            file: travis-docker-demo-$TARGET-$TRAVIS_BUILD_NUMBER.tar.gz
            provider: releases
            skip_cleanup: true
        # 32-bit release
        - <<: *deploy
          env: TARGET=i686-unknown-linux-gnu
    
  • πŸŽ₯ Example demo available here

DEMO πŸ• TIME

Credit goes to the amazing @lislis, thank you!

Pizza site

An Ember application built on the top of the pizza server.

.travis.yml file used

language: node_js
node_js:
- '6'
- '7'
sudo: false
cache:
  directories:
  - "$HOME/.npm"
before_install:
- npm config set spin false
- npm install -g phantomjs-prebuilt ember-cli
- phantomjs --version

install:
- npm install

jobs:
  include:
    - stage: test
      script: ember test
    - stage: build
      script: ember build
    - stage: deploy
      deploy: &heroku
        provider: heroku
        app: quattro-stagione
        script: skip
        on:
          branch: master
        api_key:
          secure:
          ...

Pizza Server

Crystal lang, deployed to NPM.

.travis.yml file used

language: crystal

jobs:
  include:
    - stage: build
      script: crystal build --release src/pizza-server.cr
    - stage: deploy
      script: skip
      deploy: &heroku
        provider: heroku
        app: berlin-pizza
        api_key: $HEROKU_AUTH_TOKEN
        on:
          branch: master
    - stage: npm publish
      script: skip
      deploy:
        provider: npm
        api_key: $NPM_API_KEY
        email: $EMAIL
        on:
          branch: master
          tags: true

Open source build stages examples

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.

This demonstrates a conditional build stage: browser tests using Sauce Labs that only run on push builds because pull request builds don’t have access to credentials.

.travis.yml:

stages:
  - test
  - name: browser
    if: type = push
Pull request build Push build
Bootstrap pull request build screenshot Bootstrap push build screenshot

Quasar Analytics is a general-purpose compiler for translating data processing and analytics over semi-structured data into efficient plans that run 100% in the target infrastructure.

.travis.yml:

stages:
  - name: clean
    if: NOT type = pull_request
  - name: compile
  - name: unit test
  - name: test
  - name: publish
    # weirdly, we have to add the extra PR check
    if: NOT type = pull_request
…
jobs:
  include:
    - stage: clean
      env:
      script: ./sbt -DisIsolatedEnv=${ISOLATED_ENV:=false} clean

    - stage: compile
      env:
      script:
        - set -e

        - |-
          ./sbt -DisIsolatedEnv=${ISOLATED_ENV:=false} ++$TRAVIS_SCALA_VERSION \
            checkHeaders \
            test:compile

        - set +e

    # note that the "test" stage has special significance to Travis (it's the only matrix-able stage)
    - stage: unit test
      env:
      script:
        - |-
          ./sbt -DisIsolatedEnv=${ISOLATED_ENV:=false} ++$TRAVIS_SCALA_VERSION \
            it/sideEffectTestFSConfig \
            "testOnly -- xonly" \
            "exclusive:testOnly -- xonly"

    - stage: publish
      env:
      script:
        - set -e
        - './sbt ++$TRAVIS_SCALA_VERSION doc web/assembly'
        - scripts/testJar

        # release to sonatype
        - scripts/quasarPublishAndTag

        # release to github
        - scripts/publishJar

        - set +e
Failing build Passing build
Quasar failing build Quasar passing build
One of the jobs in the test stage fails, so the final stage doesn’t run. All the jobs in the test stage pass, so the final stage runs.

Building and deploying a Jekyll site

Cron jobs

You can schedule builds in Travis CI:

Demo credit goes to the wonderful @aakritigupta, thank you!

What else?

Play, test, build, deploy!

πŸ“– Learn some more in our documentation: Travis CI Docs

πŸ“° Don't miss any new features, checkout the Travis CI Blog

🐦 @travisci in Twitter

Questions? Drop us a line at support@travis-ci.com

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