在Travis中检测PHP版本

Dan*_*ack 4 travis-ci

在我的Travis文件中,我有几个PHP版本和一个这样的脚本条目:

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
Run Code Online (Sandbox Code Playgroud)

我想export CFLAGS只在PHP版本匹配5.6时运行该行.

理论上我可以用一个讨厌的黑客从命令行中检测PHP版本,但我怎么能通过Travis配置脚本​​来做到这一点?

Odi*_*Odi 11

您可以使用shell条件来执行此操作:

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
Run Code Online (Sandbox Code Playgroud)

或者使用带有显式包含的构建矩阵:

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
Run Code Online (Sandbox Code Playgroud)

后者可能是你正在寻找的,前者有点不那么冗长.