Skip to content

Instantly share code, notes, and snippets.

@antoniotrento
Forked from MariadeAnton/hi-satellite.md
Created July 6, 2020 23:53
Show Gist options
  • Save antoniotrento/ca6a14fa74c4fcae169701dc51d1c987 to your computer and use it in GitHub Desktop.
Save antoniotrento/ca6a14fa74c4fcae169701dc51d1c987 to your computer and use it in GitHub Desktop.
Travis CI Demo Examples - GitHub Satellite 2019

Travis CI - GitHub Satellite 2019

Travis-CI-logo

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 (Ember Application - built on the top of the pizza server)

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
```

Building and deploying a Jekyll site

Cron jobs

You can schedule builds in Travis CI:

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

Windows at Travis CI

os: windows exists now!

A Windows Server, version 1803 environment with git bash, powershell, chocolatey to choco install and language built-in language support for C, C++, Node.js, Rust and Go.

Or customize to prepare your own environment, like Python builds: https://travis-ci.org/gerardcl/renfe-cli/jobs/529890694

For more details: https://docs.travis-ci.com/user/reference/windows

Import shared build configurations

The main source of configuration for your build is the .travis.yml file stored in your repository.

Additionally, this .travis.yml supports importing up to 5 YAML sources/snippets that can be shared across repositories. This works using the import key, which supports the following formats:

    #import a single file
    import: travis-ci/build-configs/rubies.yml@main
    
    # import multiple files
    
    import: 
      - travis-ci/build-configs/rubies.yml@adf1235
      - travis-ci/build-configs/other.yml@v1
# local imports fetch the same git commit ref
import:
- ./one.yml
- ./other.yml

For example:

Build Stages

cache: bundler

jobs:
  include:
    - stage: prepare cache
      script: true
      rvm: 2.3
    - stage: test
      script: bundle show
      rvm: 2.3
    - stage: test
      script: bundle show
      rvm: 2.3
    - stage: test
      script: bundle show
      rvm: 2.3
language: node_js
node_js:
  - "7"
  - "6"
  - "5"
  - "4"

script: echo "Running tests against $(node -v) ..."

jobs:
  include:
    - stage: npm release
      node_js: "7"
      script: echo "Deploying to npm ..."
      deploy:
        provider: npm
        api_key: $NPM_API_KEY
        on: deploy-npm-release

Ref: https://docs.travis-ci.com/user/build-stages/

Examples: https://docs.travis-ci.com/user/build-stages/#examples

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? Join the Travis CI Community Forum or drop us a line at [email protected]

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