From 66cc087b6e2c4568528f760f7591f81b863df18d Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 14 Jun 2017 01:44:09 +0200 Subject: [PATCH] Travis CI: Explicitly set root package version for branches Due to the fact that Travis uses a shallow clone of Pico's Git repo, composer has no chance to detect on which branch it currently is. This was no big deal with Pico 1.0, however, Pico 2.0 depends on picocms/pico-deprecated and picocms/pico-theme. We use composer's `self.version` version constraint to sync the version numbers of these separate Git repos. Thus composer must know Pico's current version to resolve these dependencies. We try to guess the current version either using known branch aliases in Pico's `composer.json`, or using the `Pico::VERSION` constant (see `_build/install.sh`). --- .travis.yml | 7 +++++-- _build/install.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100755 _build/install.sh diff --git a/.travis.yml b/.travis.yml index fd14373..7fdc791 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,11 +21,14 @@ matrix: notifications: irc: "chat.freenode.net#picocms" +before_install: + - export PATH="$TRAVIS_BUILD_DIR/_build:$PATH" + install: - - composer install + - install.sh before_script: - - export PATH="$TRAVIS_BUILD_DIR/_build:$TRAVIS_BUILD_DIR/vendor/bin:$PATH" + - export PATH="$TRAVIS_BUILD_DIR/vendor/bin:$PATH" script: - phpcs --standard=.phpcs.xml "$TRAVIS_BUILD_DIR" diff --git a/_build/install.sh b/_build/install.sh new file mode 100755 index 0000000..b40f7e8 --- /dev/null +++ b/_build/install.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e + +# set COMPOSER_ROOT_VERSION when necessary +if [ -z "$TRAVIS_TAG" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + PICO_VERSION_PATTERN="$(php -r " + \$json = json_decode(file_get_contents('$TRAVIS_BUILD_DIR/composer.json'), true); + if (\$json !== null) { + if (isset(\$json['extra']['branch-alias']['dev-$TRAVIS_BRANCH'])) { + echo 'dev-$TRAVIS_BRANCH'; + } + } + ")" + + if [ -z "$PICO_VERSION_PATTERN" ]; then + PICO_VERSION_PATTERN="$(php -r " + require_once('$TRAVIS_BUILD_DIR/lib/Pico.php'); + echo preg_replace('/\.[0-9]+-dev$/', '.x-dev', Pico::VERSION); + ")" + fi + + if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -n "$PICO_VERSION_PATTERN" ]; then + export COMPOSER_ROOT_VERSION="$PICO_VERSION_PATTERN" + fi +fi + +# install dependencies +echo "Running \`composer install\`$([ -n "$COMPOSER_ROOT_VERSION" ] && echo -n " ($COMPOSER_ROOT_VERSION)")..." +composer install