Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

before_install in a build matrix

Tags:

travis-ci

I have a program which needs to be built for multiple platforms. Right now I'm doing something like:

matrix:
  include:
    env: PLATFORM=foo
    env: PLATFORM=bar
    env: PLATFORM=baz
before_install:
  - install foo toolchain
  - install bar toolchain
  - install baz toolchain
script:
  - make PLATFORM=$PLATFORM

I'd rather not install all three toolchains given that I'm only going to be using one; it's wasteful of resources and also breaks all the builds when upstream's terrible toolchain distribution site goes down.

However, I can't figure out a way to get a before_install in the build matrix --- the documentation is desperately unclear as to the precise syntax. Is this possible, and if so, how?

like image 226
David Given Avatar asked Oct 28 '15 22:10

David Given


People also ask

What is a matrix build?

A build matrix is made up by several multiple jobs that run in parallel. This can be useful in many cases, but the two primary reasons to use a build matrix are: Reducing the overall build execution time. Running tests against different versions of runtimes or dependencies.


1 Answers

In this particular example, you could simply leverage the environment variable you've already created to dynamically expand the install command.

matrix:
  include:
    env: PLATFORM=foo
    env: PLATFORM=bar
    env: PLATFORM=baz
before_install:
  - install $PLATFORM toolchain
script:
  - make PLATFORM=$PLATFORM

For others that may find this question searching for a more complicated scenario, such as supporting ancient platforms inconsistent with modern travis environments, I manage matrix differential installs with dedicated scripts.

.
├── src
│   └── Foo.php
├── tests
│   ├── FooTest.php
│   └── travis
│       ├── install.bash
│       ├── install.legacy.bash
│       ├── script.bash
│       └── script.legacy.bash
└── .travis.yml

Then source the respective scripts for the environment.

language: php
matrix:
  include:
  - php: "nightly"
    env: LEGACY=false
  - php: "7.0"
    env: LEGACY=false
  - php: "5.3.3"
    env: LEGACY=true
install:
  - if $LEGACY; then source ./tests/travis/install.legacy.bash;
    else source ./tests/travis/install.bash; fi
script:
  - if $LEGACY; then source ./tests/travis/script.legacy.bash;
    else source ./tests/travis/script.bash; fi

Pretty ugly, so I hope travis provides an official solution sometime.

like image 86
Jeff Puckett Avatar answered Oct 13 '22 01:10

Jeff Puckett