Skip to content

Commit 58f6154

Browse files
committed
Refactor Build system
- Separate Travis branch deployment and release deployment stages (also makes `deploy.sh` obsolete) - Add `clean.sh` and `release.sh` scripts to allow users to create "release" packages locally - Use `setup/*.sh` scripts to check and install build dependencies (like PHP_CodeSniffer, phpDocumentor and cloc) - Use `create-release.sh` of `picocms/ci-tools` to create release archives - Streamline script usage Use the following to test Pico and to create a "release" package locally: ```sh cd ~/My-Pico-Workspace/Components/pico ln -rs ../ci-tools .build/ci-tools . ./.build/ci-tools/init/local.sh.inc . ./.build/init.sh.inc phpcs --standard=.phpcs.xml "$PICO_PROJECT_DIR" clean.sh release.sh ```
1 parent 7bbd873 commit 58f6154

File tree

11 files changed

+175
-176
lines changed

11 files changed

+175
-176
lines changed

.build/clean.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; }
5+
6+
# parameters
7+
ARCHIVE_DIR="${1:-$PICO_PROJECT_DIR}" # directory to create release archives in
8+
9+
# print parameters
10+
echo "Cleaning up build environment..."
11+
printf 'PICO_DEPLOY_DIR="%s"\n' "$PICO_DEPLOY_DIR"
12+
printf 'PICO_BUILD_DIR="%s"\n' "$PICO_BUILD_DIR"
13+
printf 'ARCHIVE_DIR="%s"\n' "$ARCHIVE_DIR"
14+
echo
15+
16+
echo "Removing deployment directory..."
17+
[ ! -d "$PICO_DEPLOY_DIR" ] || rm -rf "$PICO_DEPLOY_DIR"
18+
19+
echo "Removing build directory..."
20+
[ ! -d "$PICO_BUILD_DIR" ] || rm -rf "$PICO_BUILD_DIR"
21+
22+
echo "Removing release archives..."
23+
find "$ARCHIVE_DIR" -mindepth 1 -maxdepth 1 \
24+
\( -name 'pico-release-*.tar.gz' -o -name 'pico-release-*.zip' \) \
25+
-delete

.build/create-release.sh

Lines changed: 0 additions & 97 deletions
This file was deleted.

.build/deploy-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
export PATH="$PICO_TOOLS_DIR:$PATH"
4+
[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; }
55

66
# get current Pico milestone
77
VERSION="$(php -r "require_once('$PICO_PROJECT_DIR/lib/Pico.php'); echo Pico::VERSION;")"

.build/deploy-release.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22
set -e
33

4+
[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; }
5+
46
DEPLOY_FULL="true"
57
if [ "$DEPLOY_PHPDOC_RELEASES" != "true" ]; then
68
echo "Skipping phpDoc release deployment because it has been disabled"
@@ -31,10 +33,9 @@ if [ "$DEPLOY_FULL" != "true" ]; then
3133
echo
3234
fi
3335

34-
export PATH="$PICO_TOOLS_DIR:$PATH"
36+
# parse version
3537
. "$PICO_TOOLS_DIR/functions/parse-version.sh.inc"
3638

37-
# parse version
3839
if ! parse_version "$PROJECT_REPO_TAG"; then
3940
echo "Invalid version '$PROJECT_REPO_TAG'; aborting..." >&2
4041
exit 1

.build/deploy.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

.build/init.sh.inc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
if [ -z "$PICO_BUILD_ENV" ]; then
2+
echo "No Pico build environment specified" >&2
3+
exit 1
4+
fi
5+
6+
# add project build dir to $PATH
7+
export PATH="$PICO_PROJECT_DIR/.build:$PATH"
8+
9+
# set environment variables
10+
__picocms_cmd export RELEASE_REPO_SLUG="${RELEASE_REPO_SLUG:-picocms/pico-composer}"
11+
__picocms_cmd export RELEASE_REPO_BRANCH="${RELEASE_REPO_BRANCH:-master}"
12+
13+
if [ "$PROJECT_REPO_SLUG" != "picocms/Pico" ]; then
14+
__picocms_cmd export DEPLOY_REPO_SLUG="${DEPLOY_REPO_SLUG:-$PROJECT_REPO_SLUG}"
15+
__picocms_cmd export DEPLOY_REPO_BRANCH="${DEPLOY_REPO_BRANCH:-gh-pages}"
16+
else
17+
__picocms_cmd export DEPLOY_REPO_SLUG="${DEPLOY_REPO_SLUG:-picocms.github.io}"
18+
__picocms_cmd export DEPLOY_REPO_BRANCH="${DEPLOY_REPO_BRANCH:-master}"
19+
fi

.build/install.sh

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,17 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
# setup build system
5-
echo "Installing build dependencies..."
6-
echo
7-
8-
case "$1" in
9-
"--deploy")
10-
echo "Synchronizing package index files..."
11-
sudo apt-get update
12-
echo
13-
14-
echo "Installing cloc..."
15-
sudo apt-get install -y cloc
16-
echo
17-
18-
echo "Installing phpDocumentor..."
19-
curl --location --output "$PICO_TOOLS_DIR/phpdoc" \
20-
"https://github.com/phpDocumentor/phpDocumentor2/releases/latest/download/phpDocumentor.phar"
21-
chmod +x "$PICO_TOOLS_DIR/phpdoc"
22-
echo
23-
;;
24-
esac
25-
26-
echo "Installing PHP_CodeSniffer..."
27-
if [ "$(php -r 'echo PHP_VERSION_ID;')" -ge 50400 ]; then
28-
PHPCS_DOWNLOAD="https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/"
29-
else
30-
PHPCS_DOWNLOAD="https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.9.2/"
31-
fi
32-
33-
curl --location --output "$PICO_TOOLS_DIR/phpcs" \
34-
"$PHPCS_DOWNLOAD/phpcs.phar"
35-
chmod +x "$PICO_TOOLS_DIR/phpcs"
36-
37-
curl --location --output "$PICO_TOOLS_DIR/phpcbf" \
38-
"$PHPCS_DOWNLOAD/phpcbf.phar"
39-
chmod +x "$PICO_TOOLS_DIR/phpcbf"
4+
[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; }
405

41-
echo
42-
43-
# setup composer
44-
echo "Setup Composer..."
45-
46-
# let composer use our GITHUB_OAUTH_TOKEN
47-
if [ -n "$GITHUB_OAUTH_TOKEN" ]; then
48-
composer config --global github-oauth.github.com "$GITHUB_OAUTH_TOKEN"
49-
fi
6+
# setup build system
7+
BUILD_REQUIREMENTS=( --phpcs )
8+
[ "$1" != "--deploy" ] || BUILD_REQUIREMENTS+=( --cloc --phpdoc )
9+
"$PICO_TOOLS_DIR/setup/$PICO_BUILD_ENV.sh" "${BUILD_REQUIREMENTS[@]}"
5010

5111
# set COMPOSER_ROOT_VERSION when necessary
5212
if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -n "$PROJECT_REPO_BRANCH" ]; then
13+
echo "Setting up Composer..."
14+
5315
PICO_VERSION_PATTERN="$(php -r "
5416
\$json = json_decode(file_get_contents('$PICO_PROJECT_DIR/composer.json'), true);
5517
if (\$json !== null) {
@@ -69,9 +31,9 @@ if [ -z "$COMPOSER_ROOT_VERSION" ] && [ -n "$PROJECT_REPO_BRANCH" ]; then
6931
if [ -n "$PICO_VERSION_PATTERN" ]; then
7032
export COMPOSER_ROOT_VERSION="$PICO_VERSION_PATTERN"
7133
fi
72-
fi
7334

74-
echo
35+
echo
36+
fi
7537

7638
# install dependencies
7739
echo "Running \`composer install\`$([ -n "$COMPOSER_ROOT_VERSION" ] && echo -n " ($COMPOSER_ROOT_VERSION)")..."

.build/release.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; }
5+
6+
# parameters
7+
VERSION="${1:-$PROJECT_REPO_TAG}" # version to create a release for
8+
ARCHIVE_DIR="${2:-$PICO_PROJECT_DIR}" # directory to create release archives in
9+
10+
# print parameters
11+
echo "Creating new release..."
12+
printf 'VERSION="%s"\n' "$VERSION"
13+
echo
14+
15+
# guess version string
16+
if [ -z "$VERSION" ]; then
17+
PICO_VERSION="$(php -r "
18+
require_once('$PICO_PROJECT_DIR/lib/Pico.php');
19+
echo preg_replace('/-(?:dev|n|nightly)(?:[.-]?[0-9]+)?(?:[.-]dev)?$/', '', Pico::VERSION);
20+
")"
21+
22+
VERSION="v$PICO_VERSION-dev+${PROJECT_REPO_BRANCH:-master}"
23+
echo "Creating development release of Pico v$PICO_VERSION ($VERSION)..."
24+
echo
25+
fi
26+
27+
# parse version
28+
. "$PICO_TOOLS_DIR/functions/parse-version.sh.inc"
29+
30+
if ! parse_version "$VERSION"; then
31+
echo "Unable to create release archive: Invalid version '$VERSION'" >&2
32+
exit 1
33+
fi
34+
35+
DEPENDENCY_VERSION="$VERSION_FULL@$VERSION_STABILITY"
36+
if [ "$VERSION_STABILITY" == "dev" ] && [ -n "$VERSION_BUILD" ]; then
37+
DEPENDENCY_VERSION="dev-$VERSION_BUILD"
38+
fi
39+
40+
# clone repo
41+
github-clone.sh "$PICO_BUILD_DIR" "https://github.com/$RELEASE_REPO_SLUG.git" "$RELEASE_REPO_BRANCH"
42+
43+
cd "$PICO_BUILD_DIR"
44+
45+
# force Pico version
46+
echo "Updating composer dependencies..."
47+
composer require --no-update \
48+
"picocms/pico $DEPENDENCY_VERSION" \
49+
"picocms/pico-theme $DEPENDENCY_VERSION" \
50+
"picocms/pico-deprecated $DEPENDENCY_VERSION"
51+
echo
52+
53+
# set minimum stability
54+
if [ "$VERSION_STABILITY" != "stable" ]; then
55+
echo "Setting minimum stability to '$VERSION_STABILITY'..."
56+
composer config "minimum-stability" "$VERSION_STABILITY"
57+
composer config "prefer-stable" "true"
58+
echo
59+
fi
60+
61+
# install dependencies
62+
echo "Running \`composer install\`..."
63+
composer install --no-suggest --prefer-dist --no-dev --optimize-autoloader
64+
echo
65+
66+
# prepare release
67+
echo "Replacing 'index.php'..."
68+
cp vendor/picocms/pico/index.php.dist index.php
69+
70+
echo "Adding 'README.md', 'CONTRIBUTING.md', 'CHANGELOG.md'..."
71+
cp vendor/picocms/pico/README.md README.md
72+
cp vendor/picocms/pico/CONTRIBUTING.md CONTRIBUTING.md
73+
cp vendor/picocms/pico/CHANGELOG.md CHANGELOG.md
74+
75+
echo "Removing '.git' directories of plugins and themes..."
76+
find themes/ -type d -path 'themes/*/.git' -print0 | xargs -0 rm -rf
77+
find plugins/ -type d -path 'plugins/*/.git' -print0 | xargs -0 rm -rf
78+
79+
echo "Preparing 'composer.json' for release..."
80+
composer require --no-update \
81+
"picocms/pico ^$VERSION_MILESTONE" \
82+
"picocms/pico-theme ^$VERSION_MILESTONE" \
83+
"picocms/pico-deprecated ^$VERSION_MILESTONE"
84+
85+
# create release archives
86+
create-release.sh "$PICO_BUILD_DIR" "$ARCHIVE_DIR" "pico-release-v$VERSION_FULL"

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/.github export-ignore
21
/.build export-ignore
2+
/.github export-ignore
33
/assets/.gitignore export-ignore
44
/config/.gitignore export-ignore
55
/content/.gitignore export-ignore

.gitignore

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ desktop.ini
1010
.DS_Store
1111
._*
1212

13-
# composer
13+
# Composer
1414
/composer.lock
15-
/composer.phar
1615
/vendor
1716

17+
# Build system
18+
/.build/build
19+
/.build/deploy
20+
/.build/ci-tools
21+
/pico-release-*.tar.gz
22+
/pico-release-*.zip
23+
1824
# phpDocumentor
1925
/.build/phpdoc
2026
/.build/phpdoc.cache
21-
/phpDocumentor.phar

0 commit comments

Comments
 (0)