dsd57259 2015-10-13 19:48
浏览 68
已采纳

Travis CI + Go:为不同的操作系统创建特定的构建流程

I have a Go project that I want to build with Travis-CI and deploy it to a specific provider. I familiar with Gimme project that will use a cross-compilation to do so. But because Travis already support linux and osx I only need this feature for Windows build.

The big motivation is, of course, to avoid cross-compilation run time error as there are plenty of it.

My question is how can I create, in the same .travis.yml file, a different build flow:

  1. Native linux/os build (with "os" section).
  2. Windows compilation using Gimmme

The .travis.yml file for the first option will look something like:

language: go

go: 
  - 1.5.1

branches: 
  only: 
    - master

os:
    - osx
    - linux


before_script:
    - go get -d -v ./...

script:
    - go build -v ./...
    # - go test -v ./...

before_deploy: 
  -  chmod +x ./before_deploy.sh
  - ./before_deploy.sh

The .travis.yml file for the second option will look something like:

language: go

go: 
  - 1.5.1

branches: 
  only: 
    - master

env:
    - GIMME_OS=windows GIMME_ARCH=amd64


before_script:
    - go get -d -v ./...

script:
    - go build -v ./...
    # - go test -v ./...

before_deploy: 
  -  chmod +x ./before_deploy.sh
  - ./before_deploy.sh

Is there a nice clean way to combine these two (with Environment variables or any other crazy idea)?

  • 写回答

1条回答 默认 最新

  • doucuan5365 2015-10-16 08:34
    关注

    It might be simple, but matrix environement can not be done for a specific OS ...

    Then just select with local environement variable:

    language: go
    go: 
      - 1.5.1
    branches: 
      only: 
        - master
    os:
      - osx
      - linux
    install:
      - if [ "$TRAVIS_OS_NAME" == "linux" ]; then
            export GIMME_OS=windows;
            export GIMME_ARCH=amd64;
        fi
    before_script:
      - go get -d -v ./...
    script:
      - go build -v ./...
    after_script:
      - go test -v ./...
    before_deploy: 
      - ./before_deploy.sh
    

    An other way:

    language: go
    go: 
      - 1.5.1
    branches: 
      only: 
        - master
    matrix:
      include:
        - os: linux
          env: GIMME_OS=windows; GIMME_ARCH=amd64;
        - os: osx
    before_script:
      - go get -d -v ./...
    script:
      - go build -v ./...
    after_script:
      - go test -v ./...
    before_deploy: 
      - ./before_deploy.sh
    

    Note: the commande: - chmod +x ./before_deploy.sh can be directly done in your repository and commited on it ...

    Note: The environament variable can be accessibe: http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables or calling \printenv`

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题