diff --git a/.build/clean.sh b/.build/clean.sh new file mode 100755 index 0000000..a816cb8 --- /dev/null +++ b/.build/clean.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -e + +[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; } + +# parameters +ARCHIVE_DIR="${1:-$PICO_PROJECT_DIR}" # directory to create release archives in + +# print parameters +echo "Cleaning up build environment..." +printf 'PICO_DEPLOY_DIR="%s"\n' "$PICO_DEPLOY_DIR" +printf 'PICO_BUILD_DIR="%s"\n' "$PICO_BUILD_DIR" +printf 'ARCHIVE_DIR="%s"\n' "$ARCHIVE_DIR" +echo + +echo "Removing deployment directory..." +[ ! -d "$PICO_DEPLOY_DIR" ] || rm -rf "$PICO_DEPLOY_DIR" + +echo "Removing build directory..." +[ ! -d "$PICO_BUILD_DIR" ] || rm -rf "$PICO_BUILD_DIR" + +echo "Removing release archives..." +find "$ARCHIVE_DIR" -mindepth 1 -maxdepth 1 \ + \( -name 'pico-release-*.tar.gz' -o -name 'pico-release-*.zip' \) \ + -delete diff --git a/.build/create-release.sh b/.build/create-release.sh deleted file mode 100755 index 8a799a2..0000000 --- a/.build/create-release.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env bash -set -e - -export PATH="$PICO_TOOLS_DIR:$PATH" -. "$PICO_TOOLS_DIR/functions/parse-version.sh.inc" - -# parameters -ARCHIVE_DIR="$1" # directory to create release archives in -ARCHIVE_FILENAME="$2" # release archive file name (without file extension) - -if [ -z "$ARCHIVE_DIR" ] || [ "$(realpath "$ARCHIVE_DIR")" == "$(realpath "$PICO_BUILD_DIR")" ]; then - echo "Unable to create release archives: Invalid release archive target dir '$ARCHIVE_DIR'" >&2 - exit 1 -fi -if [ -z "$ARCHIVE_FILENAME" ]; then - echo "Unable to create release archives: No release archive file name given" >&2 - exit 1 -fi - -# parse version -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 "$PICO_BUILD_DIR" "https://github.com/$RELEASE_REPO_SLUG.git" "$RELEASE_REPO_BRANCH" - -cd "$PICO_BUILD_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 - -# set minimum stability -if [ "$VERSION_STABILITY" != "stable" ]; then - echo "Setting minimum stability to '$VERSION_STABILITY'..." - composer config "minimum-stability" "$VERSION_STABILITY" - composer config "prefer-stable" "true" - echo -fi - -# 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 "Adding 'README.md', 'CONTRIBUTING.md', 'CHANGELOG.md'..." -cp vendor/picocms/pico/README.md README.md -cp vendor/picocms/pico/CONTRIBUTING.md CONTRIBUTING.md -cp vendor/picocms/pico/CHANGELOG.md CHANGELOG.md - -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..." -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 archives -echo "Creating release archive '$ARCHIVE.tar.gz'..." - -if [ -e "$ARCHIVE_DIR/$ARCHIVE.tar.gz" ]; then - echo "Unable to create release archive: File '$ARCHIVE.tar.gz' exists" >&2 - exit 1 -fi - -find . -mindepth 1 -maxdepth 1 -printf '%f\0' \ - | xargs -0 -- tar -czf "$ARCHIVE_DIR/$ARCHIVE.tar.gz" -- -echo - -echo "Creating release archive '$ARCHIVE.zip'..." - -if [ -e "$ARCHIVE_DIR/$ARCHIVE.zip" ]; then - echo "Unable to create release archive: File '$ARCHIVE.zip' exists" >&2 - exit 1 -fi - -zip -q -r "$ARCHIVE_DIR/$ARCHIVE.zip" . -echo diff --git a/.build/deploy-branch.sh b/.build/deploy-branch.sh index 3917aa1..d8284a7 100755 --- a/.build/deploy-branch.sh +++ b/.build/deploy-branch.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -export PATH="$PICO_TOOLS_DIR:$PATH" +[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; } # get current Pico milestone VERSION="$(php -r "require_once('$PICO_PROJECT_DIR/lib/Pico.php'); echo Pico::VERSION;")" diff --git a/.build/deploy-release.sh b/.build/deploy-release.sh index c105d19..eef5d70 100755 --- a/.build/deploy-release.sh +++ b/.build/deploy-release.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -e +[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; } + DEPLOY_FULL="true" if [ "$DEPLOY_PHPDOC_RELEASES" != "true" ]; then echo "Skipping phpDoc release deployment because it has been disabled" @@ -31,10 +33,9 @@ if [ "$DEPLOY_FULL" != "true" ]; then echo fi -export PATH="$PICO_TOOLS_DIR:$PATH" +# parse version . "$PICO_TOOLS_DIR/functions/parse-version.sh.inc" -# parse version if ! parse_version "$PROJECT_REPO_TAG"; then echo "Invalid version '$PROJECT_REPO_TAG'; aborting..." >&2 exit 1 diff --git a/.build/deploy.sh b/.build/deploy.sh deleted file mode 100755 index 0ef0c10..0000000 --- a/.build/deploy.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -if [ -n "$PROJECT_REPO_TAG" ]; then - exec "$(dirname "$0")/deploy-release.sh" -else - exec "$(dirname "$0")/deploy-branch.sh" -fi diff --git a/.build/init.sh.inc b/.build/init.sh.inc new file mode 100644 index 0000000..e9cee44 --- /dev/null +++ b/.build/init.sh.inc @@ -0,0 +1,19 @@ +if [ -z "$PICO_BUILD_ENV" ]; then + echo "No Pico build environment specified" >&2 + exit 1 +fi + +# add project build dir to $PATH +export PATH="$PICO_PROJECT_DIR/.build:$PATH" + +# set environment variables +__picocms_cmd export RELEASE_REPO_SLUG="${RELEASE_REPO_SLUG:-picocms/pico-composer}" +__picocms_cmd export RELEASE_REPO_BRANCH="${RELEASE_REPO_BRANCH:-master}" + +if [ "$PROJECT_REPO_SLUG" != "picocms/Pico" ]; then + __picocms_cmd export DEPLOY_REPO_SLUG="${DEPLOY_REPO_SLUG:-$PROJECT_REPO_SLUG}" + __picocms_cmd export DEPLOY_REPO_BRANCH="${DEPLOY_REPO_BRANCH:-gh-pages}" +else + __picocms_cmd export DEPLOY_REPO_SLUG="${DEPLOY_REPO_SLUG:-picocms.github.io}" + __picocms_cmd export DEPLOY_REPO_BRANCH="${DEPLOY_REPO_BRANCH:-master}" +fi diff --git a/.build/install.sh b/.build/install.sh index 9e047f8..dff079c 100755 --- a/.build/install.sh +++ b/.build/install.sh @@ -1,55 +1,17 @@ #!/usr/bin/env bash set -e +[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; } + # setup build system -echo "Installing build dependencies..." -echo - -case "$1" in - "--deploy") - echo "Synchronizing package index files..." - sudo apt-get update - echo - - echo "Installing cloc..." - sudo apt-get install -y cloc - echo - - echo "Installing phpDocumentor..." - curl --location --output "$PICO_TOOLS_DIR/phpdoc" \ - "https://github.com/phpDocumentor/phpDocumentor2/releases/latest/download/phpDocumentor.phar" - chmod +x "$PICO_TOOLS_DIR/phpdoc" - echo - ;; -esac - -echo "Installing PHP_CodeSniffer..." -if [ "$(php -r 'echo PHP_VERSION_ID;')" -ge 50400 ]; then - PHPCS_DOWNLOAD="https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/" -else - PHPCS_DOWNLOAD="https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.9.2/" -fi - -curl --location --output "$PICO_TOOLS_DIR/phpcs" \ - "$PHPCS_DOWNLOAD/phpcs.phar" -chmod +x "$PICO_TOOLS_DIR/phpcs" - -curl --location --output "$PICO_TOOLS_DIR/phpcbf" \ - "$PHPCS_DOWNLOAD/phpcbf.phar" -chmod +x "$PICO_TOOLS_DIR/phpcbf" - -echo - -# setup composer -echo "Setup Composer..." - -# let composer use our GITHUB_OAUTH_TOKEN -if [ -n "$GITHUB_OAUTH_TOKEN" ]; then - composer config --global github-oauth.github.com "$GITHUB_OAUTH_TOKEN" -fi +BUILD_REQUIREMENTS=( --phpcs ) +[ "$1" != "--deploy" ] || BUILD_REQUIREMENTS+=( --cloc --phpdoc ) +"$PICO_TOOLS_DIR/setup/$PICO_BUILD_ENV.sh" "${BUILD_REQUIREMENTS[@]}" # set COMPOSER_ROOT_VERSION when necessary if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -n "$PROJECT_REPO_BRANCH" ]; then + echo "Setting up Composer..." + PICO_VERSION_PATTERN="$(php -r " \$json = json_decode(file_get_contents('$PICO_PROJECT_DIR/composer.json'), true); if (\$json !== null) { @@ -69,9 +31,9 @@ if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -n "$PROJECT_REPO_BRANCH" ]; then if [ -n "$PICO_VERSION_PATTERN" ]; then export COMPOSER_ROOT_VERSION="$PICO_VERSION_PATTERN" fi -fi -echo + echo +fi # install dependencies echo "Running \`composer install\`$([ -n "$COMPOSER_ROOT_VERSION" ] && echo -n " ($COMPOSER_ROOT_VERSION)")..." diff --git a/.build/release.sh b/.build/release.sh new file mode 100755 index 0000000..9623b3f --- /dev/null +++ b/.build/release.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +set -e + +[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; } + +# parameters +VERSION="${1:-$PROJECT_REPO_TAG}" # version to create a release for +ARCHIVE_DIR="${2:-$PICO_PROJECT_DIR}" # directory to create release archives in + +# print parameters +echo "Creating new release..." +printf 'VERSION="%s"\n' "$VERSION" +echo + +# guess version string +if [ -z "$VERSION" ]; then + PICO_VERSION="$(php -r " + require_once('$PICO_PROJECT_DIR/lib/Pico.php'); + echo preg_replace('/-(?:dev|n|nightly)(?:[.-]?[0-9]+)?(?:[.-]dev)?$/', '', Pico::VERSION); + ")" + + VERSION="v$PICO_VERSION-dev+${PROJECT_REPO_BRANCH:-master}" + echo "Creating development release of Pico v$PICO_VERSION ($VERSION)..." + echo +fi + +# parse version +. "$PICO_TOOLS_DIR/functions/parse-version.sh.inc" + +if ! parse_version "$VERSION"; then + echo "Unable to create release archive: Invalid version '$VERSION'" >&2 + exit 1 +fi + +DEPENDENCY_VERSION="$VERSION_FULL@$VERSION_STABILITY" +if [ "$VERSION_STABILITY" == "dev" ] && [ -n "$VERSION_BUILD" ]; then + DEPENDENCY_VERSION="dev-$VERSION_BUILD" +fi + +# clone repo +github-clone.sh "$PICO_BUILD_DIR" "https://github.com/$RELEASE_REPO_SLUG.git" "$RELEASE_REPO_BRANCH" + +cd "$PICO_BUILD_DIR" + +# force Pico version +echo "Updating composer dependencies..." +composer require --no-update \ + "picocms/pico $DEPENDENCY_VERSION" \ + "picocms/pico-theme $DEPENDENCY_VERSION" \ + "picocms/pico-deprecated $DEPENDENCY_VERSION" +echo + +# set minimum stability +if [ "$VERSION_STABILITY" != "stable" ]; then + echo "Setting minimum stability to '$VERSION_STABILITY'..." + composer config "minimum-stability" "$VERSION_STABILITY" + composer config "prefer-stable" "true" + echo +fi + +# 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 "Adding 'README.md', 'CONTRIBUTING.md', 'CHANGELOG.md'..." +cp vendor/picocms/pico/README.md README.md +cp vendor/picocms/pico/CONTRIBUTING.md CONTRIBUTING.md +cp vendor/picocms/pico/CHANGELOG.md CHANGELOG.md + +echo "Removing '.git' directories of plugins and themes..." +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 "Preparing 'composer.json' for release..." +composer require --no-update \ + "picocms/pico ^$VERSION_MILESTONE" \ + "picocms/pico-theme ^$VERSION_MILESTONE" \ + "picocms/pico-deprecated ^$VERSION_MILESTONE" + +# create release archives +create-release.sh "$PICO_BUILD_DIR" "$ARCHIVE_DIR" "pico-release-v$VERSION_FULL" diff --git a/.gitattributes b/.gitattributes index f03d557..bc9dbf2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,5 @@ -/.github export-ignore /.build export-ignore +/.github export-ignore /assets/.gitignore export-ignore /config/.gitignore export-ignore /content/.gitignore export-ignore diff --git a/.gitignore b/.gitignore index bccec62..490151f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,12 +10,17 @@ desktop.ini .DS_Store ._* -# composer +# Composer /composer.lock -/composer.phar /vendor +# Build system +/.build/build +/.build/deploy +/.build/ci-tools +/pico-release-*.tar.gz +/pico-release-*.zip + # phpDocumentor /.build/phpdoc /.build/phpdoc.cache -/phpDocumentor.phar diff --git a/.travis.yml b/.travis.yml index 5e5ecbc..6c36396 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,48 +23,52 @@ jobs: - php: hhvm-3.27 # until Sep 2019 - php: hhvm-3.30 # until Nov 2019 - # Deployment stage - - stage: deploy - php: 5.3 - dist: precise + # Branch deployment stage + - stage: deploy-branch + if: type == "push" && tag IS blank + php: 5.6 sudo: required install: - - '[ "$TRAVIS_PULL_REQUEST" == "false" ] || travis_terminate 0' - - '[ -n "$TRAVIS_TAG" ] || [[ ",$DEPLOY_PHPDOC_BRANCHES," == *,"$TRAVIS_BRANCH",* ]] || travis_terminate 0' + - '[[ ",$DEPLOY_PHPDOC_BRANCHES," == *,"$TRAVIS_BRANCH",* ]] || travis_terminate 0' - install.sh --deploy script: - - deploy.sh + - deploy-branch.sh + + # Release deployment stage + - stage: deploy-release + if: tag IS present + php: 5.3 + dist: precise + install: + - install.sh --deploy + script: + - '[ "$PROJECT_REPO_TAG" == "v$(php -r "require_once(\"lib/Pico.php\"); echo Pico::VERSION;")" ]' + - deploy-release.sh before_deploy: - - '[ "$TRAVIS_TAG" == "v$(php -r "require_once(\"lib/Pico.php\"); echo Pico::VERSION;")" ]' - - create-release.sh "$TRAVIS_BUILD_DIR" "pico-release-$TRAVIS_TAG" + - release.sh deploy: provider: releases api_key: ${GITHUB_OAUTH_TOKEN} file: - - pico-release-$TRAVIS_TAG.tar.gz - - pico-release-$TRAVIS_TAG.zip + - pico-release-$PROJECT_REPO_TAG.tar.gz + - pico-release-$PROJECT_REPO_TAG.zip skip_cleanup: true - name: Version ${TRAVIS_TAG:1} + name: Version ${PROJECT_REPO_TAG:1} draft: true - on: - tags: true # Ignore nightly build failures allow_failures: - php: nightly - fast-finish: true + fast_finish: true before_install: - - 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" + - . "$PICO_PROJECT_DIR/.build/init.sh.inc" install: - install.sh -before_script: - - export PATH="$TRAVIS_BUILD_DIR/vendor/bin:$PATH" - script: - - phpcs --standard=.phpcs.xml "$TRAVIS_BUILD_DIR" + - phpcs --standard=.phpcs.xml "$PICO_PROJECT_DIR"