From 1dee2c1cf685552308b88ca6274865fffb01c1dc Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 22 Oct 2017 21:27:19 +0200 Subject: [PATCH] Build system: Use 'picocms/pico-composer' to create release archives --- .travis.yml | 4 +-- _build/create-release.sh | 76 ++++++++++++++++++++++++++++++++++++++++ _build/install.sh | 15 -------- 3 files changed, 78 insertions(+), 17 deletions(-) create mode 100755 _build/create-release.sh diff --git a/.travis.yml b/.travis.yml index 9b6f8e4..ce4c2bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,11 +34,11 @@ jobs: - stage: release install: - '[ -n "$TRAVIS_TAG" ] || travis_terminate 0' - - install.sh --release + - install.sh script: - deploy-release.sh before_deploy: - - create-release-archive.sh "pico-release-$TRAVIS_TAG.tar.gz" + - create-release.sh "pico-release-$TRAVIS_TAG.tar.gz" deploy: provider: releases api_key: ${GITHUB_OAUTH_TOKEN} diff --git a/_build/create-release.sh b/_build/create-release.sh new file mode 100755 index 0000000..41acc3a --- /dev/null +++ b/_build/create-release.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +set -e + +. "$(dirname "$0")/functions/parse-version.sh.inc" +export PATH="$(dirname "$0")/tools:$PATH" + +DEPLOYMENT_ID="${TRAVIS_TAG//\//_}" +DEPLOYMENT_DIR="$TRAVIS_BUILD_DIR/_build/release-$DEPLOYMENT_ID.git" + +[ -n "$RELEASE_REPO_SLUG" ] || export RELEASE_REPO_SLUG="$TRAVIS_REPO_SLUG" +[ -n "$RELEASE_REPO_BRANCH" ] || export RELEASE_REPO_BRANCH="master" + +# parameters +ARCHIVE="$1" # release archive file name + +if [ -z "$ARCHIVE" ]; then + echo "Unable to create release archive: No file name specified" >&2 + exit 1 +fi + +# parse version +if ! parse_version "$TRAVIS_TAG"; then + echo "Unable to create release archive: Invalid version '$TRAVIS_TAG'" >&2 + exit 1 +fi + +# clone repo +github-clone.sh "$DEPLOYMENT_DIR" "https://github.com/$RELEASE_REPO_SLUG.git" "$RELEASE_REPO_BRANCH" + +cd "$DEPLOYMENT_DIR" + +# force Pico version +echo "Updating composer dependencies..." +composer require --no-update \ + "picocms/pico $VERSION_FULL@$VERSION_STABILITY" \ + "picocms/pico-theme $VERSION_FULL@$VERSION_STABILITY" \ + "picocms/pico-deprecated $VERSION_FULL@$VERSION_STABILITY" +echo + +# install dependencies +echo "Running \`composer install\`..." +composer install --no-suggest --prefer-dist --no-dev --optimize-autoloader +echo + +# prepare release +echo "Replacing 'index.php'..." +cp vendor/picocms/pico/index.php.dist index.php + +echo "Preparing 'composer.json' for release..." +composer require --no-update \ + "picocms/pico ^$VERSION_MILESTONE" \ + "picocms/pico-theme ^$VERSION_MILESTONE" \ + "picocms/pico-deprecated ^$VERSION_MILESTONE" + +echo "Removing '.git' directory and '.gitignore' file..." +rm -f .gitignore +rm -rf .git + +echo "Removing '.git' directories of dependencies..." +find vendor/ -type d -path 'vendor/*/*/.git' -print0 | xargs -0 rm -rf +find themes/ -type d -path 'themes/*/.git' -print0 | xargs -0 rm -rf +find plugins/ -type d -path 'plugins/*/.git' -print0 | xargs -0 rm -rf + +echo + +# create release archive +echo "Creating release archive '$ARCHIVE'..." + +if [ -e "$ARCHIVE" ]; then + echo "Unable to create release archive: File exists" >&2 + exit 1 +fi + +find . -mindepth 1 -maxdepth 1 -printf '%f\0' \ + | xargs -0 -- tar -czf "$ARCHIVE" -- +echo diff --git a/_build/install.sh b/_build/install.sh index a345371..f352c89 100755 --- a/_build/install.sh +++ b/_build/install.sh @@ -5,21 +5,6 @@ if [ -n "$GITHUB_OAUTH_TOKEN" ]; then composer config --global github-oauth.github.com "$GITHUB_OAUTH_TOKEN" fi -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 if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -z "$TRAVIS_TAG" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then PICO_VERSION_PATTERN="$(php -r "