forked from netz98/n98-magerun
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·100 lines (79 loc) · 2.59 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
#!/bin/bash
#
# build from clean checkout
#
# usage: ./build.sh from project root
set -euo pipefail
IFS=$'\n\t'
remove_assume_unchanged() {
local git_dir="${1}"
local path="${2}"
(
cd "${git_dir}"
rm -f "${path}"
git update-index --assume-unchanged -- "${path}"
)
}
exit_trap() {
local status=$?
if [[ -d "${base_dir}/${build_dir}" ]]; then
echo "trap: removing '${build_dir}'.."
rm -rf "${base_dir}/${build_dir}"
fi
echo "exit ($status)."
}
name="$(awk '/<project name="([^"]*)"/ && !done {print gensub(/<project name="([^"]*)".*/, "\\1", "g"); done=1}' build.xml)"
nice_name="$(php -r "echo str_replace(' ', '', ucwords(strtr('${name}', '-', ' ')));")"
phar="${name}.phar"
echo "Building ${phar}..."
# remove stub which is also the build result destination, so if build fails the file does not exists
remove_assume_unchanged "." "${phar}"
base_dir="$(pwd -P)"
build_dir="build/output"
echo "$0 executed in ${base_dir}"
trap exit_trap EXIT
rm -rf "${build_dir}"
if [[ -d "${build_dir}" ]]; then
>&2 echo "Error: Can not remove build-dir '${build_dir}'"
echo "aborting."
exit 1
fi
mkdir "${build_dir}"
if [[ ! -d "${build_dir}" ]]; then
>&2 echo "Error: Can not create build-dir '${build_dir}'"
echo "aborting."
exit 1
fi
git clone --quiet --no-local --depth 1 -- . "${build_dir}"
# remove fake-phar directly after clone
remove_assume_unchanged "${build_dir}" "n98-magerun.phar"
composer_bin="${base_dir}/vendor/bin/composer"
phing_bin="${base_dir}/vendor/bin/phing"
# Set COMPOSER_HOME if HOME and COMPOSER_HOME not set (shell with no home-dir, e.g. build server with webhook)
if [[ -z ${HOME+x} && -z ${COMPOSER_HOME+x} ]]; then
echo "provision: create COMPOSER_HOME directory for composer (no HOME)"
mkdir -p "build/composer-home"
export COMPOSER_HOME="$(pwd -P)/build/composer-home"
fi
echo "with: $(php --version|head -n 1)"
echo "with: $("${composer_bin}" --version)"
echo "with: $("${phing_bin}" -version)"
cd "${build_dir}"
echo "building in $(pwd -P)"
echo "build version: $(git --no-pager log --oneline -1)"
echo "provision: ulimits (soft) set from $(ulimit -Sn) to $(ulimit -Hn) (hard) for faster phar builds..."
ulimit -Sn $(ulimit -Hn)
timestamp="$(git log --format=format:%ct HEAD -1)" # reproduceable build
echo "build timestamp: ${timestamp}"
php -f "${phing_bin}" -dphar.readonly=0 -- \
-Dcomposer_suffix="${nice_name}${timestamp}" \
-Dcomposer_bin="${composer_bin}" \
dist_clean
php -f build/phar/phar-timestamp.php
php -f "${phar}" -- --version
ls -al "${phar}"
cd -
cp -vp "${build_dir}"/"${phar}" "${phar}"
rm -rf "${build_dir}"
trap - EXIT
echo "done."