forked from Saisengen/wikibots
/
compile.sh
executable file
·156 lines (136 loc) · 4.55 KB
/
compile.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
shopt -s nullglob
LAYERS_DIR="/layers/heroku_php"
if ! [[ -d "$LAYERS_DIR" ]]; then
IN_TOOLFORGE_BUILD="no"
LAYERS_DIR="/tmp/wikibots_build"
else
IN_TOOLFORGE_BUILD="yes"
fi
LAYER_DIR="$LAYERS_DIR/wikibots"
PUBLIC_HTML="$LAYER_DIR/public_html"
BIN_DIR="$LAYER_DIR/bin"
# Add here any new directories you want to compile
CGI_PROJECTS=(
web-services/*
)
BIN_PROJECTS=(
other-bots/*
)
export_to_bin_dir() {
echo "#################################################"
echo "## BIN Export start ##"
local dest_dir="${1?}"
mkdir -p "$dest_dir"
# Compiled files
for project in "${BIN_PROJECTS[@]}"; do
if [[ -d "$project" ]]; then
if [[ -d "$project/bin/Release" ]]; then
echo "## Gathering $project"
echo " Getting binaries and libs"
cp -a "$project"/bin/Release/*/linux-x64/publish/* "$dest_dir/"
else
echo "Unable to find release for project $project, did you forget to add it to the solutions file?"
echo " dotnet sln add $project"
fi
fi
done
echo "## Export end ##"
echo "#################################################"
}
export_to_html_dir() {
echo "#################################################"
echo "## CGI-BIN Export start ##"
local dest_dir="${1?}"
local static_files
mkdir -p "$dest_dir/cgi-bin"
# Static files
for file in web-services/*html web-services/*ico; do
echo "Gathering static file $file"
cp "$file" "$dest_dir/"
done
# Compiled files
for project in "${CGI_PROJECTS[@]}"; do
if [[ -d "$project" ]]; then
if [[ -d "$project/bin/Release" ]]; then
echo "## Gathering $project"
echo " Getting binaries and libs"
cp -a "$project"/bin/Release/*/linux-x64/publish/* "$dest_dir/cgi-bin/"
echo " Getting static content if any"
static_files=("$project"/*.html)
if [[ "${static_files[*]}" != "" ]]; then
cp "$project"/*.html "$dest_dir/cgi-bin/"
fi
else
echo "Unable to find release for project $project, did you forget to add it to the solutions file?"
echo " dotnet sln add $project"
fi
fi
done
echo "## Export end ##"
echo "#################################################"
}
build_all() {
echo "#################################################"
echo "## Building start ##"
local dotnet_build="dotnet publish --self-contained --runtime linux-x64"
echo "#################################################"
echo "## Compiling all.sln ##"
$dotnet_build all.sln
echo "## Building end ##"
echo "#################################################"
}
populate_procfile() {
echo "#################################################"
echo "## Populating procfile ##"
# This adds an entry in the procfile for each of the binaries built
# so they can be used in jobs
for executable in $(find "$PUBLIC_HTML" -type f -executable -print); do
# skip files with extensions
if ! [[ "$executable" == *.* ]]; then
echo "Creating Procfile entry point ${executable##*/}"
echo "${executable##*/}: $executable" >> Procfile
fi
done
for executable in $(find "$BIN_DIR" -type f -executable -print); do
# skip files with extensions
if ! [[ "$executable" == *.* ]]; then
echo "Creating Procfile entry point ${executable##*/}"
echo "${executable##*/}: $executable" >> Procfile
fi
done
echo "#################################################"
}
add_buildpack_layer_config() {
echo "#################################################"
echo "## Creating buildpack layer config ##"
cat >>"$LAYER_DIR.toml" <<EOL
[types]
launch = true
build = false
cache = false
EOL
echo "#################################################"
}
cleanup() {
echo "#################################################"
echo "## Cleanup ##"
# Remove all the temporary files we generated
git clean -fdx
echo "#################################################"
}
main() {
build_all
export_to_html_dir "$PUBLIC_HTML"
export_to_bin_dir "$BIN_DIR"
populate_procfile
add_buildpack_layer_config
cleanup
if [[ "$IN_TOOLFORGE_BUILD" == "no" ]]; then
echo "Local build, you can find the output at $LAYER_DIR"
fi
}
main "$@"