Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect PHP version in Travis

Tags:

travis-ci

In my Travis file I have several PHP versions and a script entry like this:

php:
    - 5.6
    - 5.5
    - 5.4
    - 5.3

script:
    - export CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"
    - phpize #and lots of other stuff here.
    - make

I want to run the export CFLAGS line only when the PHP version matches 5.6.

I could theoretically do that with a nasty hack to detect the PHP version from the command line, but how can I do this through the Travis configuration script?

like image 812
Danack Avatar asked Feb 23 '15 14:02

Danack


People also ask

How to check PHP version in Windows?

Check PHP Version 1 Open the Command Prompt or Terminal. If you have PHP installed locally, you can use the Command Prompt or Terminal to check the version. ... 2 Enter the command to check the PHP version. When you run the command, the installed version of PHP will be displayed. 3 Fix the version not appearing in Windows. See More....

What PHP versions are supported by Travis CI?

Travis CI provides several PHP versions, all of which include XDebug and PHPUnit. Travis CI uses phpenv to manage the different PHP versions installed on the virtual machines. An example .travis.yml file that tests various PHP versions:

How do I check if a PHP file is compatible?

Then you can check compatibility of your code with specified PHP version using shell: find . -name *.php | xargs -n1 /usr/bin/php -l. php -l command runs PHP in syntax check only mode. The command above will check each PHP file in your project againts compatibility with PHP version located at /usr/bin/php.

What version of PHP do I have installed on my Mac?

Mac - Open Terminal from the Utilities folder. Linux - Open Terminal from the dash, or by pressing Ctrl + Alt + T. Enter the command to check the PHP version. When you run the command, the installed version of PHP will be displayed. Fix the version not appearing in Windows.


1 Answers

You can either use shell conditionals to do this:

php:
    - 5.6
    - 5.5
    - 5.4
    - 5.3

script:
    - if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.6" ]]; then export CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"; fi
    - phpize #and lots of other stuff here.
    - make

Or use the build matrix with explicit inclusions:

matrix:
    include:
      - php: 5.6
        env: CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"
      - php: 5.5
        env: CFLAGS=""
      - php: 5.4
        env: CFLAGS=""
      - php: 5.3
        env: CFLAGS=""

script:
    - phpize #and lots of other stuff here.
    - make

The latter is probably what you're looking for, the former is a little less verbose.

like image 84
Odi Avatar answered Dec 04 '22 03:12

Odi