-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathbuild.sh
executable file
·131 lines (106 loc) · 4.36 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/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...";