diff --git a/.build/build.sh b/.build/build.sh new file mode 100755 index 000000000..24a54b0dc --- /dev/null +++ b/.build/build.sh @@ -0,0 +1,486 @@ +#!/bin/bash +# Pico -- build.sh +# Builds a new Pico release and creates release archives. +# +# This file is part of Pico, a stupidly simple, blazing fast, flat file CMS. +# Visit us at https://picocms.org/ for more info. +# +# Copyright (c) 2017 Daniel Rudolf +# +# This work is licensed under the terms of the MIT license. +# For a copy, see LICENSE file or . +# +# SPDX-License-Identifier: MIT +# License-Filename: LICENSE + +set -eu -o pipefail +export LC_ALL=C + +# env variables +PHP="${PHP:-php}" +export -n PHP + +COMPOSER="${COMPOSER:-composer}" +export -n COMPOSER + +if ! which "$PHP" > /dev/null; then + echo "Missing script dependency: php" >&2 + exit 1 +elif ! which "$COMPOSER" > /dev/null; then + echo "Missing script dependency: composer" >&2 + exit 1 +elif ! which "git" > /dev/null; then + echo "Missing script dependency: git" >&2 + exit 1 +elif ! which "gh" > /dev/null; then + echo "Missing script dependency: gh" >&2 + exit 1 +elif ! which "rsync" > /dev/null; then + echo "Missing script dependency: rsync" >&2 + exit 1 +elif ! which "jq" > /dev/null; then + echo "Missing script dependency: jq" >&2 + exit 1 +fi + +# parameters +BUILD_NAME="pico" +BUILD_PROJECT="picocms/pico" +BUILD_VERSION= + +PICO_COMPOSER_NAME="pico-composer" +PICO_COMPOSER_PROJECT="picocms/pico-composer" +PICO_COMPOSER_DIR= + +PICO_THEME_NAME="pico-theme" +PICO_THEME_PROJECT="picocms/pico-theme" +PICO_THEME_DIR= + +PICO_DEPRECATED_NAME="pico-deprecated" +PICO_DEPRECATED_PROJECT="picocms/pico-deprecated" +PICO_DEPRECATED_DIR= + +PHP_VERSION="7.2" + +# options +VERSION= +PUBLISH= +NOCHECK= +NOCLEAN= + +while [ $# -gt 0 ]; do + if [ "$1" == "--help" ]; then + echo "Usage:" + echo " build.sh [OPTIONS]... [VERSION]" + echo + echo "Builds a new Pico release and creates release archives." + echo + echo "Help options:" + echo " --help display this help and exit" + echo + echo "Application options:" + echo " --publish create GitHub release and upload artifacts" + echo " --pico-composer PATH path to a local copy of '$PICO_COMPOSER_PROJECT'" + echo " --pico-theme PATH path to a local copy of '$PICO_THEME_PROJECT'" + echo " --pico-deprecated PATH path to a local copy of '$PICO_DEPRECATED_PROJECT'" + echo " --no-check skip version checks for dev builds" + echo " --no-clean don't remove build dir on exit" + echo + echo "You must run this script from within Pico's source directory. Please note" + echo "that this script will perform a large number of strict sanity checks before" + echo "building a new non-development version of Pico. VERSION must start with 'v'." + exit 0 + elif [ "$1" == "--publish" ]; then + PUBLISH="y" + shift + elif [ "$1" == "--no-check" ]; then + NOCHECK="y" + shift + elif [ "$1" == "--no-clean" ]; then + NOCLEAN="y" + shift + elif [ "$1" == "--pico-composer" ] && [ $# -ge 2 ]; then + PICO_COMPOSER_DIR="$2" + shift 2 + elif [ "$1" == "--pico-theme" ] && [ $# -ge 2 ]; then + PICO_THEME_DIR="$2" + shift 2 + elif [ "$1" == "--pico-deprecated" ] && [ $# -ge 2 ]; then + PICO_DEPRECATED_DIR="$2" + shift 2 + elif [ -z "$VERSION" ] && [ "${1:0:1}" == "v" ]; then + VERSION="$1" + shift + else + echo "Unknown option: $1" >&2 + exit 1 + fi +done + +# check options and current working dir +if [ ! -f "./composer.json" ] || [ ! -f "./lib/Pico.php" ]; then + echo "You must run this from within Pico's source directory" >&2 + exit 1 +elif [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" != "true" ]; then + echo "You must run this from within a non-bare Git repository" >&2 + exit 1 +fi + +if [ -n "$PICO_COMPOSER_DIR" ]; then + if [ ! -f "$PICO_COMPOSER_DIR/composer.json" ] || [ ! -f "$PICO_COMPOSER_DIR/index.php" ]; then + echo "You must pass a source directory of '$PICO_COMPOSER_PROJECT' as '--pico-composer': $PICO_COMPOSER_DIR" >&2 + exit 1 + elif [ "$(git -C "$PICO_COMPOSER_DIR" rev-parse --is-inside-work-tree 2> /dev/null)" != "true" ]; then + echo "You must pass a non-bare Git repository as '--pico-composer': $PICO_COMPOSER_DIR" >&2 + exit 1 + fi +fi + +if [ -n "$PICO_THEME_DIR" ]; then + if [ ! -f "$PICO_THEME_DIR/composer.json" ] || [ ! -f "$PICO_THEME_DIR/pico-theme.yml" ]; then + echo "You must pass a source directory of '$PICO_THEME_PROJECT' as '--pico-theme': $PICO_THEME_DIR" >&2 + exit 1 + elif [ "$(git -C "$PICO_THEME_DIR" rev-parse --is-inside-work-tree 2> /dev/null)" != "true" ]; then + echo "You must pass a non-bare Git repository as '--pico-theme': $PICO_THEME_DIR" >&2 + exit 1 + fi +fi + +if [ -n "$PICO_DEPRECATED_DIR" ]; then + if [ ! -f "$PICO_DEPRECATED_DIR/composer.json" ] || [ ! -f "$PICO_DEPRECATED_DIR/PicoDeprecated.php" ]; then + echo "You must pass a source directory of '$PICO_DEPRECATED_PROJECT' as '--pico-deprecated': $PICO_DEPRECATED_DIR" >&2 + exit 1 + elif [ "$(git -C "$PICO_DEPRECATED_DIR" rev-parse --is-inside-work-tree 2> /dev/null)" != "true" ]; then + echo "You must pass a non-bare Git repository as '--pico-deprecated': $PICO_DEPRECATED_DIR" >&2 + exit 1 + fi +fi + +# parse version +function parse_version { + VERSION_FULL="${1#v}" + + if ! [[ "$VERSION_FULL" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z\.\-]+))?(\+([0-9A-Za-z\.\-]+))?$ ]]; then + return 1 + fi + + VERSION_MAJOR="${BASH_REMATCH[1]}" + VERSION_MINOR="${BASH_REMATCH[2]}" + VERSION_PATCH="${BASH_REMATCH[3]}" + VERSION_SUFFIX="${BASH_REMATCH[5]}" + + VERSION_STABILITY="stable" + if [[ "$VERSION_SUFFIX" =~ ^(dev|a|alpha|b|beta|rc)?([.-]?[0-9]+)?([.-](dev))?$ ]]; then + if [ "${BASH_REMATCH[1]}" == "dev" ] || [ "${BASH_REMATCH[4]}" == "dev" ]; then + VERSION_STABILITY="dev" + elif [ "${BASH_REMATCH[1]}" == "a" ] || [ "${BASH_REMATCH[1]}" == "alpha" ]; then + VERSION_STABILITY="alpha" + elif [ "${BASH_REMATCH[1]}" == "b" ] || [ "${BASH_REMATCH[1]}" == "beta" ]; then + VERSION_STABILITY="beta" + elif [ "${BASH_REMATCH[1]}" == "rc" ]; then + VERSION_STABILITY="rc" + fi + fi +} + +BUILD_VERSION="v$("$PHP" -r 'require("./lib/Pico.php"); echo Pico::VERSION;')" + +if ! parse_version "$BUILD_VERSION"; then + echo "Unable to build Pico: Invalid Pico version '$BUILD_VERSION'" >&2 + exit 1 +fi + +if [ -z "$VERSION" ]; then + GIT_LOCAL_HEAD="$(git rev-parse HEAD)" + GIT_LOCAL_BRANCH="$(git rev-parse --abbrev-ref HEAD)" + DATETIME="$(date -u +'%Y%m%dT%H%M%SZ')" + + VERSION="v$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" + [ -z "$VERSION_SUFFIX" ] || VERSION+="-$VERSION_SUFFIX" + [ "$VERSION_STABILITY" == "dev" ] || VERSION+="-dev" + VERSION+="+git.$GIT_LOCAL_HEAD.$DATETIME" + + if ! parse_version "$VERSION"; then + echo "Unable to build Pico: Invalid build version '$VERSION'" >&2 + exit 1 + fi + + DEPENDENCY_VERSION="dev-$GIT_LOCAL_BRANCH" +else + if ! parse_version "$VERSION"; then + echo "Unable to build Pico: Invalid build version '$VERSION'" >&2 + exit 1 + fi + + DEPENDENCY_VERSION= + if [ "$VERSION_STABILITY" == "dev" ]; then + DEPENDENCY_VERSION="$(jq -r --arg ALIAS "$VERSION_MAJOR.$VERSION_MINOR.x-dev" \ + '.extra."branch-alias"|to_entries|map(select(.value==$ALIAS).key)[0]//empty' \ + "composer.json")" + fi + + if [ -z "$DEPENDENCY_VERSION" ]; then + DEPENDENCY_VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" + [ -z "$VERSION_SUFFIX" ] || DEPENDENCY_VERSION+="-$VERSION_SUFFIX" + [ "$VERSION_STABILITY" == "stable" ] || DEPENDENCY_VERSION+="@$VERSION_STABILITY" + fi +fi + +# build checks +if [ "$VERSION_STABILITY" != "dev" ]; then + GIT_LOCAL_CLEAN="$(git status --porcelain)" + GIT_LOCAL_HEAD="$(git rev-parse HEAD)" + GIT_LOCAL_TAG="$(git rev-parse --verify "refs/tags/$VERSION" 2> /dev/null || true)" + GIT_REMOTE="$(git 'for-each-ref' --format='%(upstream:remotename)' "$(git symbolic-ref -q HEAD)")" + GIT_REMOTE_TAG="$(git ls-remote "${GIT_REMOTE:-origin}" "refs/tags/$VERSION" 2> /dev/null | cut -f 1 || true)" + PHP_VERSION_LOCAL="$("$PHP" -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')" + + if [ "$VERSION" != "$BUILD_VERSION" ]; then + echo "Unable to build Pico: Building $VERSION, but Pico indicates $BUILD_VERSION" >&2 + exit 1 + elif [ -n "$GIT_LOCAL_CLEAN" ]; then + echo "Unable to build Pico: Building $VERSION, but the working tree is not clean" >&2 + exit 1 + elif [ -z "$GIT_LOCAL_TAG" ]; then + echo "Unable to build Pico: Building $VERSION, but no matching local Git tag was found" >&2 + exit 1 + elif [ "$GIT_LOCAL_HEAD" != "$GIT_LOCAL_TAG" ]; then + echo "Unable to build Pico: Building $VERSION, but the matching Git tag is not checked out" >&2 + exit 1 + elif [ -z "$GIT_REMOTE_TAG" ]; then + echo "Unable to build Pico: Building $VERSION, but no matching remote Git tag was found" >&2 + exit 1 + elif [ "$GIT_LOCAL_TAG" != "$GIT_REMOTE_TAG" ]; then + echo "Unable to build Pico: Building $VERSION, but the matching local and remote Git tags differ" >&2 + exit 1 + elif [ "$PHP_VERSION_LOCAL" != "$PHP_VERSION" ]; then + echo "Unable to build Pico: Refusing to build Pico with PHP $PHP_VERSION_LOCAL, expecting PHP $PHP_VERSION" >&2 + exit 1 + elif [ -n "$PICO_COMPOSER_DIR" ] || [ -n "$PICO_THEME_DIR" ] || [ -n "$PICO_DEPRECATED_DIR" ]; then + echo "Unable to build Pico: Refusing to build a non-dev version with local dependencies" >&2 + exit 1 + fi +else + if [ -z "$NOCHECK" ] && [[ "$VERSION" != "$BUILD_VERSION"* ]]; then + echo "Unable to build Pico: Building $VERSION, but Pico indicates $BUILD_VERSION" >&2 + exit 1 + elif [ -n "$PUBLISH" ]; then + echo "Unable to build Pico: Refusing to publish a dev version" >&2 + exit 1 + fi +fi + +# build in progress... +APP_DIR="$PWD" + +BUILD_DIR="$(mktemp -d)" +[ -n "$NOCLEAN" ] || trap "rm -rf ${BUILD_DIR@Q}" ERR EXIT + +echo "Building Pico $BUILD_VERSION ($VERSION)..." +[ -z "$NOCLEAN" ] || echo "Build directory: $BUILD_DIR" +echo + +# prepare dev versions of components +if [ "$VERSION_STABILITY" == "dev" ]; then + # copy dev version of Pico + echo "Creating clean working tree copy of '$BUILD_PROJECT'..." + rsync -a \ + --exclude="/.build" \ + --exclude="/.git" \ + --exclude="/.github" \ + --exclude="/assets/.gitignore" \ + --exclude="/config/.gitignore" \ + --exclude="/content/.gitignore" \ + --exclude="/plugins/.gitignore" \ + --exclude="/themes/.gitignore" \ + --exclude="/.gitattributes" \ + --exclude="/.gitignore" \ + --exclude="/.phpcs.xml" \ + --exclude="/.phpdoc.xml" \ + --exclude-from=<(git ls-files --exclude-standard -oi --directory) \ + ./ "$BUILD_DIR/$BUILD_NAME/" + + # copy dev version of Composer starter project + if [ -n "$PICO_COMPOSER_DIR" ]; then + echo "Creating clean working tree copy of '$PICO_COMPOSER_PROJECT'..." + rsync -a \ + --exclude="/.git" \ + --exclude="/assets/.gitignore" \ + --exclude="/config/.gitignore" \ + --exclude="/content/.gitignore" \ + --exclude="/plugins/.gitignore" \ + --exclude="/themes/.gitignore" \ + --exclude="/.gitattributes" \ + --exclude="/.gitignore" \ + --exclude-from=<(git -C "$PICO_COMPOSER_DIR" ls-files --exclude-standard -oi --directory) \ + "$PICO_COMPOSER_DIR/" "$BUILD_DIR/$PICO_COMPOSER_NAME/" + fi + + # copy dev version of default theme + if [ -n "$PICO_THEME_DIR" ]; then + echo "Creating clean working tree copy of '$PICO_THEME_PROJECT'..." + rsync -a \ + --exclude="/.git" \ + --exclude="/.github" \ + --exclude="/.gitattributes" \ + --exclude="/.gitignore" \ + --exclude-from=<(git -C "$PICO_THEME_DIR" ls-files --exclude-standard -oi --directory) \ + "$PICO_THEME_DIR/" "$BUILD_DIR/$PICO_THEME_NAME/" + fi + + # copy dev version of PicoDeprecated + if [ -n "$PICO_DEPRECATED_DIR" ]; then + echo "Creating clean working tree copy of '$PICO_DEPRECATED_PROJECT'..." + rsync -a \ + --exclude="/.build" \ + --exclude="/.git" \ + --exclude="/.github" \ + --exclude="/.gitattributes" \ + --exclude="/.gitignore" \ + --exclude="/.phpcs.xml" \ + --exclude-from=<(git -C "$PICO_DEPRECATED_DIR" ls-files --exclude-standard -oi --directory) \ + "$PICO_DEPRECATED_DIR/" "$BUILD_DIR/$PICO_DEPRECATED_NAME/" + fi + + echo +fi + +# download Composer starter project +if [ "$VERSION_STABILITY" != "dev" ] || [ -z "$PICO_COMPOSER_DIR" ]; then + PICO_COMPOSER_VERSION="$DEPENDENCY_VERSION" + [[ "$PICO_COMPOSER_VERSION" == "dev-"* ]] || PICO_COMPOSER_VERSION="$VERSION_MAJOR.$VERSION_MINOR" + + echo "Setting up Pico's Composer starter project (version '$PICO_COMPOSER_VERSION')..." + "$COMPOSER" create-project --no-install "$PICO_COMPOSER_PROJECT" \ + "$BUILD_DIR/$PICO_COMPOSER_NAME" \ + "$PICO_COMPOSER_VERSION" + echo +fi + +# switch to build dir... +cd "$BUILD_DIR/$PICO_COMPOSER_NAME" + +# inject local component copies +if [ "$VERSION_STABILITY" == "dev" ]; then + function composer_repo_config { + jq -nc --arg PACKAGE "$1" --arg VERSION "$2" --arg URL "$3" \ + '{"type": "path", "url": $URL, options: {"symlink": false, "versions": {($PACKAGE): $VERSION}}}' + } + + echo "Adding Composer repository for '$BUILD_PROJECT'..." + "$COMPOSER" config repositories."$BUILD_NAME" \ + "$(composer_repo_config "$BUILD_PROJECT" "$DEPENDENCY_VERSION" "$BUILD_DIR/$BUILD_NAME")" + + if [ -n "$PICO_THEME_DIR" ]; then + echo "Adding Composer repository for '$PICO_THEME_PROJECT'..." + "$COMPOSER" config repositories."$PICO_THEME_NAME" \ + "$(composer_repo_config "$PICO_THEME_PROJECT" "$DEPENDENCY_VERSION" "$BUILD_DIR/$PICO_THEME_NAME")" + fi + + if [ -n "$PICO_DEPRECATED_DIR" ]; then + echo "Adding Composer repository for '$PICO_DEPRECATED_PROJECT'..." + "$COMPOSER" config repositories."$PICO_DEPRECATED_NAME" \ + "$(composer_repo_config "$PICO_DEPRECATED_PROJECT" "$DEPENDENCY_VERSION" "$BUILD_DIR/$PICO_DEPRECATED_NAME")" + fi + + echo +fi + +# update build version constraints +echo "Updating Composer dependency version constraints..." +"$COMPOSER" require --no-update \ + "$BUILD_PROJECT $DEPENDENCY_VERSION" \ + "$PICO_THEME_PROJECT $DEPENDENCY_VERSION" \ + "$PICO_DEPRECATED_PROJECT $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 "Installing Composer dependencies..." +"$COMPOSER" install --no-dev --optimize-autoloader +echo + +# prepare release +echo "Replacing 'index.php'..." +cp "vendor/$BUILD_PROJECT/index.php.dist" index.php + +echo "Adding 'README.md', 'CONTRIBUTING.md', 'CHANGELOG.md', 'SECURITY.md'..." +cp "vendor/$BUILD_PROJECT/README.md" README.md +cp "vendor/$BUILD_PROJECT/CONTRIBUTING.md" CONTRIBUTING.md +cp "vendor/$BUILD_PROJECT/CHANGELOG.md" CHANGELOG.md +cp "vendor/$BUILD_PROJECT/SECURITY.md" SECURITY.md + +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 + +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 "Removing 'index.php' and 'index.php.dist' from 'vendor/$BUILD_PROJECT'" +rm -f "vendor/$BUILD_PROJECT/index.php" +rm -f "vendor/$BUILD_PROJECT/index.php.dist" + +echo + +# restore composer.json +echo "Restoring Composer dependency version constraints..." +"$COMPOSER" require --no-update \ + "$BUILD_PROJECT ^$VERSION_MAJOR.$VERSION_MINOR" \ + "$PICO_THEME_PROJECT ^$VERSION_MAJOR.$VERSION_MINOR" \ + "$PICO_DEPRECATED_PROJECT ^$VERSION_MAJOR.$VERSION_MINOR" + +if [ "$VERSION_STABILITY" == "dev" ]; then + echo "Removing Composer repositories..." + "$COMPOSER" config --unset repositories."$BUILD_NAME" + + if [ -n "$PICO_THEME_DIR" ]; then + "$COMPOSER" config --unset repositories."$PICO_THEME_NAME" + fi + if [ -n "$PICO_DEPRECATED_DIR" ]; then + "$COMPOSER" config --unset repositories."$PICO_DEPRECATED_NAME" + fi +fi + +echo + +# create release archives +ARCHIVE_FILENAME="$BUILD_NAME-release-$VERSION" + +echo "Creating release archive '$ARCHIVE_FILENAME.tar.gz'..." +find . -mindepth 1 -maxdepth 1 -printf '%f\0' \ + | xargs -0 -- tar -czf "$APP_DIR/$ARCHIVE_FILENAME.tar.gz" -- + +echo "Creating release archive '$ARCHIVE_FILENAME.zip'..." +zip -q -r "$APP_DIR/$ARCHIVE_FILENAME.zip" . + +# publish release +if [ -n "$PUBLISH" ]; then + echo + + # switch to app dir + cd "$APP_DIR" + + # create GitHub release and upload release archives + echo "Creating GitHub release and uploading release archives..." + + GITHUB_PRERELEASE= + [ "$VERSION_STABILITY" == "stable" ] || GITHUB_PRERELEASE="--prerelease" + + gh release create "$VERSION" \ + --title "Version $VERSION_FULL" \ + --generate-notes \ + "$GITHUB_PRERELEASE" \ + "$APP_DIR/$ARCHIVE_FILENAME.tar.gz" \ + "$APP_DIR/$ARCHIVE_FILENAME.zip" +fi diff --git a/.build/clean.sh b/.build/clean.sh deleted file mode 100755 index a816cb8e9..000000000 --- a/.build/clean.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/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/deploy-branch.sh b/.build/deploy-branch.sh deleted file mode 100755 index d8284a7ed..000000000 --- a/.build/deploy-branch.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -set -e - -[ -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;")" -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 deleted file mode 100755 index eef5d70a0..000000000 --- a/.build/deploy-release.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/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" - DEPLOY_FULL="false" -fi -if [ "$DEPLOY_VERSION_BADGE" != "true" ]; then - echo "Skipping version badge deployment because it has been disabled" - DEPLOY_FULL="false" -fi -if [ "$DEPLOY_VERSION_FILE" != "true" ]; then - echo "Skipping version file deployment because it has been disabled" - DEPLOY_FULL="false" -fi -if [ "$DEPLOY_CLOC_STATS" != "true" ]; then - echo "Skipping cloc statistics deployment because it has been disabled" - DEPLOY_FULL="false" -fi - -if [ "$DEPLOY_FULL" != "true" ]; then - if [ "$DEPLOY_PHPDOC_RELEASES" != "true" ] \ - && [ "$DEPLOY_VERSION_BADGE" != "true" ] \ - && [ "$DEPLOY_VERSION_FILE" != "true" ] \ - && [ "$DEPLOY_CLOC_STATS" != "true" ] - then - # nothing to do - exit 0 - fi - echo -fi - -# parse version -. "$PICO_TOOLS_DIR/functions/parse-version.sh.inc" - -if ! parse_version "$PROJECT_REPO_TAG"; then - echo "Invalid version '$PROJECT_REPO_TAG'; aborting..." >&2 - exit 1 -fi - -echo "Deploying Pico $VERSION_MILESTONE ($VERSION_STABILITY)..." -printf 'VERSION_FULL="%s"\n' "$VERSION_FULL" -printf 'VERSION_NAME="%s"\n' "$VERSION_NAME" -printf 'VERSION_ID="%s"\n' "$VERSION_ID" -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 -if [ "$DEPLOY_PHPDOC_RELEASES" == "true" ]; then - # generate phpDocs - generate-phpdoc.sh \ - "$PICO_PROJECT_DIR/.phpdoc.xml" \ - "-" "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT" \ - "Pico $VERSION_MILESTONE API Documentation (v$VERSION_FULL)" - - if [ -n "$(git status --porcelain "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT")" ]; then - # update phpDoc list - update-phpdoc-list.sh \ - "$PICO_DEPLOY_DIR/_data/phpDoc.yml" \ - "$PICO_DEPLOYMENT" "version" "Pico $VERSION_FULL" "$(date +%s)" - - # commit phpDocs - github-commit.sh \ - "Update phpDocumentor class docs for v$VERSION_FULL" \ - "$PICO_DEPLOY_DIR/phpDoc/$PICO_DEPLOYMENT" "$PICO_DEPLOY_DIR/_data/phpDoc.yml" - fi -fi - -# don't update version badge, version file and cloc statistics for pre-releases -if [ "$VERSION_STABILITY" == "stable" ]; then - # update version badge - if [ "$DEPLOY_VERSION_BADGE" == "true" ]; then - generate-badge.sh \ - "$PICO_DEPLOY_DIR/badges/pico-version.svg" \ - "release" "$VERSION_FULL" "blue" - - # commit version badge - github-commit.sh \ - "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 \ - "$PICO_DEPLOY_DIR/_data/version.yml" \ - "$VERSION_FULL" - - # commit version file - github-commit.sh \ - "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 \ - "$PICO_PROJECT_DIR" \ - "$PICO_DEPLOY_DIR/_data/cloc.yml" - - # commit cloc statistics - github-commit.sh \ - "Update cloc statistics for v$VERSION_FULL" \ - "$PICO_DEPLOY_DIR/_data/cloc.yml" - fi -fi - -# deploy -github-deploy.sh "$PROJECT_REPO_SLUG" "tags/$PROJECT_REPO_TAG" "$PROJECT_REPO_COMMIT" diff --git a/.build/init.sh.inc b/.build/init.sh.inc deleted file mode 100644 index e9cee446d..000000000 --- a/.build/init.sh.inc +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100755 index dff079c8e..000000000 --- a/.build/install.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -set -e - -[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; } - -# setup build system -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) { - 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('$PICO_PROJECT_DIR/lib/Pico.php'); - echo preg_replace('/\.[0-9]+-dev$/', '.x-dev', Pico::VERSION); - ")" - fi - - if [ -n "$PICO_VERSION_PATTERN" ]; then - export COMPOSER_ROOT_VERSION="$PICO_VERSION_PATTERN" - fi - - echo -fi - -# install dependencies -echo "Running \`composer install\`$([ -n "$COMPOSER_ROOT_VERSION" ] && echo -n " ($COMPOSER_ROOT_VERSION)")..." -composer install --no-suggest diff --git a/.build/release.sh b/.build/release.sh deleted file mode 100755 index 7a2cc1d0d..000000000 --- a/.build/release.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/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 - -# force minimum stability <= beta due to Parsedown 1.8 currently being in beta -if [ "$VERSION_STABILITY" == "stable" ] || [ "$VERSION_STABILITY" == "rc" ]; then - VERSION_STABILITY="beta" -fi - -# 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 bc9dbf292..9c003e83a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,4 +9,3 @@ /.gitignore export-ignore /.phpcs.xml export-ignore /.phpdoc.xml export-ignore -/.travis.yml export-ignore diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml new file mode 100644 index 000000000..c4829545a --- /dev/null +++ b/.github/actions/install/action.yml @@ -0,0 +1,77 @@ +name: Install Pico CMS +description: Install Pico CMS to the current working directory + +inputs: + path: + description: Install Pico CMS in directory. + required: false + default: . + php-version: + description: PHP version to setup. + required: true + php-tools: + description: Setup additional PHP tools. + required: false + +runs: + using: "composite" + steps: + - name: Setup PHP ${{ inputs.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php-version }} + tools: composer, ${{ inputs.php-tools }} + + - name: Setup Composer auth + shell: bash + working-directory: ${{ inputs.path }} + run: | + composer config --global github-oauth.github.com "${{ github.token }}" + + - name: Get Composer cache directory + shell: bash + working-directory: ${{ inputs.path }} + run: | + COMPOSER_CACHE_DIR="$(composer config --global cache-dir)" + echo "COMPOSER_CACHE_DIR=$COMPOSER_CACHE_DIR" | tee -a "$GITHUB_ENV" + + - name: Restore Composer cache + uses: actions/cache@v2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: ${{ runner.os }}-composer-php${{ inputs.php-version }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Setup Composer root version + if: ${{ github.ref_type == 'branch' }} + shell: bash + working-directory: ${{ inputs.path }} + run: | + COMPOSER_ROOT_VERSION= + + COMPOSER_ROOT_VERSION="$(composer config \ + extra.branch-alias."dev-${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" \ + 2> /dev/null || true)" + + if [ -z "$COMPOSER_ROOT_VERSION" ]; then + COMPOSER_ROOT_VERSION="$(php -r " + require('./lib/Pico.php'); + echo preg_replace('/\.[0-9]+-dev$/', '.x-dev', Pico::VERSION); + ")" + fi + + echo "COMPOSER_ROOT_VERSION=$COMPOSER_ROOT_VERSION" | tee -a "$GITHUB_ENV" + + - name: Install Composer dependencies + shell: bash + working-directory: ${{ inputs.path }} + run: | + composer install + + - name: Read Pico version + shell: bash + working-directory: ${{ inputs.path }} + run: | + PICO_VERSION="$(php -r 'require("./lib/Pico.php"); echo Pico::VERSION;')" + echo "PICO_VERSION=$PICO_VERSION" | tee -a "$GITHUB_ENV" diff --git a/.github/workflows/deploy-branch.yml b/.github/workflows/deploy-branch.yml new file mode 100644 index 000000000..c8fd01beb --- /dev/null +++ b/.github/workflows/deploy-branch.yml @@ -0,0 +1,97 @@ +name: Git branch deployment + +on: + push: + branches: + - 'master' + - 'pico-3.0' + +env: + WEBSITE_REPO_SLUG: picocms/picocms.github.io + WEBSITE_REPO_BRANCH: master + CI_TOOLS_SETUP: https://raw.githubusercontent.com/picocms/ci-tools/master/setup.sh + +jobs: + website: + name: Update website for branch updates + + runs-on: ubuntu-latest + permissions: + contents: write + + env: + PHP_VERSION: '7.4' + BUILD_DIR: ./build + WEBSITE_DIR: ./website + + steps: + - name: Setup CI tools + run: | + . <(curl -fsS -L "$CI_TOOLS_SETUP") + echo "CI_TOOLS_PATH=$CI_TOOLS_PATH" | tee -a "$GITHUB_ENV" + + - name: Checkout repository + uses: actions/checkout@v2 + with: + path: ${{ env.BUILD_DIR }} + + - name: Install Pico CMS + uses: ./build/.github/actions/install + with: + path: ${{ env.BUILD_DIR }} + php-version: ${{ env.PHP_VERSION }} + php-tools: phpdoc + + - name: Read Pico milestone + working-directory: ${{ env.BUILD_DIR }} + run: | + PICO_VERSION_MILESTONE="$(php -r 'require("./lib/Pico.php"); preg_match("/^([0-9]+\.[0-9]+)\./", Pico::VERSION, $m); echo $m[1];')" + echo "PICO_VERSION_MILESTONE=$PICO_VERSION_MILESTONE" | tee -a "$GITHUB_ENV" + + - name: Checkout website repository + uses: actions/checkout@v2 + with: + repository: ${{ env.WEBSITE_REPO_SLUG }} + ref: ${{ env.WEBSITE_REPO_BRANCH }} + path: ${{ env.WEBSITE_DIR }} + + # + # Update phpDoc class docs + # + + - name: Update phpDoc class docs + run: | + "$CI_TOOLS_PATH/generate-phpdoc.sh" \ + "$BUILD_DIR/.phpdoc.xml" \ + "$WEBSITE_DIR/phpDoc/$GITHUB_REF_NAME" \ + "$WEBSITE_DIR/phpDoc/$GITHUB_REF_NAME.cache" \ + "Pico $PICO_VERSION_MILESTONE API Documentation ($GITHUB_REF_NAME branch)" + + - name: Check for phpDoc class docs updates + run: | + PHPDOC_UPDATED="$([ -n "$(git -C "$WEBSITE_DIR" status --porcelain "phpDoc/$GITHUB_REF_NAME.cache")" ] && echo "yes" || echo "no")" + echo "PHPDOC_UPDATED=$PHPDOC_UPDATED" | tee -a "$GITHUB_ENV" + + - name: Update phpDoc class docs list + if: ${{ env.PHPDOC_UPDATED == 'yes' }} + run: | + "$CI_TOOLS_PATH/update-phpdoc-list.sh" \ + "$WEBSITE_DIR/_data/phpDoc.yml" \ + "$GITHUB_REF_NAME" "branch" \ + "$GITHUB_REF_NAME branch" "$(date +%s)" + + - name: Commit phpDoc class docs updates + if: ${{ env.PHPDOC_UPDATED == 'yes' }} + uses: stefanzweifel/git-auto-commit-action@v4 + with: + repository: ${{ env.WEBSITE_DIR }} + file_pattern: >- + phpDoc/${{ github.ref_name }} + phpDoc/${{ github.ref_name }}.cache + _data/phpDoc.yml + commit_user_name: Pico CMS Bot + commit_user_email: bot@picocms.org + commit_message: >- + Update phpDocumentor class docs + for ${{ github.ref_name }} branch + @ ${{ github.sha }} diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml new file mode 100644 index 000000000..96360b8f0 --- /dev/null +++ b/.github/workflows/deploy-release.yml @@ -0,0 +1,172 @@ +name: Git release deployment + +on: + release: + types: [ 'published' ] + +env: + WEBSITE_REPO_SLUG: picocms/picocms.github.io + WEBSITE_REPO_BRANCH: master + CI_TOOLS_SETUP: https://raw.githubusercontent.com/picocms/ci-tools/master/setup.sh + +jobs: + website: + name: Update website for new releases + + runs-on: ubuntu-latest + permissions: + contents: write + + env: + PHP_VERSION: '7.4' + BUILD_DIR: ./build + WEBSITE_DIR: ./website + CLOC_SOURCE: https://github.com/AlDanial/cloc/releases/download/1.92/cloc-1.92.pl + + steps: + - name: Setup CI tools + run: | + . <(curl -fsS -L "$CI_TOOLS_SETUP") + echo "CI_TOOLS_PATH=$CI_TOOLS_PATH" | tee -a "$GITHUB_ENV" + + - name: Checkout repository + uses: actions/checkout@v2 + with: + path: ${{ env.BUILD_DIR }} + + - name: Install Pico CMS + uses: ./build/.github/actions/install + with: + path: ${{ env.BUILD_DIR }} + php-version: ${{ env.PHP_VERSION }} + php-tools: phpdoc + + - name: Parse Pico version + run: | + . "$CI_TOOLS_PATH/parse_version.inc.sh" + + if ! parse_version "$GITHUB_REF_NAME"; then + echo "Invalid version string: $GITHUB_REF_NAME" >&2 + exit 1 + fi + + printf '%s=%s\n' \ + "PICO_VERSION_FULL" "$VERSION_FULL" \ + "PICO_VERSION_STABILITY" "$VERSION_STABILITY" \ + "PICO_VERSION_MILESTONE" "$VERSION_MILESTONE" \ + | tee -a "$GITHUB_ENV" + + - name: Checkout website repository + uses: actions/checkout@v2 + with: + repository: ${{ env.WEBSITE_REPO_SLUG }} + ref: ${{ env.WEBSITE_REPO_BRANCH }} + path: ${{ env.WEBSITE_DIR }} + + # + # Update phpDoc class docs + # + + - name: Update phpDoc class docs + run: | + "$CI_TOOLS_PATH/generate-phpdoc.sh" \ + "$BUILD_DIR/.phpdoc.xml" \ + "$WEBSITE_DIR/phpDoc/$GITHUB_REF_NAME" \ + "$WEBSITE_DIR/phpDoc/$GITHUB_REF_NAME/cache" \ + "Pico $PICO_VERSION_MILESTONE API Documentation ($GITHUB_REF_NAME)" + + - name: Update phpDoc class docs list + run: | + "$CI_TOOLS_PATH/update-phpdoc-list.sh" \ + "$WEBSITE_DIR/_data/phpDoc.yml" \ + "$GITHUB_REF_NAME" "version" \ + "Pico $PICO_VERSION_FULL" "$(date +%s)" + + - name: Commit phpDoc class docs updates + uses: stefanzweifel/git-auto-commit-action@v4 + with: + repository: ${{ env.WEBSITE_DIR }} + file_pattern: >- + phpDoc/${{ github.ref_name }} + _data/phpDoc.yml + commit_user_name: Pico CMS Bot + commit_user_email: bot@picocms.org + commit_message: >- + Update phpDocumentor class docs + for ${{ github.ref_name }} + + # + # Update version badge + # + + - name: Generate version badge + if: ${{ env.PICO_VERSION_STABILITY == 'stable' }} + run: | + "$CI_TOOLS_PATH/generate-badge.sh" \ + "$WEBSITE_DIR/badges/pico-version.svg" \ + "release" "$PICO_VERSION_FULL" "blue" + + - name: Commit version badge + if: ${{ env.PICO_VERSION_STABILITY == 'stable' }} + uses: stefanzweifel/git-auto-commit-action@v4 + with: + repository: ${{ env.WEBSITE_DIR }} + file_pattern: >- + badges/pico-version.svg + commit_user_name: Pico CMS Bot + commit_user_email: bot@picocms.org + commit_message: >- + Update version badge for ${{ github.ref_name }} + + # + # Update version file + # + + - name: Update version file + if: ${{ env.PICO_VERSION_STABILITY == 'stable' }} + run: | + "$CI_TOOLS_PATH/update-version-file.sh" \ + "$WEBSITE_DIR/_data/version.yml" \ + "$PICO_VERSION_FULL" + + - name: Commit version file + if: ${{ env.PICO_VERSION_STABILITY == 'stable' }} + uses: stefanzweifel/git-auto-commit-action@v4 + with: + repository: ${{ env.WEBSITE_DIR }} + file_pattern: >- + _data/version.yml + commit_user_name: Pico CMS Bot + commit_user_email: bot@picocms.org + commit_message: >- + Update version file for ${{ github.ref_name }} + + # + # Update cloc statistics + # + + - name: Install cloc + if: ${{ env.PICO_VERSION_STABILITY == 'stable' }} + run: | + sudo curl -fsS -L -o "/usr/local/bin/cloc" "$CLOC_SOURCE" + sudo chmod +x "/usr/local/bin/cloc" + + - name: Update cloc statistics + if: ${{ env.PICO_VERSION_STABILITY == 'stable' }} + run: | + "$CI_TOOLS_PATH/update-cloc-stats.sh" \ + "$WEBSITE_DIR/_data/cloc.yml" \ + "$BUILD_DIR/lib" \ + "$BUILD_DIR/index.php" + + - name: Commit cloc statistics + if: ${{ env.PICO_VERSION_STABILITY == 'stable' }} + uses: stefanzweifel/git-auto-commit-action@v4 + with: + repository: ${{ env.WEBSITE_DIR }} + file_pattern: >- + _data/cloc.yml + commit_user_name: Pico CMS Bot + commit_user_email: bot@picocms.org + commit_message: >- + Update cloc statistics for ${{ github.ref_name }} diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 878d942c9..5ca512e0d 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -1,28 +1,33 @@ -name: "Mark or close stale issues and PRs" +name: Mark or close stale issues and PRs + on: - schedule: - - cron: "0 12 * * *" + schedule: + - cron: "0 */6 * * *" jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v3 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - days-before-stale: 7 - days-before-close: 2 - stale-issue-message: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed in two days if no further activity - occurs. Thank you for your contributions! :+1: - stale-pr-message: > - This pull request has been automatically marked as stale because it has not had - recent activity. It will be closed in two days if no further activity - occurs. Thank you for your contributions! :+1: - stale-pr-label: "info: Stale" - stale-issue-label: "info: Stale" - exempt-issue-labels: "type: Bug,type: Enhancement,type: Feature,type: Idea,type: Release,info: Pinned" - exempt-pr-labels: "type: Bug,type: Enhancement,type: Feature,type: Idea,type: Release,info: Pinned" - remove-stale-when-updated: true + stale: + name: Mark or close stale issues and PRs + + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/stale@v3 + with: + days-before-stale: 7 + days-before-close: 2 + stale-issue-message: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed in two days if no further activity + occurs. Thank you for your contributions! :+1: + stale-pr-message: > + This pull request has been automatically marked as stale because it has not had + recent activity. It will be closed in two days if no further activity + occurs. Thank you for your contributions! :+1: + stale-pr-label: "info: Stale" + stale-issue-label: "info: Stale" + exempt-issue-labels: "type: Bug,type: Enhancement,type: Feature,type: Idea,type: Release,info: Pinned" + exempt-pr-labels: "type: Bug,type: Enhancement,type: Feature,type: Idea,type: Release,info: Pinned" + remove-stale-when-updated: true diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml new file mode 100644 index 000000000..93b50a46c --- /dev/null +++ b/.github/workflows/test-pr.yml @@ -0,0 +1,27 @@ +name: Test Pico CMS pull request + +on: + pull_request: {} + +jobs: + test: + name: Test Pico CMS + uses: ./.github/workflows/test.yml + + bouncer: + name: Bouncer + + needs: test + if: ${{ always() }} + + runs-on: ubuntu-latest + permissions: {} + + steps: + - name: Check build matrix status + if: ${{ needs.test.result != 'success' }} + run: | + : + echo "Some tests of Pico CMS failed." >&2 + echo "Please check the GitHub workflow logs for details." >&2 + exit 1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..e25e0f271 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,52 @@ +name: Test Pico CMS + +on: + push: + branches: + - 'master' + - 'pico-3.0' + tags: [ 'v*.*.*' ] + workflow_call: {} + +jobs: + test: + name: PHP ${{ matrix.PHP_VERSION }} + + runs-on: ubuntu-latest + permissions: + contents: read + + strategy: + matrix: + PHP_VERSION: + - '7.2' + - '7.3' + - '7.4' + - '8.0' + - '8.1' + - 'nightly' + fail-fast: false + + continue-on-error: ${{ matrix.PHP_VERSION == 'nightly' }} + + env: + PHP_VERSION: ${{ matrix.PHP_VERSION }} + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Pico CMS + uses: ./.github/actions/install + with: + php-version: ${{ env.PHP_VERSION }} + php-tools: phpcs + + - name: Check Pico version + if: ${{ github.ref_type == 'tag' }} + run: | + [ "$GITHUB_REF_NAME" == "v$PICO_VERSION" ] + + - name: Run PHP_CodeSniffer + run: | + phpcs --standard=.phpcs.xml diff --git a/.gitignore b/.gitignore index 490151f25..c30fa9795 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,6 @@ desktop.ini /vendor # Build system -/.build/build -/.build/deploy -/.build/ci-tools /pico-release-*.tar.gz /pico-release-*.zip diff --git a/.htaccess b/.htaccess index b3e76858c..742186e63 100644 --- a/.htaccess +++ b/.htaccess @@ -5,7 +5,7 @@ # Deny access to internal dirs and files by passing the URL to Pico RewriteRule ^(config|content|content-sample|lib|vendor)(/|$) index.php [L] - RewriteRule ^(CHANGELOG\.md|composer\.(json|lock|phar))(/|$) index.php [L] + RewriteRule ^(CHANGELOG\.md|SECURITY.md|composer\.(json|lock|phar))(/|$) index.php [L] RewriteRule (^\.|/\.)(?!well-known(/|$)) index.php [L] # Enable URL rewriting diff --git a/.phpdoc.xml b/.phpdoc.xml index 8f6456e48..0180a69ad 100644 --- a/.phpdoc.xml +++ b/.phpdoc.xml @@ -1,33 +1,32 @@ - - <![CDATA[Pico API Documentation]]> - - .build/phpdoc.cache - - - .build/phpdoc - - -