From 722de2a1e54518f96773fe34516c8aa140ce1a20 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sat, 2 Dec 2017 17:17:41 +0100 Subject: [PATCH] Build system: Refactor scripts to use picocms/ci-tools --- {_build => .build}/create-release.sh | 16 +++------ .build/deploy-branch.sh | 44 +++++++++++++++++++++++ {_build => .build}/deploy-release.sh | 54 +++++++++++++--------------- {_build => .build}/deploy.sh | 2 +- {_build => .build}/install.sh | 10 +++--- .gitattributes | 2 +- .travis.yml | 5 ++- _build/.gitignore | 4 --- _build/deploy-branch.sh | 50 -------------------------- 9 files changed, 84 insertions(+), 103 deletions(-) rename {_build => .build}/create-release.sh (78%) create mode 100755 .build/deploy-branch.sh rename {_build => .build}/deploy-release.sh (57%) rename {_build => .build}/deploy.sh (76%) rename {_build => .build}/install.sh (74%) delete mode 100644 _build/.gitignore delete mode 100755 _build/deploy-branch.sh diff --git a/_build/create-release.sh b/.build/create-release.sh similarity index 78% rename from _build/create-release.sh rename to .build/create-release.sh index d9f21d6..152825e 100755 --- a/_build/create-release.sh +++ b/.build/create-release.sh @@ -2,13 +2,7 @@ set -e . "$(dirname "$0")/tools/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" +export PATH="$PICO_TOOLS_DIR:$PATH" # parameters ARCHIVE="$1" # release archive file name @@ -19,15 +13,15 @@ if [ -z "$ARCHIVE" ]; then fi # parse version -if ! parse_version "$TRAVIS_TAG"; then - echo "Unable to create release archive: Invalid version '$TRAVIS_TAG'" >&2 +if ! parse_version "$PROJECT_REPO_TAG"; then + echo "Unable to create release archive: Invalid version '$PROJECT_REPO_TAG'" >&2 exit 1 fi # clone repo -github-clone.sh "$DEPLOYMENT_DIR" "https://github.com/$RELEASE_REPO_SLUG.git" "$RELEASE_REPO_BRANCH" +github-clone.sh "$PICO_BUILD_DIR" "https://github.com/$RELEASE_REPO_SLUG.git" "$RELEASE_REPO_BRANCH" -cd "$DEPLOYMENT_DIR" +cd "$PICO_BUILD_DIR" # force Pico version echo "Updating composer dependencies..." diff --git a/.build/deploy-branch.sh b/.build/deploy-branch.sh new file mode 100755 index 0000000..3917aa1 --- /dev/null +++ b/.build/deploy-branch.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -e + +export PATH="$PICO_TOOLS_DIR:$PATH" + +# get current Pico milestone +VERSION="$(php -r "require_once('$PICO_PROJECT_DIR/lib/Pico.php'); echo Pico::VERSION;")" +MILESTONE="Pico$([[ "$VERSION" =~ ^([0-9]+\.[0-9]+)\. ]] && echo " ${BASH_REMATCH[1]}")" + +echo "Deploying $PROJECT_REPO_BRANCH branch ($MILESTONE)..." +echo + +# clone repo +github-clone.sh "$PICO_DEPLOY_DIR" "https://github.com/$DEPLOY_REPO_SLUG.git" "$DEPLOY_REPO_BRANCH" + +cd "$PICO_DEPLOY_DIR" + +# setup repo +github-setup.sh + +# generate phpDocs +generate-phpdoc.sh \ + "$PICO_PROJECT_DIR/.phpdoc.xml" \ + "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT.cache" "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT" \ + "$MILESTONE API Documentation ($PROJECT_REPO_BRANCH branch)" + +if [ -z "$(git status --porcelain "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT.cache")" ]; then + # nothing to do + exit 0 +fi + +# update phpDoc list +update-phpdoc-list.sh \ + "$PICO_DEPLOY_DIR/_data/phpDoc.yml" \ + "$PICO_DEPLOYMENT" "branch" "$PROJECT_REPO_BRANCH branch" "$(date +%s)" + +# commit phpDocs +github-commit.sh \ + "Update phpDocumentor class docs for $PROJECT_REPO_BRANCH branch @ $PROJECT_REPO_COMMIT" \ + "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT.cache" "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT" \ + "$PICO_DEPLOY_DIR/_data/phpDoc.yml" + +# deploy phpDocs +github-deploy.sh "$PROJECT_REPO_SLUG" "heads/$PROJECT_REPO_BRANCH" "$PROJECT_REPO_COMMIT" diff --git a/_build/deploy-release.sh b/.build/deploy-release.sh similarity index 57% rename from _build/deploy-release.sh rename to .build/deploy-release.sh index 48f3209..d2a61a1 100755 --- a/_build/deploy-release.sh +++ b/.build/deploy-release.sh @@ -32,17 +32,11 @@ if [ "$DEPLOY_FULL" != "true" ]; then fi . "$(dirname "$0")/tools/functions/parse-version.sh.inc" -export PATH="$(dirname "$0")/tools:$PATH" - -DEPLOYMENT_ID="${TRAVIS_TAG//\//_}" -DEPLOYMENT_DIR="$TRAVIS_BUILD_DIR/_build/deploy-$DEPLOYMENT_ID.git" - -[ -n "$DEPLOY_REPO_SLUG" ] || export DEPLOY_REPO_SLUG="$TRAVIS_REPO_SLUG" -[ -n "$DEPLOY_REPO_BRANCH" ] || export DEPLOY_REPO_BRANCH="gh-pages" +export PATH="$PICO_TOOLS_DIR:$PATH" # parse version -if ! parse_version "$TRAVIS_TAG"; then - echo "Invalid version '$TRAVIS_TAG'; aborting..." >&2 +if ! parse_version "$PROJECT_REPO_TAG"; then + echo "Invalid version '$PROJECT_REPO_TAG'; aborting..." >&2 exit 1 fi @@ -53,9 +47,9 @@ printf 'VERSION_ID="%s"\n' "$VERSION_ID" echo # clone repo -github-clone.sh "$DEPLOYMENT_DIR" "https://github.com/$DEPLOY_REPO_SLUG.git" "$DEPLOY_REPO_BRANCH" +github-clone.sh "$PICO_DEPLOY_DIR" "https://github.com/$DEPLOY_REPO_SLUG.git" "$DEPLOY_REPO_BRANCH" -cd "$DEPLOYMENT_DIR" +cd "$PICO_DEPLOY_DIR" # setup repo github-setup.sh @@ -64,20 +58,20 @@ github-setup.sh if [ "$DEPLOY_PHPDOC_RELEASES" == "true" ]; then # generate phpDocs generate-phpdoc.sh \ - "$TRAVIS_BUILD_DIR/.phpdoc.xml" \ - "-" "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" \ - "Pico $VERSION_MILESTONE API Documentation ($TRAVIS_TAG)" + "$PICO_PROJECT_DIR/.phpdoc.xml" \ + "-" "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT" \ + "Pico $VERSION_MILESTONE API Documentation (v$VERSION_FULL)" - if [ -n "$(git status --porcelain "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID")" ]; then + if [ -n "$(git status --porcelain "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT")" ]; then # update phpDoc list update-phpdoc-list.sh \ - "$DEPLOYMENT_DIR/_data/phpDoc.yml" \ - "$TRAVIS_TAG" "version" "Pico ${TRAVIS_TAG#v}" "$(date +%s)" + "$PICO_DEPLOY_DIR/_data/phpDoc.yml" \ + "$PICO_DEPLOYMENT" "version" "Pico $VERSION_FULL" "$(date +%s)" # commit phpDocs github-commit.sh \ - "Update phpDocumentor class docs for $TRAVIS_TAG" \ - "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" "$DEPLOYMENT_DIR/_data/phpDoc.yml" + "Update phpDocumentor class docs for v$VERSION_FULL" \ + "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT" "$PICO_DEPLOY_DIR/_data/phpDoc.yml" fi fi @@ -86,37 +80,37 @@ if [ "$VERSION_STABILITY" == "stable" ]; then # update version badge if [ "$DEPLOY_VERSION_BADGE" == "true" ]; then generate-badge.sh \ - "$DEPLOYMENT_DIR/badges/pico-version.svg" \ - "release" "$TRAVIS_TAG" "blue" + "$PICO_DEPLOY_DIR/badges/pico-version.svg" \ + "release" "$VERSION_FULL" "blue" # commit version badge github-commit.sh \ - "Update version badge for $TRAVIS_TAG" \ - "$DEPLOYMENT_DIR/badges/pico-version.svg" + "Update version badge for v$VERSION_FULL" \ + "$PICO_DEPLOY_DIR/badges/pico-version.svg" fi # update version file if [ "$DEPLOY_VERSION_FILE" == "true" ]; then update-version-file.sh \ - "$DEPLOYMENT_DIR/_data/version.yml" \ + "$PICO_DEPLOY_DIR/_data/version.yml" \ "$VERSION_FULL" # commit version file github-commit.sh \ - "Update version file for $TRAVIS_TAG" \ - "$DEPLOYMENT_DIR/_data/version.yml" + "Update version file for v$VERSION_FULL" \ + "$PICO_DEPLOY_DIR/_data/version.yml" fi # update cloc statistics if [ "$DEPLOY_CLOC_STATS" == "true" ]; then - update-cloc-stats.sh "$DEPLOYMENT_DIR/_data/cloc.yml" + update-cloc-stats.sh "$PICO_DEPLOY_DIR/_data/cloc.yml" # commit cloc statistics github-commit.sh \ - "Update cloc statistics for $TRAVIS_TAG" \ - "$DEPLOYMENT_DIR/_data/cloc.yml" + "Update cloc statistics for v$VERSION_FULL" \ + "$PICO_DEPLOY_DIR/_data/cloc.yml" fi fi # deploy -github-deploy.sh "$TRAVIS_REPO_SLUG" "tags/$TRAVIS_TAG" "$TRAVIS_COMMIT" +github-deploy.sh "$PROJECT_REPO_SLUG" "tags/$PROJECT_REPO_TAG" "$PROJECT_REPO_COMMIT" diff --git a/_build/deploy.sh b/.build/deploy.sh similarity index 76% rename from _build/deploy.sh rename to .build/deploy.sh index 3d5e4b5..0ef0c10 100755 --- a/_build/deploy.sh +++ b/.build/deploy.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -if [ -n "$TRAVIS_TAG" ]; then +if [ -n "$PROJECT_REPO_TAG" ]; then exec "$(dirname "$0")/deploy-release.sh" else exec "$(dirname "$0")/deploy-branch.sh" diff --git a/_build/install.sh b/.build/install.sh similarity index 74% rename from _build/install.sh rename to .build/install.sh index dee3ee5..713f521 100755 --- a/_build/install.sh +++ b/.build/install.sh @@ -21,19 +21,19 @@ if [ -n "$GITHUB_OAUTH_TOKEN" ]; then fi # set COMPOSER_ROOT_VERSION when necessary -if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -z "$TRAVIS_TAG" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then +if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -n "$PROJECT_REPO_BRANCH" ]; then PICO_VERSION_PATTERN="$(php -r " - \$json = json_decode(file_get_contents('$TRAVIS_BUILD_DIR/composer.json'), true); + \$json = json_decode(file_get_contents('$PICO_PROJECT_DIR/composer.json'), true); if (\$json !== null) { - if (isset(\$json['extra']['branch-alias']['dev-$TRAVIS_BRANCH'])) { - echo 'dev-$TRAVIS_BRANCH'; + if (isset(\$json['extra']['branch-alias']['dev-$PROJECT_REPO_BRANCH'])) { + echo 'dev-$PROJECT_REPO_BRANCH'; } } ")" if [ -z "$PICO_VERSION_PATTERN" ]; then PICO_VERSION_PATTERN="$(php -r " - require_once('$TRAVIS_BUILD_DIR/lib/Pico.php'); + require_once('$PICO_PROJECT_DIR/lib/Pico.php'); echo preg_replace('/\.[0-9]+-dev$/', '.x-dev', Pico::VERSION); ")" fi diff --git a/.gitattributes b/.gitattributes index 0d8d494..447d4c6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ -/_build export-ignore +/.build export-ignore /assets/.gitignore export-ignore /config/.gitignore export-ignore /content/.gitignore export-ignore diff --git a/.travis.yml b/.travis.yml index 9b2f71d..e2c041e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,10 @@ jobs: fast-finish: true before_install: - - export PATH="$TRAVIS_BUILD_DIR/_build:$PATH" + - export PATH="$TRAVIS_BUILD_DIR/.build:$PATH" + - export PICO_TOOLS_DIR="$HOME/__picocms_tools" + - git clone --branch="$TOOLS_REPO_BRANCH" "https://github.com/$TOOLS_REPO_SLUG.git" "$PICO_TOOLS_DIR" + - . "$PICO_TOOLS_DIR/init/travis.sh.inc" install: - install.sh diff --git a/_build/.gitignore b/_build/.gitignore deleted file mode 100644 index 41c43ff..0000000 --- a/_build/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore temporary directories created while building/deploying Pico -/phpdoc -/phpdoc.cache -/deploy-*.git diff --git a/_build/deploy-branch.sh b/_build/deploy-branch.sh deleted file mode 100755 index 8301932..0000000 --- a/_build/deploy-branch.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash -set -e - -export PATH="$(dirname "$0")/tools:$PATH" - -DEPLOYMENT_ID="${TRAVIS_BRANCH//\//_}" -DEPLOYMENT_DIR="$TRAVIS_BUILD_DIR/_build/deploy-$DEPLOYMENT_ID.git" - -[ -n "$DEPLOY_REPO_SLUG" ] || export DEPLOY_REPO_SLUG="$TRAVIS_REPO_SLUG" -[ -n "$DEPLOY_REPO_BRANCH" ] || export DEPLOY_REPO_BRANCH="gh-pages" - -# get current Pico milestone -VERSION="$(php -r 'require_once(__DIR__ . "/lib/Pico.php"); echo Pico::VERSION;')" -MILESTONE="Pico$([[ "$VERSION" =~ ^([0-9]+\.[0-9]+)\. ]] && echo " ${BASH_REMATCH[1]}")" - -echo "Deploying $TRAVIS_BRANCH branch ($MILESTONE)..." -echo - -# clone repo -github-clone.sh "$DEPLOYMENT_DIR" "https://github.com/$DEPLOY_REPO_SLUG.git" "$DEPLOY_REPO_BRANCH" - -cd "$DEPLOYMENT_DIR" - -# setup repo -github-setup.sh - -# generate phpDocs -generate-phpdoc.sh \ - "$TRAVIS_BUILD_DIR/.phpdoc.xml" \ - "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID.cache" "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" \ - "$MILESTONE API Documentation ($TRAVIS_BRANCH branch)" - -if [ -z "$(git status --porcelain "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID.cache")" ]; then - # nothing to do - exit 0 -fi - -# update phpDoc list -update-phpdoc-list.sh \ - "$DEPLOYMENT_DIR/_data/phpDoc.yml" \ - "$TRAVIS_BRANCH" "branch" "$TRAVIS_BRANCH branch" "$(date +%s)" - -# commit phpDocs -github-commit.sh \ - "Update phpDocumentor class docs for $TRAVIS_BRANCH branch @ $TRAVIS_COMMIT" \ - "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID.cache" "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" \ - "$DEPLOYMENT_DIR/_data/phpDoc.yml" - -# deploy phpDocs -github-deploy.sh "$TRAVIS_REPO_SLUG" "heads/$TRAVIS_BRANCH" "$TRAVIS_COMMIT"