forked from thirtybees/thirtybees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·129 lines (102 loc) · 2.79 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
#!/usr/bin/env bash
# This script builds an installation package from the current repository.
#
# Usage: ./build.sh [<git branch>]
#
# Currently, only Git branches 'master' and 'HEAD' make sense, because the
# same branch name is used for each submodule, too. Default is branch 'master'.
GIT_BRANCH="${1:-master}"
TB_VERSION=$((cat install-dev/install_version.php &&
echo 'print(_TB_INSTALL_VERSION_);') | \
php)
echo "Packaging thirty bees version ${TB_VERSION}."
echo "Assuming all module repositories are up to date."
# Create packaging directory.
DIR=$(mktemp -d)
trap "rm -rf ${DIR}" 0
DIR+="/thirtybees-v${TB_VERSION}"
mkdir "${DIR}"
export DIR
# Collect Git repositories to deal with. This is a bit slow, but parsing
# .gitmodules directly is unreliable.
REPOS_GIT=($(
git submodule | \
cut -b 2- | \
cut -d ' ' -f 2
))
REPOS_GIT+=(".")
# Files not needed in the release package.
EXCLUDE_FILE=(".coveralls.yml")
EXCLUDE_FILE+=(".gitignore")
EXCLUDE_FILE+=(".gitmodules")
EXCLUDE_FILE+=(".scrutinizer.yml")
EXCLUDE_FILE+=(".travis.yml")
EXCLUDE_FILE+=("architecture.md")
EXCLUDE_FILE+=("build.sh")
EXCLUDE_FILE+=("codeception.yml")
EXCLUDE_FILE+=("composer.lock")
# Directories not needed in the release package.
EXCLUDE_DIR=("docs")
EXCLUDE_DIR+=("examples")
EXCLUDE_DIR+=("Examples")
EXCLUDE_DIR+=("tests")
EXCLUDE_DIR+=("Tests")
EXCLUDE_DIR+=("unitTests")
# As always, there are some exceptions :-)
KEEP=("lib/Twig/Node/Expression/Test")
KEEP_FLAGS=()
for E in "${KEEP[@]}"; do
KEEP_FLAGS+=("!")
KEEP_FLAGS+=("-path")
KEEP_FLAGS+=("\*${E}\*")
done
# Create copies of all the stuff.
# Try to copy not much more than what's needed.
# Git repositories.
export D
for D in "${REPOS_GIT[@]}"; do
(
echo -n "Copying ${D} ... "
cd ${D} || continue
mkdir -p "${DIR}/${D}"
git archive "${GIT_BRANCH}" | tar -C "${DIR}/${D}" -xf-
cd "${DIR}/${D}"
if [ -d admin-dev ]; then
mv admin-dev admin
fi
if [ -d install-dev ]; then
mv install-dev install
fi
echo "done."
)
done
# Composer repositories. Not reasonably doable without network access,
# but fortunately composer maintains a cache, so no heavy downloads.
(
cd "${DIR}" || exit 1
composer install --no-dev
composer dump-autoload -o
)
# Cleaning :-)
(
cd "${DIR}"
for E in "${EXCLUDE_FILE[@]}"; do
find . "${KEEP_FLAGS[@]}" -type f -name "${E}" -delete
done
for E in "${EXCLUDE_DIR[@]}"; do
find . "${KEEP_FLAGS[@]}" -type d -name "${E}" | while read D; do
rm -rf "${D}"
done
done
)
# Make the package.
(
echo -n "Creating package ... "
cd "${DIR}"
php ./tools/generatemd5list.php
zip -r -q $(basename "${DIR}").zip .
echo "done."
)
mv "${DIR}"/$(basename "${DIR}").zip .
echo "Created $(basename "${DIR}").zip successfully."
exit 0