raykolbe/DOMPDFModule

View on GitHub
build.sh

Summary

Maintainability
Test Coverage
#!/usr/bin/env bash
# ------------------------------------------------------------------
# [Raymond J Kolbe] Build Tools
#                   Simple build tools pipeline inspired by ABC
#                   http://abc.tools.qafoo.com/ and Ant Maven
#                   https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
# ------------------------------------------------------------------

set -euo pipefail

readonly PROJECT_ROOT=${PWD}
readonly BUILD_LOGS=${PROJECT_ROOT}/build/logs
readonly BUILD_DIST=${PROJECT_ROOT}/build/dist
readonly VENDOR_BIN=${PROJECT_ROOT}/vendor/bin

echo "Starting new build..."

# ------------------------------------------------------------------
# Clean
#
# Remove all files generated by the previous build
# ------------------------------------------------------------------
echo "Cleaning project space...";

rm -rf ${PROJECT_ROOT}/vendor
rm -rf ${BUILD_LOGS}
rm -rf ${BUILD_DIST}

# ------------------------------------------------------------------
# Validate
#
# Validate the project is correct and all necessary information is available.
# ------------------------------------------------------------------
echo "Validating project space...";

# Ensure PHP interpreter exists.
which php &> /dev/null || {
    echo 'PHP interpreter not found. Aborting build.'
    exit 1
}

# Ensure supported PHP version (5.6.0+)
php -r 'exit((int) !(PHP_VERSION_ID >= 50600));' || {
    echo 'Unsupported version of PHP. Aborting build.'
    exit 1
}

# Ensure PHP Composer exists.
which composer &> /dev/null || {
    echo 'PHP Composer not found. Aborting build.'
    exit 1
}

composer validate --strict

# ------------------------------------------------------------------
# Initialize
#
# Initialize build state, e.g. set properties or create directories.
# ------------------------------------------------------------------
echo "Initializing project space...";

mkdir ${BUILD_LOGS}
mkdir ${BUILD_DIST}

# ------------------------------------------------------------------
# Compile
#
# Compiles the project source code. For PHP this means, that a lint check will be run on the source files.
# ------------------------------------------------------------------
echo "Compiling project...";

composer --prefer-dist install

php -l ${PROJECT_ROOT}/src
php -l ${PROJECT_ROOT}/config
php -l ${PROJECT_ROOT}/tests
php -l ${PROJECT_ROOT}/Module.php

# ------------------------------------------------------------------
# Test
#
# Run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
# ------------------------------------------------------------------
echo "Executing tests...";

${VENDOR_BIN}/phpunit ${PROJECT_ROOT}/tests -v -c ${PROJECT_ROOT}/tests/phpunit.xml

# ------------------------------------------------------------------
# Package
#
# Package the code in its distributable format (i.e. zip, phar, etc.).
# ------------------------------------------------------------------
echo "Packaging artifacts...";

# PHP Composer relies on git archives so we mimic what a dist looks like.
git archive --format=tar.gz -o ${BUILD_DIST}/SNAPSHOT.tar.gz HEAD

# ------------------------------------------------------------------
# Integration test
#
# Process and deploy the package if necessary into an environment where integration tests can be run.
# ------------------------------------------------------------------
echo "Executing integration tests...";
# TODO Placeholder for integration test suite.

# ------------------------------------------------------------------
# Verify
#
# Static analysis and code quality checks.
# ------------------------------------------------------------------
echo "Verifying source...";

${VENDOR_BIN}/phpcs --standard=PSR2 src
${VENDOR_BIN}/phpcs --standard=PSR2 config
${VENDOR_BIN}/phpcs --standard=PSR2 tests
${VENDOR_BIN}/phpmd config,src,tests text cleancode,codesize,controversial,design,naming,unusedcode

# ------------------------------------------------------------------
# Install
# ------------------------------------------------------------------
echo "Installing package...";
# TODO Placeholder for local installation.

# ------------------------------------------------------------------
# Deploy
# ------------------------------------------------------------------
echo "Deploying package...";
# TODO Placeholder for automatic publishing of artifact.

echo "Build complete...";