From 17dbc4cf186c926625d179ed5611430fc2a265d6 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 26 Nov 2015 00:29:14 +0100 Subject: [PATCH] phpDocs auto deployment: Cleanup --- .travis.yml | 17 +++-------------- build/deploy-phpdoc-branch.sh | 28 ++++++++++++++++++++++++++++ build/deploy-phpdoc-release.sh | 15 +++++++++++++++ build/deploy-phpdoc.sh | 28 ++++++++++++++++------------ 4 files changed, 62 insertions(+), 26 deletions(-) create mode 100755 build/deploy-phpdoc-branch.sh create mode 100755 build/deploy-phpdoc-release.sh diff --git a/.travis.yml b/.travis.yml index bdd1e82..8e87356 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,27 +17,16 @@ install: - composer install before_script: - - export PATH="$TRAVIS_BUILD_DIR/vendor/bin:$PATH" + - export PATH="$TRAVIS_BUILD_DIR/build:$TRAVIS_BUILD_DIR/vendor/bin:$PATH" script: - find . -not \( -path './vendor' -prune \) -type f -name '*.php' -print0 | xargs -0 -I file php -l file > /dev/null after_success: - - | - [ "$TRAVIS_PHP_VERSION" != "5.3" ] && echo "Skipping phpDoc deployment because this is not on the required runtime" && exit - [[ ",$DEPLOY_PHPDOC_BRANCHES," != *,"$TRAVIS_BRANCH",* ]] && echo "Skipping phpDoc deployment because this branch is not permitted to deploy" && exit - [ "$TRAVIS_SECURE_ENV_VARS" != "true" ] && echo "Skipping phpDoc deployment because this is no environment with write access to the repository" && exit - PHPDOC_ID="${TRAVIS_BRANCH//\//_}" - ./build/generate-phpdoc.sh "$TRAVIS_BUILD_DIR" "$TRAVIS_BUILD_DIR/build/phpdoc-$PHPDOC_ID" "Pico 1.0 API Documentation ($TRAVIS_BRANCH branch)" || exit 1 - ./build/deploy-phpdoc.sh "$TRAVIS_REPO_SLUG" "$TRAVIS_BUILD_DIR/build/phpdoc-$PHPDOC_ID" "$TRAVIS_BRANCH @ $TRAVIS_COMMIT" "phpDoc/$PHPDOC_ID" "gh-pages" || exit 1 + - deploy-phpdoc-branch.sh before_deploy: - - | - [ "$DEPLOY_PHPDOC_TAGS" == "true" ] && ( - PHPDOC_ID="${TRAVIS_BRANCH//\//_}" - ./build/generate-phpdoc.sh "$TRAVIS_BUILD_DIR" "$TRAVIS_BUILD_DIR/build/phpdoc-$PHPDOC_ID" "Pico 1.0 API Documentation ($TRAVIS_TAG)" || exit 1 - ./build/deploy-phpdoc.sh "$TRAVIS_REPO_SLUG" "$TRAVIS_BUILD_DIR/build/phpdoc-$PHPDOC_ID" "$TRAVIS_TAG" "phpDoc/$PHPDOC_ID" "gh-pages" || exit 1 - ) + - deploy-phpdoc-release.sh - composer install --no-dev --optimize-autoloader - tar -czf "pico-release-$TRAVIS_TAG.tar.gz" README.md LICENSE CONTRIBUTING.md CHANGELOG.md composer.json composer.lock config content-sample lib plugins themes vendor .htaccess index.php diff --git a/build/deploy-phpdoc-branch.sh b/build/deploy-phpdoc-branch.sh new file mode 100755 index 0000000..2a401a4 --- /dev/null +++ b/build/deploy-phpdoc-branch.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +if [ "$TRAVIS_PHP_VERSION" != "5.3" ]; then + echo "Skipping phpDoc deployment because this is not on the required runtime" + exit +fi + +if [[ ",$DEPLOY_PHPDOC_BRANCHES," != *,"$TRAVIS_BRANCH",* ]]; then + echo "Skipping phpDoc deployment because this branch is not permitted to deploy" + exit +fi + +if [ "$TRAVIS_SECURE_ENV_VARS" != "true" ]; then + echo "Skipping phpDoc deployment because this is no environment with write access to the repository" + exit +fi + +PHPDOC_ID="${TRAVIS_BRANCH//\//_}" + +generate-phpdoc.sh \ + "$TRAVIS_BUILD_DIR" "$TRAVIS_BUILD_DIR/build/phpdoc-$PHPDOC_ID" \ + "Pico 1.0 API Documentation ($TRAVIS_BRANCH branch)" +[ $? -eq 0 ] || exit 1 + +deploy-phpdoc.sh \ + "$TRAVIS_REPO_SLUG" "$TRAVIS_BRANCH @ $TRAVIS_COMMIT" "$TRAVIS_BUILD_DIR/build/phpdoc-$PHPDOC_ID" \ + "$TRAVIS_REPO_SLUG" "gh-pages" "phpDoc/$PHPDOC_ID" +[ $? -eq 0 ] || exit 1 diff --git a/build/deploy-phpdoc-release.sh b/build/deploy-phpdoc-release.sh new file mode 100755 index 0000000..6604ba6 --- /dev/null +++ b/build/deploy-phpdoc-release.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +[ "$DEPLOY_PHPDOC_RELEASES" == "true" ] || exit + +PHPDOC_ID="${TRAVIS_BRANCH//\//_}" + +generate-phpdoc.sh \ + "$TRAVIS_BUILD_DIR" "$TRAVIS_BUILD_DIR/build/phpdoc-$PHPDOC_ID" \ + "Pico 1.0 API Documentation ($TRAVIS_TAG)" +[ $? -eq 0 ] || exit 1 + +deploy-phpdoc.sh \ + "$TRAVIS_REPO_SLUG" "$TRAVIS_TAG" "$TRAVIS_BUILD_DIR/build/phpdoc-$PHPDOC_ID" \ + "$TRAVIS_REPO_SLUG" "gh-pages" "phpDoc/$PHPDOC_ID" +[ $? -eq 0 ] || exit 1 diff --git a/build/deploy-phpdoc.sh b/build/deploy-phpdoc.sh index bede6f0..85dcddb 100755 --- a/build/deploy-phpdoc.sh +++ b/build/deploy-phpdoc.sh @@ -1,25 +1,29 @@ #!/usr/bin/env bash +set -e + +# base variables APP_NAME="$(basename "$0")" BASE_PWD="$PWD" -set -e # environment variables # GITHUB_OAUTH_TOKEN GitHub authentication token, see https://github.com/settings/tokens # parameters -GITHUB_SLUG="$1" # GitHub repo (e.g. picocms/Pico) -SOURCE_DIR="$2" # absolute source path -SOURCE_REF="$3" # source reference (either [branch]@[commit], [branch] or [tag]) -TARGET_DIR="$4" # relative target path +SOURCE_REPO_SLUG="$1" # source GitHub repo (e.g. picocms/Pico) +SOURCE_REF="$2" # source reference (either [branch]@[commit], [branch] or [tag]) +SOURCE_DIR="$3" # absolute source path +TARGET_REPO_SLUG="$4" # target GitHub repo (e.g. picocms/Pico) TARGET_BRANCH="$5" # target branch (e.g. gh-pages) +TARGET_DIR="$6" # relative target path # print parameters echo "Deploying phpDocs..." -printf 'GITHUB_SLUG="%s"\n' "$GITHUB_SLUG" -printf 'SOURCE_DIR="%s"\n' "$SOURCE_DIR" +printf 'SOURCE_REPO_SLUG="%s"\n' "$SOURCE_REPO_SLUG" printf 'SOURCE_REF="%s"\n' "$SOURCE_REF" -printf 'TARGET_DIR="%s"\n' "$TARGET_DIR" +printf 'SOURCE_DIR="%s"\n' "$SOURCE_DIR" +printf 'TARGET_REPO_SLUG="%s"\n' "$TARGET_REPO_SLUG" printf 'TARGET_BRANCH="%s"\n' "$TARGET_BRANCH" +printf 'TARGET_DIR="%s"\n' "$TARGET_DIR" echo # evaluate target reference @@ -46,7 +50,7 @@ fi # clone repo printf 'Cloning repo...\n' GIT_DIR="$SOURCE_DIR.git" -git clone --branch="$TARGET_BRANCH" "https://github.com/$GITHUB_SLUG.git" "$GIT_DIR" +git clone --branch="$TARGET_BRANCH" "https://github.com/$TARGET_REPO_SLUG.git" "$GIT_DIR" # setup git cd "$GIT_DIR" @@ -67,7 +71,7 @@ cp -R "$SOURCE_DIR" "$TARGET_DIR" # commit changes printf '\nCommiting changes...\n' git add --all "$TARGET_DIR" -git commit -m "Update phpDocumentor class docs for $SOURCE_REF" +git commit --message="Update phpDocumentor class docs for $SOURCE_REF" # very simple race condition protection for concurrent Travis builds # this is no definite protection (race conditions are still possible during `git push`), @@ -75,7 +79,7 @@ git commit -m "Update phpDocumentor class docs for $SOURCE_REF" if [ "$SOURCE_REF_TYPE" == "commit" ]; then # get latest commit printf '\nRetrieving latest commit...\n' - LATEST_COMMIT="$(wget -O- "https://api.github.com/repos/$GITHUB_SLUG/git/refs/heads/$SOURCE_REF_BRANCH" 2> /dev/null | php -r " + LATEST_COMMIT="$(wget -O- "https://api.github.com/repos/$SOURCE_REPO_SLUG/git/refs/heads/$SOURCE_REF_BRANCH" 2> /dev/null | php -r " \$json = json_decode(stream_get_contents(STDIN), true); if (\$json !== null) { if (isset(\$json['ref']) && (\$json['ref'] === 'refs/heads/$SOURCE_REF_BRANCH')) { @@ -95,6 +99,6 @@ fi # push changes printf '\nPushing changes...\n' -git push "https://github.com/$GITHUB_SLUG.git" "$TARGET_BRANCH:$TARGET_BRANCH" +git push "https://github.com/$TARGET_REPO_SLUG.git" "$TARGET_BRANCH:$TARGET_BRANCH" echo