diff --git a/.build/create-release.sh b/.build/create-release.sh new file mode 100755 index 0000000..8522e32 --- /dev/null +++ b/.build/create-release.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +set -e + +export PATH="$PICO_TOOLS_DIR:$PATH" +. "$PICO_TOOLS_DIR/functions/parse-version.sh.inc" + +# parameters +ARCHIVE="$1" # release archive file name + +if [ -z "$ARCHIVE" ]; then + echo "Unable to create release archive: No file name specified" >&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 + +# 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 'config/config.yml.template'..." +cp vendor/picocms/pico/config/config.yml.template config/config.yml.template + +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 archive +echo "Creating release archive '$ARCHIVE'..." + +if [ -e "$ARCHIVE" ]; then + echo "Unable to create release archive: File exists" >&2 + exit 1 +fi + +find . -mindepth 1 -maxdepth 1 -printf '%f\0' \ + | xargs -0 -- tar -czf "$ARCHIVE" -- +echo 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 new file mode 100755 index 0000000..137d92e --- /dev/null +++ b/.build/deploy-release.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env bash +set -e + +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 + +export PATH="$PICO_TOOLS_DIR:$PATH" +. "$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 +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_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/deploy.sh b/.build/deploy.sh new file mode 100755 index 0000000..0ef0c10 --- /dev/null +++ b/.build/deploy.sh @@ -0,0 +1,6 @@ +#!/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/install.sh b/.build/install.sh new file mode 100755 index 0000000..5dde051 --- /dev/null +++ b/.build/install.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -e + +# setup build system +echo "Installing build dependencies..." + +case "$1" in + "--deploy") + echo "Synchronizing package index files..." + sudo apt-get update + + echo "Installing packages..." + sudo apt-get install -y cloc + ;; +esac + +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 + +# set COMPOSER_ROOT_VERSION when necessary +if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -n "$PROJECT_REPO_BRANCH" ]; then + 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 +fi + +echo + +# install dependencies +echo "Running \`composer install\`$([ -n "$COMPOSER_ROOT_VERSION" ] && echo -n " ($COMPOSER_ROOT_VERSION)")..." +composer install --no-suggest diff --git a/.gitattributes b/.gitattributes index 38ea2cc..f03d557 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,12 @@ -/.github export-ignore -/_build export-ignore -/.gitattributes export-ignore -/.gitignore export-ignore -/.phpcs.xml export-ignore -/.phpdoc.xml export-ignore -/.travis.yml export-ignore -/index.php.dist export-ignore +/.github export-ignore +/.build export-ignore +/assets/.gitignore export-ignore +/config/.gitignore export-ignore +/content/.gitignore export-ignore +/plugins/.gitignore export-ignore +/themes/.gitignore export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.phpcs.xml export-ignore +/.phpdoc.xml export-ignore +/.travis.yml export-ignore diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ec08db4 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,48 @@ + diff --git a/.gitignore b/.gitignore index 673e405..bccec62 100644 --- a/.gitignore +++ b/.gitignore @@ -10,28 +10,12 @@ desktop.ini .DS_Store ._* -# Composer +# composer /composer.lock /composer.phar /vendor -# Build system -/_build/phpdoc -/_build/phpdoc.cache -/_build/deploy-*.git - -# User config -/config/config.php - -# User themes -/themes/* -!/themes/default - -# User plugins -/plugins/* -!/plugins/0?-* -!/plugins/1?-* -!/plugins/DummyPlugin.php - -# User content -/content +# phpDocumentor +/.build/phpdoc +/.build/phpdoc.cache +/phpDocumentor.phar diff --git a/.htaccess b/.htaccess index 453a3e3..b3e7685 100644 --- a/.htaccess +++ b/.htaccess @@ -2,13 +2,19 @@ RewriteEngine On # May be required to access sub directories #RewriteBase / + + # 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 (^\.|/\.)(?!well-known(/|$)) index.php [L] + + # Enable URL rewriting RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule ^(.*)$ index.php?$1 [L,QSA] - RewriteRule ^(\.git|config|content|content-sample|lib|vendor)(/.*)?$ index.php?$0 [L,QSA] - RewriteRule ^(CHANGELOG\.md|composer\.(json|lock)) index.php?404 [L] + RewriteRule ^ index.php [L] + # Let Pico know about available URL rewriting SetEnv PICO_URL_REWRITING 1 diff --git a/.phpcs.xml b/.phpcs.xml index 77a35e5..2592313 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -11,9 +11,10 @@ . - ^_build/ + ^.build/ + ^.github/ ^vendor/ *.min.js @@ -41,4 +42,15 @@ + + + + *.js + + + *.js + diff --git a/.phpdoc.xml b/.phpdoc.xml index c46b6da..f924f31 100644 --- a/.phpdoc.xml +++ b/.phpdoc.xml @@ -1,11 +1,11 @@ - <![CDATA[Pico 1.0 API Documentation]]> + <![CDATA[Pico API Documentation]]> - _build/phpdoc.cache + .build/phpdoc.cache - _build/phpdoc + .build/phpdoc