Procházet zdrojové kódy

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`).
Daniel Rudolf před 8 roky
rodič
revize
66cc087b6e
2 změnil soubory, kde provedl 35 přidání a 2 odebrání
  1. 5 2
      .travis.yml
  2. 30 0
      _build/install.sh

+ 5 - 2
.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"

+ 30 - 0
_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