Skip to content

Commit 2d1050b

Browse files
committed
Installation as composer dependency
1 parent 8256869 commit 2d1050b

File tree

13 files changed

+64
-59
lines changed

13 files changed

+64
-59
lines changed

codeLink.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env bash
22

3-
source common.sh
4-
source validation/configurationValidation.sh
3+
# Assume that we are in vendor/bin directory. If you know how to get the real path of this script, don't hesitate ;)
4+
readonly BENCHMARK_KIT_PATH=$(dirname $(cd `dirname $0` && pwd))"/phpbenchmarks/benchmark-kit"
5+
source $BENCHMARK_KIT_PATH/common.sh
6+
source $BENCHMARK_KIT_PATH/validation/configurationValidation.sh
57

68
function isValidUrl {
79
local url=$1

codeValidation.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#!/usr/bin/env bash
22

3+
# Assume that we are in vendor/bin directory. If you know how to get the real path of this script, don't hesitate ;)
4+
readonly BENCHMARK_KIT_PATH=$(dirname $(cd `dirname $0` && pwd))"/phpbenchmarks/benchmark-kit"
5+
source $BENCHMARK_KIT_PATH/common.sh
6+
source $BENCHMARK_KIT_PATH/validation/configurationValidation.sh
7+
38
function validateCode {
49
local containerName=$1
510

6-
cp common.sh $RESULT_TYPE_PATH/docker/codeValidation
11+
cp "$BENCHMARK_KIT_PATH/common.sh" $RESULT_TYPE_PATH/docker/codeValidation
712

813
cd $RESULT_TYPE_PATH/docker/codeValidation
914

@@ -32,9 +37,6 @@ function validateCode {
3237
echoValidationGroupEnd
3338
}
3439

35-
source common.sh
36-
source validation/configurationValidation.sh
37-
3840
echoValidationGroupStart "Validation of .phpbenchmarks directory"
3941
copyConfigurationFiles "$CONFIGURATION_PATH"
4042
assertCommonConfiguration

common.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ function definePhpComponentConfigurationValues {
108108
sed -i -e "s~____PHPBENCHMARKS_PHP_7_3_ENABLED____~$PHPBENCHMARKS_PHP_7_3_ENABLED~g" $phpFile
109109

110110
sed -i -e "s~____PHPBENCHMARKS_BENCHMARK_URL____~$PHPBENCHMARKS_BENCHMARK_URL~g" $phpFile
111-
sed -i -e "s~____PHPBENCHMARKS_SLUG____~$PHPBENCHMARKS_SLUG~g" $phpFile
111+
112+
sed -i -e "s~____PHPBENCHMARKS_COMPONENT_SLUG____~$PHPBENCHMARKS_COMPONENT_SLUG~g" $phpFile
112113

113114
sed -i -e "s~____PHPBENCHMARKS_DEPENDENCY_NAME____~$PHPBENCHMARKS_DEPENDENCY_NAME~g" $phpFile
114115
sed -i -e "s~____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____~$PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION~g" $phpFile
@@ -141,7 +142,7 @@ function validateBranchName {
141142
echoValidationWarning "Branch names are not validated. Don't forget to remove '--repositories-not-created' parameter when repositories will be created."
142143
else
143144
local gitBranch=$(cd $INSTALLATION_PATH && git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' -e 's/(//g' -e 's/)//g')
144-
local expectedGitBranch="$PHPBENCHMARKS_SLUG"_"$PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION.$PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION"_"$RESULT_TYPE_SLUG"
145+
local expectedGitBranch="$PHPBENCHMARKS_COMPONENT_SLUG"_"$PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION.$PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION"_"$RESULT_TYPE_SLUG"
145146
if [ $VALIDATE_DEV == true ]; then
146147
expectedGitBranch=$expectedGitBranch"_prepare"
147148
fi
@@ -177,9 +178,9 @@ function assertReadMe {
177178

178179
local oldIFS=$IFS
179180
IFS=
180-
local validReadMeContent=$(cat validation/mainRepository/README.md)
181-
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_SLUG____/$PHPBENCHMARKS_SLUG}
182-
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_NAME____/$PHPBENCHMARKS_NAME}
181+
local validReadMeContent=$(cat $BENCHMARK_KIT_PATH/validation/mainRepository/README.md)
182+
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_COMPONENT_SLUG____/$PHPBENCHMARKS_COMPONENT_SLUG}
183+
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_COMPONENT_NAME____/$PHPBENCHMARKS_COMPONENT_NAME}
183184
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____/$PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION}
184185
validReadMeContent=${validReadMeContent//____PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION____/$PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION}
185186
local readMeContent=$(cat $INSTALLATION_PATH/README.md)

composerUpdate.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env bash
22

3-
source common.sh
4-
source validation/configurationValidation.sh
3+
# Assume that we are in vendor/bin directory. If you know how to get the real path of this script, don't hesitate ;)
4+
readonly BENCHMARK_KIT_PATH=$(dirname $(cd `dirname $0` && pwd))"/phpbenchmarks/benchmark-kit"
5+
source $BENCHMARK_KIT_PATH/common.sh
6+
source $BENCHMARK_KIT_PATH/validation/configurationValidation.sh
57

68
echoValidationGroupStart "Validation of .phpbenchmarks directory"
79
copyConfigurationFiles "$CONFIGURATION_PATH"
@@ -10,12 +12,12 @@ echoValidationGroupEnd
1012

1113
validateBranchName
1214

13-
cp common.sh docker/composerUpdate
14-
copyConfigurationFiles "docker/composerUpdate/componentFiles/.phpbenchmarks"
15+
cp "$BENCHMARK_KIT_PATH/common.sh" "$BENCHMARK_KIT_PATH/docker/composerUpdate"
16+
copyConfigurationFiles "$BENCHMARK_KIT_PATH/docker/composerUpdate/componentFiles/.phpbenchmarks"
1517

16-
source docker/composerUpdate/createEnv.sh
18+
source "$BENCHMARK_KIT_PATH/docker/composerUpdate/createEnv.sh"
1719
echoValidationGroupStart "Building Docker container"
18-
cd docker/composerUpdate
20+
cd "$BENCHMARK_KIT_PATH/docker/composerUpdate"
1921
if [ $VERBOSE_LEVEL -ge 2 ]; then
2022
docker-compose up --build --no-start
2123
[ $? != "0" ] && exitScript "Error while building Docker container."

docker/benchmarkKit/cli/ComponentConfiguration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class ComponentConfiguration
1111
public const PHP_7_3_ENABLED = ____PHPBENCHMARKS_PHP_7_3_ENABLED____;
1212

1313
public const URL = "____PHPBENCHMARKS_BENCHMARK_URL____";
14-
public const SLUG = "____PHPBENCHMARKS_SLUG____";
14+
public const SLUG = "____PHPBENCHMARKS_COMPONENT_SLUG____";
1515

16-
public const COMMON_REPOSITORY = '____PHPBENCHMARKS_SLUG____-common';
16+
public const COMMON_REPOSITORY = '____PHPBENCHMARKS_COMPONENT_SLUG____-common';
1717

1818
public const DEPENDENCY_NAME = "____PHPBENCHMARKS_DEPENDENCY_NAME____";
1919
public const DEPENDENCY_MAJOR_VERSION = ____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____;

docker/composerUpdate/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM phpbenchmarks/benchmark-kit:1.0.0
1+
FROM phpbenchmarks/benchmark-kit:1.0.1
22

33
COPY entrypoint.sh /var/phpbenchmarks
44
RUN chmod +x /var/phpbenchmarks/entrypoint.sh

docker/composerUpdate/createEnv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
readonly ENV_DIR="$(dirname $0)/docker/composerUpdate"
3+
readonly ENV_DIR="$BENCHMARK_KIT_PATH/docker/composerUpdate"
44

55
echoValidationGroupStart "Create $ENV_DIR/.env"
66

documentation/installation.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ You will need this dependencies to make it work:
99
Installation
1010
-
1111

12+
Add `phpbenchmarks/benchmark-kit` as dependency of your projet.
13+
14+
Not you have to do it in `require`, not in `require-dev`.
15+
As benchmark kit contains only bash scripts, requiring it will not affect your code until you call them manually.
16+
1217
```bash
13-
mkdir ~/benchmarkKit
14-
cd ~/benchmarkKit
15-
echo '{"require": {"phpbenchmarks/benchmark-kit": "^1.0"}}' > composer.json
16-
docker run --rm -v $(pwd):/app composer/composer update
17-
# composer update is called with root user, so change permissions to current user
18-
sudo chown -R $USER:$USER vendor
18+
composer require phpbenchmarks/benchmark-kit ^1.0
1919
```
2020

2121
[Back to documentation index](../README.md)

initializeBranch.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env bash
22

3-
source common.sh
4-
source validation/configurationValidation.sh
3+
# Assume that we are in vendor/bin directory. If you know how to get the real path of this script, don't hesitate ;)
4+
readonly BENCHMARK_KIT_PATH=$(dirname $(cd `dirname $0` && pwd))"/phpbenchmarks/benchmark-kit"
5+
source $BENCHMARK_KIT_PATH/common.sh
6+
source $BENCHMARK_KIT_PATH/validation/configurationValidation.sh
57

68
function downloadGitHubFile {
79
local file=$1
@@ -123,8 +125,8 @@ function createConfigurationFile {
123125
defineVariableInConfigurationFile "PHPBENCHMARKS_PHP_7_3_ENABLED" "$PHPBENCHMARKS_PHP_7_3_ENABLED" false "true/false"
124126

125127
echo "" >> $configurationFilePath
126-
defineVariableInConfigurationFile "PHPBENCHMARKS_NAME" "$PHPBENCHMARKS_NAME" true
127-
defineVariableInConfigurationFile "PHPBENCHMARKS_SLUG" "$PHPBENCHMARKS_SLUG" true
128+
defineVariableInConfigurationFile "PHPBENCHMARKS_COMPONENT_NAME" "$PHPBENCHMARKS_COMPONENT_NAME" true
129+
defineVariableInConfigurationFile "PHPBENCHMARKS_COMPONENT_SLUG" "$PHPBENCHMARKS_COMPONENT_SLUG" true
128130

129131
echo "" >> $configurationFilePath
130132
defineVariableInConfigurationFile "PHPBENCHMARKS_BENCHMARK_URL" "$PHPBENCHMARKS_BENCHMARK_URL" true
@@ -146,7 +148,7 @@ function createInitBenchmarkFile {
146148
if [ ! -f "$initBenchmarkPath" ]; then
147149
echoValidationGroupStart "Create .phpbenchmarks/initBenchmark.sh"
148150

149-
cp validation/mainRepository/.phpbenchmarks/initBenchmark.sh $INSTALLATION_PATH/.phpbenchmarks/
151+
cp "$BENCHMARK_KIT_PATH/validation/mainRepository/.phpbenchmarks/initBenchmark.sh" "$INSTALLATION_PATH/.phpbenchmarks/"
150152
[ $? != "0" ] && exitScript "Error while writing $initBenchmarkPath."
151153
echoValidatedTest "File created."
152154
echoValidatedTest "Function initBenchmark() created."
@@ -165,7 +167,7 @@ function createVhostFile {
165167
if [ ! -f "$vhostPath" ]; then
166168
echoValidationGroupStart "Create .phpbenchmarks/vhost.conf"
167169

168-
cp validation/mainRepository/.phpbenchmarks/vhost.conf $INSTALLATION_PATH/.phpbenchmarks/
170+
cp "$BENCHMARK_KIT_PATHvalidation/mainRepository/.phpbenchmarks/vhost.conf" "$INSTALLATION_PATH/.phpbenchmarks/"
169171
[ $? != "0" ] && exitScript "Error while writing $vhostPath."
170172
echoValidatedTest "File created."
171173
echoValidationWarning ".phpbenchmarks/vhost.conf has been created with default nginx virtual host configuration. Edit it if needed."

validation/common.sh

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
COMPONENT_TYPE=$1
44
RESULT_TYPE_SLUG=$2
5-
INSTALLATION_PATH=$3
65
showCliWarning=false
76

87
if [ "$COMPONENT_TYPE" != "framework" ] && [ "$COMPONENT_TYPE" != "templateEngine" ]; then
@@ -29,19 +28,16 @@ if [ "$RESULT_TYPE_SLUG" != "hello-world" ] && [ "$RESULT_TYPE_SLUG" != "rest-ap
2928
exitScript "Invalid benchmark type."
3029
fi
3130

32-
if [ "$INSTALLATION_PATH" == "" ]; then
33-
showCliWarning=true
34-
echoAsk "Path to your code?" false
35-
echo ""
36-
read INSTALLATION_PATH
37-
fi
38-
if [ ! -d "$INSTALLATION_PATH" ]; then
39-
exitScript "Invalid path to your code: $INSTALLATION_PATH."
40-
fi
41-
4231
if [ $showCliWarning == true ]; then
43-
echoWarning "You could use \"$0 $COMPONENT_TYPE $RESULT_TYPE_SLUG $INSTALLATION_PATH\"."
32+
echoWarning "You could use \"$0 $COMPONENT_TYPE $RESULT_TYPE_SLUG\"."
4433
fi
4534

46-
readonly RESULT_TYPE_PATH="$(dirname $0)/validation/$COMPONENT_TYPE/$RESULT_TYPE_SLUG"
35+
readonly INSTALLATION_PATH="$BENCHMARK_KIT_PATH/../../.."
36+
readonly RESULT_TYPE_PATH="$BENCHMARK_KIT_PATH/validation/$COMPONENT_TYPE/$RESULT_TYPE_SLUG"
37+
if [ ! -d $RESULT_TYPE_PATH ]; then
38+
exitScript "$RESULT_TYPE_PATH is not a valid directory."
39+
fi
4740
readonly CONFIGURATION_PATH="$RESULT_TYPE_PATH/componentFiles/.phpbenchmarks"
41+
if [ ! -d "$CONFIGURATION_PATH" ]; then
42+
mkdir "$CONFIGURATION_PATH"
43+
fi

validation/configurationValidation.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
source "$(dirname $0)/validation/common.sh"
3+
source "$BENCHMARK_KIT_PATH/validation/common.sh"
44

55
function copyConfigurationFiles {
66
local destinationPath=$1
@@ -52,13 +52,13 @@ function assertCommonConfiguration {
5252
&& exitScript "[.phpbenchmarks/configuration.sh] Should define \$PHPBENCHMARKS_PHP_7_3_ENABLED. See README.md for more informations."
5353
echoValidatedTest "[.phpbenchmarks/configuration.sh] Define \$PHPBENCHMARKS_PHP_7_3_ENABLED ($PHPBENCHMARKS_PHP_7_3_ENABLED)."
5454

55-
[ "$PHPBENCHMARKS_NAME" == "" ] \
56-
&& exitScript "[.phpbenchmarks/configuration.sh] Should define \$PHPBENCHMARKS_NAME. See README.md for more informations."
57-
echoValidatedTest "[.phpbenchmarks/configuration.sh] Define \$PHPBENCHMARKS_NAME ($PHPBENCHMARKS_NAME)."
55+
[ "$PHPBENCHMARKS_COMPONENT_NAME" == "" ] \
56+
&& exitScript "[.phpbenchmarks/configuration.sh] Should define \$PHPBENCHMARKS_COMPONENT_NAME. See README.md for more informations."
57+
echoValidatedTest "[.phpbenchmarks/configuration.sh] Define \$PHPBENCHMARKS_COMPONENT_NAME ($PHPBENCHMARKS_COMPONENT_NAME)."
5858

59-
[ "$PHPBENCHMARKS_SLUG" == "" ] \
60-
&& exitScript "[.phpbenchmarks/configuration.sh] Should define \$PHPBENCHMARKS_SLUG. See README.md for more informations."
61-
echoValidatedTest "[.phpbenchmarks/configuration.sh] Define \$PHPBENCHMARKS_SLUG ($PHPBENCHMARKS_SLUG)."
59+
[ "$PHPBENCHMARKS_COMPONENT_SLUG" == "" ] \
60+
&& exitScript "[.phpbenchmarks/configuration.sh] Should define \$PHPBENCHMARKS_COMPONENT_SLUG. See README.md for more informations."
61+
echoValidatedTest "[.phpbenchmarks/configuration.sh] Define \$PHPBENCHMARKS_COMPONENT_SLUG ($PHPBENCHMARKS_COMPONENT_SLUG)."
6262

6363
[ "$PHPBENCHMARKS_BENCHMARK_URL" == "" ] \
6464
&& exitScript "[.phpbenchmarks/configuration.sh] Should define \$PHPBENCHMARKS_BENCHMARK_URL. See README.md for more informations."

validation/framework/hello-world/docker/codeValidation/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM phpbenchmarks/benchmark-kit:1.0.0
1+
FROM phpbenchmarks/benchmark-kit:1.0.1
22

33
# copy config files
44
COPY componentFiles/.phpbenchmarks /var/phpbenchmarks/componentFiles/.phpbenchmarks/

validation/mainRepository/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ Our benchmarking protocol is available on [benchmarking protocol page](http://ww
1414

1515
## What is this repository ?
1616

17-
It contains ____PHPBENCHMARKS_NAME____ installation `only`.
17+
It contains ____PHPBENCHMARKS_COMPONENT_NAME____ installation `only`.
1818
To reuse code between minor versions, features for benchmarks are not coded in this repository
19-
but in [phpbenchmarks/____PHPBENCHMARKS_SLUG____-common](https://github.com/phpbenchmarks/____PHPBENCHMARKS_SLUG____-common) repository.
19+
but in [phpbenchmarks/____PHPBENCHMARKS_COMPONENT_SLUG____-common](https://github.com/phpbenchmarks/____PHPBENCHMARKS_COMPONENT_SLUG____-common) repository.
2020

2121
Switch branch to select version and benchmark you want to see.
2222

2323
## Benchmarks
2424

25-
You can find ____PHPBENCHMARKS_NAME____ ____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____.____PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION____ benchmarks results on
26-
[benchmarks results page](http://www.phpbenchmarks.com/en/benchmark/____PHPBENCHMARKS_SLUG____/____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____.____PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION____).
25+
You can find ____PHPBENCHMARKS_COMPONENT_NAME____ ____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____.____PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION____ benchmarks results on
26+
[benchmarks results page](http://www.phpbenchmarks.com/en/benchmark/____PHPBENCHMARKS_COMPONENT_SLUG____/____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____.____PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION____).
2727

28-
See all ____PHPBENCHMARKS_NAME____ benchmarked versions on [select version page](http://www.phpbenchmarks.com/en/benchmark/____PHPBENCHMARKS_SLUG____/version).
28+
See all ____PHPBENCHMARKS_COMPONENT_NAME____ benchmarked versions on [select version page](http://www.phpbenchmarks.com/en/benchmark/____PHPBENCHMARKS_COMPONENT_SLUG____/version).
2929

3030
## Community
3131

0 commit comments

Comments
 (0)