Browse Source

Travis CI: Use Build Stages

See https://docs.travis-ci.com/user/build-stages
Daniel Rudolf 8 years ago
parent
commit
df532e45bb

+ 46 - 32
.travis.yml

@@ -1,26 +1,56 @@
+dist: trusty
+sudo: false
+
 language: php
 language: php
-php:
-  - 5.4
-  - 5.5
-  - 5.6
-  - 7.0
-  - 7.1
-  - nightly
-  - hhvm
-  - hhvm-nightly
-
-matrix:
+
+cache:
+  directories:
+    - $HOME/.composer/cache/files
+
+jobs:
   include:
   include:
+    # Test stage
     - php: 5.3
     - php: 5.3
       dist: precise
       dist: precise
+    - php: 5.4
+    - php: 5.5
+    - php: 5.6
+    - php: 7.0
+    - php: 7.1
+    - php: nightly
+    - php: hhvm
+    - php: hhvm-nightly
+
+    # Deployment stage
+    - stage: deploy
+      install:
+        - '[ "$TRAVIS_PULL_REQUEST" == "false" ] || travis_terminate 0'
+        - '[[ ",$DEPLOY_PHPDOC_BRANCHES," == *,"$TRAVIS_BRANCH",* ]] || travis_terminate 0'
+        - install.sh
+      script:
+        - deploy-phpdoc-branch.sh
+
+    # Release stage
+    - stage: release
+      install:
+        - '[ -n "$TRAVIS_TAG" ] || travis_terminate 0'
+        - install.sh --release
+      script:
+        - deploy-phpdoc-release.sh
+      before_deploy:
+        - create-release-archive.sh "pico-release-$TRAVIS_TAG.tar.gz"
+      deploy:
+        provider: releases
+        api_key: ${GITHUB_OAUTH_TOKEN}
+        file: pico-release-$TRAVIS_TAG.tar.gz
+        skip_cleanup: true
+
+  # Ignore nightly build failures
   allow_failures:
   allow_failures:
     - php: nightly
     - php: nightly
     - php: hhvm-nightly
     - php: hhvm-nightly
   fast-finish: true
   fast-finish: true
 
 
-notifications:
-  irc: "chat.freenode.net#picocms"
-
 before_install:
 before_install:
   - export PATH="$TRAVIS_BUILD_DIR/_build:$PATH"
   - export PATH="$TRAVIS_BUILD_DIR/_build:$PATH"
 
 
@@ -33,21 +63,5 @@ before_script:
 script:
 script:
   - phpcs --standard=.phpcs.xml "$TRAVIS_BUILD_DIR"
   - phpcs --standard=.phpcs.xml "$TRAVIS_BUILD_DIR"
 
 
-after_success:
-  - deploy-phpdoc-branch.sh
-
-before_deploy:
-  - deploy-phpdoc-release.sh
-  - create-release-archive.sh "$TRAVIS_TAG"
-
-deploy:
-  provider: releases
-  api_key: ${GITHUB_OAUTH_TOKEN}
-  file: pico-release-$TRAVIS_TAG.tar.gz
-  skip_cleanup: true
-  on:
-    tags: true
-    php: 5.3
-
-dist: trusty
-sudo: false
+notifications:
+  irc: "chat.freenode.net#picocms"

+ 1 - 14
_build/create-release-archive.sh

@@ -1,19 +1,6 @@
 #!/usr/bin/env bash
 #!/usr/bin/env bash
 
 
-RELEASE="$1"
-ARCHIVE="pico-release.tar.gz"
-[ -n "$RELEASE" ] && ARCHIVE="pico-release-$RELEASE.tar.gz"
-
-# install dependencies
-echo "Running \`composer install\`..."
-composer install --no-dev --optimize-autoloader
-[ $? -eq 0 ] || exit 1
-echo
-
-# remove .git dirs
-echo "Removing '.git' directories of dependencies..."
-find vendor/ -type d -path 'vendor/*/*/.git' -print0 | xargs -0 rm -rf
-echo
+ARCHIVE="$1"
 
 
 # create release archive
 # create release archive
 echo "Creating release archive '$ARCHIVE'..."
 echo "Creating release archive '$ARCHIVE'..."

+ 1 - 16
_build/deploy-phpdoc-branch.sh

@@ -1,20 +1,5 @@
 #!/usr/bin/env bash
 #!/usr/bin/env bash
 
 
-if [ "$TRAVIS_PHP_VERSION" != "5.3" ]; then
-    echo "Skipping branch deployment because this is not on the required runtime"
-    exit 0
-fi
-
-if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
-    echo "Skipping branch deployment because this pull request (#$TRAVIS_PULL_REQUEST) is not permitted to deploy"
-    exit 0
-fi
-
-if [[ ",$DEPLOY_PHPDOC_BRANCHES," != *,"$TRAVIS_BRANCH",* ]]; then
-    echo "Skipping phpDoc branch deployment because this branch ($TRAVIS_BRANCH) is not permitted to deploy"
-    exit 0
-fi
-
 DEPLOYMENT_ID="${TRAVIS_BRANCH//\//_}"
 DEPLOYMENT_ID="${TRAVIS_BRANCH//\//_}"
 DEPLOYMENT_DIR="$TRAVIS_BUILD_DIR/_build/deploy-$DEPLOYMENT_ID.git"
 DEPLOYMENT_DIR="$TRAVIS_BUILD_DIR/_build/deploy-$DEPLOYMENT_ID.git"
 
 
@@ -51,7 +36,7 @@ update-phpdoc-list.sh \
 
 
 # commit phpDocs
 # commit phpDocs
 echo "Committing changes..."
 echo "Committing changes..."
-git add \
+git add --all \
     "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID.cache" "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" \
     "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID.cache" "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" \
     "$DEPLOYMENT_DIR/_data/phpDoc.yml"
     "$DEPLOYMENT_DIR/_data/phpDoc.yml"
 git commit \
 git commit \

+ 1 - 1
_build/deploy-phpdoc-release.sh

@@ -50,7 +50,7 @@ if [ "$DEPLOY_PHPDOC_RELEASES" == "true" ]; then
 
 
         # commit phpDocs
         # commit phpDocs
         echo "Committing phpDoc changes..."
         echo "Committing phpDoc changes..."
-        git add "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" "$DEPLOYMENT_DIR/_data/phpDoc.yml"
+        git add --all "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" "$DEPLOYMENT_DIR/_data/phpDoc.yml"
         git commit \
         git commit \
             --message="Update phpDocumentor class docs for $TRAVIS_TAG" \
             --message="Update phpDocumentor class docs for $TRAVIS_TAG" \
             "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" "$DEPLOYMENT_DIR/_data/phpDoc.yml"
             "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" "$DEPLOYMENT_DIR/_data/phpDoc.yml"

+ 6 - 3
_build/github-deploy.sh

@@ -16,6 +16,9 @@ CHECK_REPO_SLUG="$1"        # optional GitHub repo (e.g. picocms/Pico) to check
 CHECK_REMOTE_REF="$2"       # optional remote Git reference (e.g. heads/master)
 CHECK_REMOTE_REF="$2"       # optional remote Git reference (e.g. heads/master)
 CHECK_LOCAL_COMMIT="$3"     # optional local commit SHA1
 CHECK_LOCAL_COMMIT="$3"     # optional local commit SHA1
 
 
+# environment variables
+# GITHUB_OAUTH_TOKEN    GitHub authentication token, see https://github.com/settings/tokens
+
 # print parameters
 # print parameters
 echo "Deploying repo..."
 echo "Deploying repo..."
 printf 'CHECK_REPO_SLUG="%s"\n' "$CHECK_REPO_SLUG"
 printf 'CHECK_REPO_SLUG="%s"\n' "$CHECK_REPO_SLUG"
@@ -34,12 +37,12 @@ fi
 # but it should give a basic protection without disabling concurrent builds completely
 # but it should give a basic protection without disabling concurrent builds completely
 if [ -n "$CHECK_REPO_SLUG" ] && [ -n "$CHECK_REMOTE_REF" ] && [ -n "$CHECK_LOCAL_COMMIT" ]; then
 if [ -n "$CHECK_REPO_SLUG" ] && [ -n "$CHECK_REMOTE_REF" ] && [ -n "$CHECK_LOCAL_COMMIT" ]; then
     # retrieve information using GitHub APIv3
     # retrieve information using GitHub APIv3
-    printf 'Checking latest commit...\n'
+    echo "Checking latest commit$([ -n "$GITHUB_OAUTH_TOKEN" ] && echo " (authorized)")..."
     CHECK_API_URL="https://api.github.com/repos/$CHECK_REPO_SLUG/git/refs/$CHECK_REMOTE_REF"
     CHECK_API_URL="https://api.github.com/repos/$CHECK_REPO_SLUG/git/refs/$CHECK_REMOTE_REF"
     if [ -n "$GITHUB_OAUTH_TOKEN" ]; then
     if [ -n "$GITHUB_OAUTH_TOKEN" ]; then
-        CHECK_API_RESPONSE="$(wget -O- --header="Authorization: token $GITHUB_OAUTH_TOKEN" "$CHECK_API_URL" 2> /dev/null)"
+        CHECK_API_RESPONSE="$(curl --fail --silent --show-error --header "Authorization: token $GITHUB_OAUTH_TOKEN" "$CHECK_API_URL")"
     else
     else
-        CHECK_API_RESPONSE="$(wget -O- "$CHECK_API_URL" 2> /dev/null)"
+        CHECK_API_RESPONSE="$(curl --fail --silent --show-error "$CHECK_API_URL")"
     fi
     fi
 
 
     # evaluate JSON response
     # evaluate JSON response

+ 16 - 1
_build/install.sh

@@ -1,6 +1,19 @@
 #!/usr/bin/env bash
 #!/usr/bin/env bash
 
 
-set -e
+if [ "$1" == "--release" ]; then
+    # install dependencies
+    echo "Running \`composer install\`..."
+    composer install --no-dev --optimize-autoloader
+    [ $? -eq 0 ] || exit 1
+    echo
+
+    # remove .git dirs
+    echo "Removing '.git' directories of dependencies..."
+    find vendor/ -type d -path 'vendor/*/*/.git' -print0 | xargs -0 rm -rf
+    echo
+
+    exit 0
+fi
 
 
 # set COMPOSER_ROOT_VERSION when necessary
 # set COMPOSER_ROOT_VERSION when necessary
 if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -z "$TRAVIS_TAG" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
 if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -z "$TRAVIS_TAG" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
@@ -28,3 +41,5 @@ fi
 # install dependencies
 # install dependencies
 echo "Running \`composer install\`$([ -n "$COMPOSER_ROOT_VERSION" ] && echo -n " ($COMPOSER_ROOT_VERSION)")..."
 echo "Running \`composer install\`$([ -n "$COMPOSER_ROOT_VERSION" ] && echo -n " ($COMPOSER_ROOT_VERSION)")..."
 composer install
 composer install
+
+exit $?