Skip to content

Commit 96f1590

Browse files
committed
Initialize responseBody.txt, initBenchmark.sh, vhost.conf and README.md
1 parent 15e8ca9 commit 96f1590

File tree

9 files changed

+130
-51
lines changed

9 files changed

+130
-51
lines changed

common.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,53 @@ function definePhpCliVersion {
159159
sudo /usr/bin/update-alternatives --set php /usr/bin/php$phpVersion
160160
}
161161

162+
function copyReadMe {
163+
local readMePath="$CONFIGURATION_PATH/../README.md"
164+
if [ -f "$readMePath" ]; then
165+
rm "$readMePath"
166+
fi
167+
168+
cp $INSTALLATION_PATH/README.md $readMePath
169+
[ $? != "0" ] && exitScript "[README.md] Error while copying README.md."
170+
}
171+
172+
function assertReadMe {
173+
local askToModify=$1
174+
echoValidationGroupStart "Validation of README.md"
175+
176+
assertFileExist "README.md"
177+
178+
local oldIFS=$IFS
179+
IFS=
180+
local validReadMeContent=$(cat validation/mainRepository/README.md)
181+
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_SLUG____/$PHPBENCHMARKS_SLUG}
182+
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_NAME____/$PHPBENCHMARKS_NAME}
183+
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____/$PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION}
184+
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION____/$PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION}
185+
local readMeContent=$(cat $INSTALLATION_PATH/README.md)
186+
187+
if [ "$validReadMeContent" != "$readMeContent" ]; then
188+
if [ "$askToModify" == "true" ] | [ "$askToModify" == "" ]; then
189+
echoAsk "Content of README.md is not valid. Do you want to modify it automaticaly? [Y/n]"
190+
read editReadMe
191+
else
192+
local editReadMe="y"
193+
fi
194+
195+
if [ "$editReadMe" == "" ] || [ "$editReadMe" == "y" ] || [ "$editReadMe" == "Y" ]; then
196+
echo "$validReadMeContent" > $INSTALLATION_PATH/README.md
197+
198+
copyReadMe
199+
local readMeContent=$(cat $INSTALLATION_PATH/README.md)
200+
fi
201+
fi
202+
IFS=$oldIFS
203+
[ "$validReadMeContent" != "$readMeContent" ] && exitScript "[README.md] Content is invalid."
204+
echoValidatedTest "[README.md] Content is valid."
205+
206+
echoValidationGroupEnd
207+
}
208+
162209
VERBOSE_LEVEL=0
163210
for param in "$@"; do
164211
if [ "$param" == "-v" ]; then

documentation/initializeBranch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ You can use `initializeBranch.sh` to create them.
77
<br>
88
Feel free to edit them manually.
99

10-
* `README.md`: explanations about phpbenchmarks.com, this repository etc.
10+
* `README.md`: explanations about phpbenchmarks.com, this repository etc.
1111
* `.phpbenchmarks/vhost.conf`: nginx configuration for virtual host.
1212
* `.phpbenchmarks/configuration.sh`: configure enabled PHP versions, component version etc.
1313
* `.phpbenchmarks/initBenchmark.sh`: should contains `initBenchmark()` function. Called before the benchmark to clear cache, install dependencies etc.

initializeBranch.sh

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source common.sh
44
source validation/configurationValidation.sh
55

6-
function downloadGithubFile {
6+
function downloadGitHubFile {
77
local file=$1
88
local url="https://raw.githubusercontent.com/phpbenchmarks/$slugToCopy/$GITHUB_BRANCH/$file"
99
local showValidationSuccess=true
@@ -32,9 +32,9 @@ function downloadFilesFromGithub {
3232

3333
readonly GITHUB_BRANCH="$slugToCopy"_"$versionToCopy"_"$RESULT_TYPE_SLUG"
3434
echoValidationGroupStart "Downloading files from https://github.com/phpbenchmarks/$slugToCopy/tree/$GITHUB_BRANCH"
35-
downloadGithubFile ".phpbenchmarks/configuration.sh"
36-
downloadGithubFile ".phpbenchmarks/initBenchmark.sh"
37-
downloadGithubFile ".phpbenchmarks/vhost.conf"
35+
downloadGitHubFile ".phpbenchmarks/configuration.sh"
36+
downloadGitHubFile ".phpbenchmarks/initBenchmark.sh"
37+
downloadGitHubFile ".phpbenchmarks/vhost.conf"
3838
source $RESULT_TYPE_PATH/downloadFilesFromGithub.sh
3939
echoValidationGroupEnd
4040
}
@@ -140,6 +140,43 @@ function createConfigurationFile {
140140
echoValidationGroupEnd
141141
}
142142

143+
function createInitBenchmarkFile {
144+
local initBenchmarkPath="$INSTALLATION_PATH/.phpbenchmarks/initBenchmark.sh"
145+
146+
if [ ! -f "$initBenchmarkPath" ]; then
147+
echoValidationGroupStart "Create .phpbenchmarks/initBenchmark.sh"
148+
149+
cp validation/mainRepository/.phpbenchmarks/initBenchmark.sh $INSTALLATION_PATH/.phpbenchmarks/
150+
[ $? != "0" ] && exitScript "Error while writing $initBenchmarkPath."
151+
echoValidatedTest "File created."
152+
echoValidatedTest "Function initBenchmark() created."
153+
echoValidationWarning ".phpbenchmarks/initBenchmark.sh::initBenchmark() has been created, but is nearly empty. Add commands to initialize benchmark here."
154+
155+
if [ $VERBOSE_LEVEL -eq 0 ]; then
156+
echo ""
157+
fi
158+
echoValidationGroupEnd
159+
fi
160+
}
161+
162+
function createVhostFile {
163+
local vhostPath="$INSTALLATION_PATH/.phpbenchmarks/vhost.conf"
164+
165+
if [ ! -f "$vhostPath" ]; then
166+
echoValidationGroupStart "Create .phpbenchmarks/vhost.conf"
167+
168+
cp validation/mainRepository/.phpbenchmarks/vhost.conf $INSTALLATION_PATH/.phpbenchmarks/
169+
[ $? != "0" ] && exitScript "Error while writing $vhostPath."
170+
echoValidatedTest "File created."
171+
echoValidationWarning ".phpbenchmarks/vhost.conf has been created with default nginx virtual host configuration. Edit it if needed."
172+
173+
if [ $VERBOSE_LEVEL -eq 0 ]; then
174+
echo ""
175+
fi
176+
echoValidationGroupEnd
177+
fi
178+
}
179+
143180
createPhpbenchmarksDirectories
144181

145182
echoAsk "Copy configuration files from another location? [github/NONE]" false
@@ -156,3 +193,7 @@ fi
156193

157194
createCodeLinkFile
158195
createConfigurationFile
196+
createInitBenchmarkFile
197+
createVhostFile
198+
assertReadMe false
199+
source $RESULT_TYPE_PATH/initializeBranch.sh

validation/configurationValidation.sh

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22

33
source "$(dirname $0)/validation/common.sh"
44

5-
function copyReadMe {
6-
local readMePath="$CONFIGURATION_PATH/../README.md"
7-
if [ -f "$readMePath" ]; then
8-
rm "$readMePath"
9-
fi
10-
11-
cp $INSTALLATION_PATH/README.md $readMePath
12-
[ $? != "0" ] && exitScript "[README.md] Error while copying README.md."
13-
}
14-
155
function copyConfigurationFiles {
166
local destinationPath=$1
177

@@ -118,38 +108,3 @@ function assertInitBenchmark {
118108
&& validationFailedExit "Function init_benchmark.sh::initBenchmark() does not exist. See README.md for more informations."
119109
echoValidatedTest "[.phpbenchmarks/initBenchmark.sh] Function initBenchmark() exist."
120110
}
121-
122-
function assertReadMe {
123-
echoValidationGroupStart "Validation of README.md"
124-
125-
assertFileExist "README.md"
126-
127-
local oldIFS=$IFS
128-
IFS=
129-
local validReadMeContent=$(cat validation/mainRepositoryReadme.md)
130-
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_SLUG____/$PHPBENCHMARKS_SLUG}
131-
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_NAME____/$PHPBENCHMARKS_NAME}
132-
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____/$PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION}
133-
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION____/$PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION}
134-
local readMeContent=$(cat $CONFIGURATION_PATH/../README.md)
135-
IFS=$oldIFS
136-
if [ "$validReadMeContent" != "$readMeContent" ]; then
137-
echoAsk "Content of README.md is not valid. Do you want to modify it automaticaly? [Y/n]"
138-
read editReadMe
139-
140-
if [ $VERBOSE_LEVEL -eq 0 ]; then
141-
echo ""
142-
fi
143-
144-
if [ "$editReadMe" == "" ] || [ "$editReadMe" == "y" ] || [ "$editReadMe" == "Y" ]; then
145-
echo "$validReadMeContent" > $INSTALLATION_PATH/README.md
146-
147-
copyReadMe
148-
local readMeContent=$(cat $CONFIGURATION_PATH/../README.md)
149-
fi
150-
fi
151-
[ "$validReadMeContent" != "$readMeContent" ] && exitScript "[README.md] Content is invalid."
152-
echoValidatedTest "[README.md] Content is valid."
153-
154-
echoValidationGroupEnd
155-
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
downloadGithubFile ".phpbenchmarks/responseBody/responseBody.txt"
3+
downloadGitHubFile ".phpbenchmarks/responseBody/responseBody.txt"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
if [ ! -f "$INSTALLATION_PATH/.phpbenchmarks/responseBody/responseBody.txt" ]; then
4+
echoValidationGroupStart "Create .phpbenchmarks/responseBody/responseBody.txt"
5+
echo "Hello World !" > "$INSTALLATION_PATH/.phpbenchmarks/responseBody/responseBody.txt"
6+
[ $? != "0" ] && exitScript "Error while creating $INSTALLATION_PATH/.phpbenchmarks/responseBody/responseBody.txt."
7+
echoValidatedTest "File created."
8+
echoValidationGroupEnd
9+
fi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
function initBenchmark {
4+
# add commands to initialize benchmark: clear cache and logs, warmp up cache etc
5+
6+
composer install --no-dev --classmap-authoritative
7+
[ $? != "0" ] && exit 1
8+
9+
return 0
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
server {
2+
listen 80;
3+
server_name ____HOST____;
4+
root ____PROJECT_DIR____/public;
5+
location / {
6+
try_files $uri /index.php$is_args$args;
7+
}
8+
location ~ ^/(index).php(/|$) {
9+
fastcgi_pass unix:/run/php/____PHP_FPM_SOCK____;
10+
fastcgi_split_path_info ^(.+.php)(/.*)$;
11+
include fastcgi_params;
12+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
13+
fastcgi_param HTTPS off;
14+
}
15+
error_log /var/log/nginx/benchmark_error.log;
16+
access_log /var/log/nginx/benchmark_access.log;
17+
}

0 commit comments

Comments
 (0)