diff --git a/.gitignore b/.gitignore index 9be633f..673e405 100644 --- a/.gitignore +++ b/.gitignore @@ -15,10 +15,10 @@ desktop.ini /composer.phar /vendor -# phpDocumentor -/_build/phpdoc/ -/_build/phpdoc.cache/ -/_build/phpdoc-*/ +# Build system +/_build/phpdoc +/_build/phpdoc.cache +/_build/deploy-*.git # User config /config/config.php diff --git a/README.md b/README.md index da1fb7b..7efcccb 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ Pico ==== -[![License](https://img.shields.io/github/license/picocms/Pico.svg)](https://github.com/picocms/Pico/blob/master/LICENSE.md) -[![Version](https://img.shields.io/github/release/picocms/Pico.svg)](https://github.com/picocms/Pico/releases/latest) -[![Build Status](https://img.shields.io/travis/picocms/Pico.svg)](https://travis-ci.org/picocms/Pico) -[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/theshka/pico.svg)](https://scrutinizer-ci.com/g/theshka/Pico/?branch=master) +[![License](https://picocms.github.io/Pico/badges/pico-license.svg)](https://github.com/picocms/Pico/blob/master/LICENSE.md) +[![Version](https://picocms.github.io/Pico/badges/pico-version.svg)](https://github.com/picocms/Pico/releases/latest) +[![Build Status](https://api.travis-ci.org/picocms/Pico.svg)](https://travis-ci.org/picocms/Pico) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/theshka/Pico/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/theshka/Pico/?branch=master) [![Tweet Button](https://cloud.githubusercontent.com/assets/640217/11483728/b0842918-976f-11e5-9185-d53261b3125b.png)](https://twitter.com/intent/tweet?text=Pico+is+a+stupidly+simple%2C+blazing+fast%2C+flat+file+CMS.+Visit+http%3A%2F%2Fpicocms.org+and+downlaod+%23picocms+today%21+via+%40gitpicocms&related=gitpicocms) Pico is a stupidly simple, blazing fast, flat file CMS. See http://picocms.org/ for more info. diff --git a/_build/deploy-phpdoc-branch.sh b/_build/deploy-phpdoc-branch.sh index fd4eaba..c4a94a9 100755 --- a/_build/deploy-phpdoc-branch.sh +++ b/_build/deploy-phpdoc-branch.sh @@ -1,40 +1,51 @@ #!/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 ($TRAVIS_BRANCH) is not permitted to deploy" - exit + echo "Skipping branch deployment because this is not on the required runtime" + exit 0 fi if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then - echo "Skipping phpDoc deployment because this pull request (#$TRAVIS_PULL_REQUEST) is not permitted to deploy" - exit + echo "Skipping branch deployment because this pull request (#$TRAVIS_PULL_REQUEST) is not permitted to deploy" + exit 0 fi -PHPDOC_ID="${TRAVIS_BRANCH//\//_}" -PHPDOC_GIT_DIR="$TRAVIS_BUILD_DIR/_build/phpdoc-$PHPDOC_ID.git" +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_DIR="$TRAVIS_BUILD_DIR/_build/deploy-$DEPLOYMENT_ID.git" # clone repo echo "Cloning repo..." -git clone --branch="gh-pages" "https://github.com/$TRAVIS_REPO_SLUG.git" "$PHPDOC_GIT_DIR" +git clone --branch="gh-pages" "https://github.com/$TRAVIS_REPO_SLUG.git" "$DEPLOYMENT_DIR" [ $? -eq 0 ] || exit 1 -cd "$PHPDOC_GIT_DIR" +cd "$DEPLOYMENT_DIR" echo +# setup repo +github-setup.sh + # generate phpDocs generate-phpdoc.sh \ "$TRAVIS_BUILD_DIR/.phpdoc.xml" \ - "$PHPDOC_GIT_DIR/phpDoc/$PHPDOC_ID.cache" "$PHPDOC_GIT_DIR/phpDoc/$PHPDOC_ID" \ + "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID.cache" "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" \ "Pico 1.0 API Documentation ($TRAVIS_BRANCH branch)" [ $? -eq 0 ] || exit 1 +[ -n "$(git status --porcelain "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID.cache")" ] || exit 0 + +# commit phpDocs +echo "Committing changes..." +git add "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID.cache" "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" +git commit \ + --message="Update phpDocumentor class docs for $TRAVIS_BRANCH branch @ $TRAVIS_COMMIT" \ + "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID.cache" "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" +[ $? -eq 0 ] || exit 1 +echo # deploy phpDocs -deploy-phpdoc.sh \ - "Update phpDocumentor class docs for $TRAVIS_BRANCH branch @ $TRAVIS_COMMIT" \ - "$TRAVIS_REPO_SLUG" "heads/$TRAVIS_BRANCH" "$TRAVIS_COMMIT" +github-deploy.sh "$TRAVIS_REPO_SLUG" "heads/$TRAVIS_BRANCH" "$TRAVIS_COMMIT" [ $? -eq 0 ] || exit 1 diff --git a/_build/deploy-phpdoc-release.sh b/_build/deploy-phpdoc-release.sh index e613808..42f11e2 100755 --- a/_build/deploy-phpdoc-release.sh +++ b/_build/deploy-phpdoc-release.sh @@ -1,27 +1,65 @@ #!/usr/bin/env bash -[ "$DEPLOY_PHPDOC_RELEASES" == "true" ] || exit +if [ "$DEPLOY_PHPDOC_RELEASES" != "true" ]; then + echo "Skipping phpDoc release deployment because it has been disabled" +fi +if [ "$DEPLOY_VERSION_BADGE" != "true" ]; then + echo "Skipping version badge deployment because it has been disabled" +fi +if [ "$DEPLOY_PHPDOC_RELEASES" != "true" ] || [ "$DEPLOY_VERSION_BADGE" != "true" ]; then + [ "$DEPLOY_PHPDOC_RELEASES" != "true" ] && [ "$DEPLOY_VERSION_BADGE" != "true" ] && exit 0 || echo +fi -PHPDOC_ID="${TRAVIS_BRANCH//\//_}" -PHPDOC_GIT_DIR="$TRAVIS_BUILD_DIR/_build/phpdoc-$PHPDOC_ID.git" +DEPLOYMENT_ID="${TRAVIS_BRANCH//\//_}" +DEPLOYMENT_DIR="$TRAVIS_BUILD_DIR/_build/deploy-$DEPLOYMENT_ID.git" # clone repo echo "Cloning repo..." -git clone --branch="gh-pages" "https://github.com/$TRAVIS_REPO_SLUG.git" "$PHPDOC_GIT_DIR" +git clone --branch="gh-pages" "https://github.com/$TRAVIS_REPO_SLUG.git" "$DEPLOYMENT_DIR" [ $? -eq 0 ] || exit 1 -cd "$PHPDOC_GIT_DIR" +cd "$DEPLOYMENT_DIR" echo -# generate phpDocs -generate-phpdoc.sh \ - "$TRAVIS_BUILD_DIR/.phpdoc.xml" \ - "-" "$PHPDOC_GIT_DIR/phpDoc/$PHPDOC_ID" \ - "Pico 1.0 API Documentation ($TRAVIS_TAG)" -[ $? -eq 0 ] || exit 1 +# setup repo +github-setup.sh -# deploy phpDocs -deploy-phpdoc.sh \ - "Update phpDocumentor class docs for $TRAVIS_TAG" \ - "$TRAVIS_REPO_SLUG" "tags/$TRAVIS_TAG" "$TRAVIS_COMMIT" +# generate phpDocs +if [ "$DEPLOY_PHPDOC_RELEASES" == "true" ]; then + generate-phpdoc.sh \ + "$TRAVIS_BUILD_DIR/.phpdoc.xml" \ + "-" "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" \ + "Pico 1.0 API Documentation ($TRAVIS_TAG)" + [ $? -eq 0 ] || exit 1 + + # commit phpDocs + if [ -n "$(git status --porcelain "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID")" ]; then + echo "Committing phpDoc changes..." + git add "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" + git commit \ + --message="Update phpDocumentor class docs for $TRAVIS_TAG" \ + "$DEPLOYMENT_DIR/phpDoc/$DEPLOYMENT_ID" + [ $? -eq 0 ] || exit 1 + echo + fi +fi + +# update version badge +if [ "$DEPLOY_VERSION_BADGE" == "true" ]; then + generate-badge.sh \ + "$DEPLOYMENT_DIR/badges/pico-version.svg" \ + "release" "$TRAVIS_TAG" "blue" + + # commit version badge + echo "Committing changes..." + git add "$DEPLOYMENT_DIR/badges/pico-version.svg" + git commit \ + --message="Update version badge for $TRAVIS_TAG" \ + "$DEPLOYMENT_DIR/badges/pico-version.svg" + [ $? -eq 0 ] || exit 1 + echo +fi + +# deploy +github-deploy.sh "$TRAVIS_REPO_SLUG" "tags/$TRAVIS_TAG" "$TRAVIS_COMMIT" [ $? -eq 0 ] || exit 1 diff --git a/_build/generate-badge.sh b/_build/generate-badge.sh new file mode 100755 index 0000000..5727e74 --- /dev/null +++ b/_build/generate-badge.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +## +# Downloads a custom badge from shields.io +# +# All credit goes to the awesome guys at shields.io! +# +# @see http://shields.io/ +# +# @author Daniel Rudolf +# @link http://picocms.org +# @license http://opensource.org/licenses/MIT +# + +set -e + +# parameters +BADGE_FILE_PATH="$1" # target file path +BADGE_SUBJECT="$2" # subject (left half) of the badge +BADGE_STATUS="$3" # status (right half) of the badge +BADGE_COLOR="$4" # color of the badge + +# print parameters +echo "Generating badge..." +printf 'BADGE_FILE_PATH="%s"\n' "$BADGE_FILE_PATH" +printf 'BADGE_SUBJECT="%s"\n' "$BADGE_SUBJECT" +printf 'BADGE_STATUS="%s"\n' "$BADGE_STATUS" +printf 'BADGE_COLOR="%s"\n' "$BADGE_COLOR" +echo + +# download badge from shields.io +printf 'Downloading badge...\n' +TMP_BADGE="$(mktemp -u)" + +curl --location --output "$TMP_BADGE" \ + "https://img.shields.io/badge/$BADGE_SUBJECT-$BADGE_STATUS-$BADGE_COLOR.svg" + +# validate badge +if [ ! -f "$TMP_BADGE" ] || [ ! -s "$TMP_BADGE" ]; then + echo "Unable to generate badge; skipping..." >&2 + exit 1 +fi + +# MIME type image/svg+xml isn't supported at the moment +# +#TMP_BADGE_MIME="$(file --mime-type "$TMP_BADGE" | cut -d ' ' -f 2)" +#if [ "$TMP_BADGE_MIME" != "image/svg+xml" ]; then +# echo "Generated badge should be of type 'image/svg+xml', '$TMP_BADGE_MIME' given; aborting...\n" >&2 +# exit 1 +#fi + +# deploy badge +mv "$TMP_BADGE" "$BADGE_FILE_PATH" + +echo diff --git a/_build/deploy-phpdoc.sh b/_build/github-deploy.sh similarity index 61% rename from _build/deploy-phpdoc.sh rename to _build/github-deploy.sh index dea8366..3734f20 100755 --- a/_build/deploy-phpdoc.sh +++ b/_build/github-deploy.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash ## -# Deploys phpDoc class documentation +# Pushes commits to a GitHub repo # # @author Daniel Rudolf # @link http://picocms.org @@ -10,52 +10,31 @@ set -e -# environment variables -# GITHUB_OAUTH_TOKEN GitHub authentication token, see https://github.com/settings/tokens - # parameters -COMMIT_MESSAGE="$1" # commit message -CHECK_REPO_SLUG="$2" # optional GitHub repo (e.g. picocms/Pico) to check +CHECK_REPO_SLUG="$1" # optional GitHub repo (e.g. picocms/Pico) to check # its latest commit as basic race condition protection -CHECK_REMOTE_REF="$3" # optional remote Git reference (e.g. heads/master) -CHECK_LOCAL_COMMIT="$4" # optional local commit SHA1 +CHECK_REMOTE_REF="$2" # optional remote Git reference (e.g. heads/master) +CHECK_LOCAL_COMMIT="$3" # optional local commit SHA1 # print parameters -echo "Deploying phpDocs..." -printf 'COMMIT_MESSAGE="%s"\n' "$COMMIT_MESSAGE" +echo "Deploying repo..." printf 'CHECK_REPO_SLUG="%s"\n' "$CHECK_REPO_SLUG" printf 'CHECK_REMOTE_REF="%s"\n' "$CHECK_REMOTE_REF" printf 'CHECK_LOCAL_COMMIT="%s"\n' "$CHECK_LOCAL_COMMIT" echo # check for changes -if [ -z "$(git status --porcelain)" ]; then +if [ -z "$(git log --oneline '@{upstream}..')" ]; then printf 'Nothing to deploy; skipping...\n\n' exit 0 fi -# setup git -printf 'Preparing repo...\n' -git config push.default simple -git config user.name "Travis CI" -git config user.email "travis-ci@picocms.org" - -if [ -n "$GITHUB_OAUTH_TOKEN" ]; then - git config credential.helper 'store --file=.git/credentials' - (umask 077 && echo "https://GitHub:$GITHUB_OAUTH_TOKEN@github.com" > .git/credentials) -fi - -# commit changes -printf '\nCommiting changes...\n' -git add --all -git commit --message="$COMMIT_MESSAGE" - # race condition protection for concurrent Travis builds # this is no definite protection (race conditions are still possible during `git push`), # 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 # retrieve information using GitHub APIv3 - printf '\nChecking latest commit...\n' + printf 'Checking latest commit...\n' CHECK_API_URL="https://api.github.com/repos/$CHECK_REPO_SLUG/git/refs/$CHECK_REMOTE_REF" if [ -n "$GITHUB_OAUTH_TOKEN" ]; then CHECK_API_RESPONSE="$(wget -O- --header="Authorization: token $GITHUB_OAUTH_TOKEN" "$CHECK_API_URL" 2> /dev/null)" @@ -77,13 +56,15 @@ if [ -n "$CHECK_REPO_SLUG" ] && [ -n "$CHECK_REMOTE_REF" ] && [ -n "$CHECK_LOCAL # compare source reference against the latest commit if [ "$CHECK_REMOTE_COMMIT" != "$CHECK_LOCAL_COMMIT" ]; then - echo "WARNING: latest local commit '$CHECK_LOCAL_COMMIT' doesn't match latest remote commit '$CHECK_REMOTE_COMMIT'" >&2 - exit 0 + echo "Latest local commit '$CHECK_LOCAL_COMMIT' doesn't match latest remote commit '$CHECK_REMOTE_COMMIT'; aborting..." >&2 + exit 1 fi + + echo fi # push changes -printf '\nPushing changes...\n' -git push origin +printf 'Pushing changes...\n' +git push echo diff --git a/_build/github-setup.sh b/_build/github-setup.sh new file mode 100755 index 0000000..a9697cb --- /dev/null +++ b/_build/github-setup.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +## +# Prepares a GitHub repo for deployment +# +# @author Daniel Rudolf +# @link http://picocms.org +# @license http://opensource.org/licenses/MIT +# + +set -e + +# environment variables +# GITHUB_OAUTH_TOKEN GitHub authentication token, see https://github.com/settings/tokens + +# print "parameters" (we don't have any) +echo "Setup repo..." +echo + +# check for git repo +if ! git rev-parse --git-dir > /dev/null 2>&1; then + echo "Not a git repo; aborting..." >&2 + exit 1 +fi + +# setup git +printf 'Preparing repo...\n' +git config push.default simple +git config user.name "Travis CI" +git config user.email "travis-ci@picocms.org" + +if [ -n "$GITHUB_OAUTH_TOKEN" ]; then + git config credential.helper 'store --file=.git/credentials' + (umask 077 && echo "https://GitHub:$GITHUB_OAUTH_TOKEN@github.com" > .git/credentials) +fi + +echo