Skip to content

Commit 0c58371

Browse files
committed
Create initializeBranch.sh
1 parent ec512a5 commit 0c58371

14 files changed

+246
-60
lines changed

codeLink.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function validateCodeLinks {
2121
hasNewValues=true
2222
invalidUrl=true
2323
while [ $invalidUrl == true ]; do
24-
echoWarningAsk "${codeLinkNames[$codeLinkKey]}"
24+
echoAsk "${codeLinkNames[$codeLinkKey]}"
2525
read sourceCodeUrl
2626

2727
if ! isValidUrl "$sourceCodeUrl"; then
@@ -38,7 +38,7 @@ function validateCodeLinks {
3838
done
3939

4040
if [ $hasNewValues == true ]; then
41-
echoWarningAsk "Write .phpbenchmarks/codeLink.sh with new values? [Y/n]"
41+
echoAsk "Write .phpbenchmarks/codeLink.sh with new values? [Y/n]"
4242
read writeCodeLinkFile
4343
if [ "$writeCodeLinkFile" == "" ] || [ "$writeCodeLinkFile" == "y" ] || [ "$writeCodeLinkFile" == "Y" ]; then
4444
codeLinkInstallationPath="$INSTALLATION_PATH/.phpbenchmarks/codeLink.sh"

common.sh

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,29 @@ function echoValidationGroupStart {
4141
function echoValidationWarning {
4242
if [ $VERBOSE_LEVEL -ge 1 ]; then
4343
echo -e " \e[43m > \e[00m \e[43m $1 \e[00m"
44+
else
45+
echo -e "\e[43m $1 \e[00m"
4446
fi
4547
}
4648

4749
function echoValidatedTest {
50+
local message=$1
51+
local title=$2
52+
[ "$title" == "" ] && title="Validated"
53+
4854
if [ $VERBOSE_LEVEL -ge 1 ]; then
49-
echo -e " \e[42m > \e[00m \e[32mValidated\e[00m $1"
55+
echo -e " \e[42m > \e[00m \e[32m$title\e[00m $1"
5056
fi
5157
}
5258

53-
function echoWarningAsk {
59+
function echoAsk {
5460
local message=$1
61+
local isInValidationGroup=$2
5562

56-
if [ $VERBOSE_LEVEL -ge 1 ]; then
57-
echo -n -e " \e[43m > \e[00m \e[43m $message \e[00m "
63+
if [ "$isInValidationGroup" == "false" ] || [ $VERBOSE_LEVEL -le 0 ]; then
64+
echo -n -e "\e[45m $message \e[00m "
5865
else
59-
echo -n -e "\e[43m $message \e[00m "
66+
echo -n -e " \e[45m > \e[00m \e[45m $message \e[00m "
6067
fi
6168
}
6269

@@ -103,10 +110,10 @@ function definePhpComponentConfigurationValues {
103110
sed -i -e "s~____PHPBENCHMARKS_BENCHMARK_URL____~$PHPBENCHMARKS_BENCHMARK_URL~g" $phpFile
104111
sed -i -e "s~____PHPBENCHMARKS_SLUG____~$PHPBENCHMARKS_SLUG~g" $phpFile
105112

106-
sed -i -e "s~____PHPBENCHMARKS_MAIN_REPOSITORY____~$PHPBENCHMARKS_MAIN_REPOSITORY~g" $phpFile
107-
sed -i -e "s~____PHPBENCHMARKS_MAJOR_VERSION____~$PHPBENCHMARKS_MAJOR_VERSION~g" $phpFile
108-
sed -i -e "s~____PHPBENCHMARKS_MINOR_VERSION____~$PHPBENCHMARKS_MINOR_VERSION~g" $phpFile
109-
sed -i -e "s~____PHPBENCHMARKS_BUGFIX_VERSION____~$PHPBENCHMARKS_BUGFIX_VERSION~g" $phpFile
113+
sed -i -e "s~____PHPBENCHMARKS_DEPENDENCY_NAME____~$PHPBENCHMARKS_DEPENDENCY_NAME~g" $phpFile
114+
sed -i -e "s~____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____~$PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION~g" $phpFile
115+
sed -i -e "s~____PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION____~$PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION~g" $phpFile
116+
sed -i -e "s~____PHPBENCHMARKS_DEPENDENCY_BUGFIX_VERSION____~$PHPBENCHMARKS_DEPENDENCY_BUGFIX_VERSION~g" $phpFile
110117
}
111118

112119
function validateComposerJson {
@@ -134,7 +141,7 @@ function validateBranchName {
134141
echoValidationWarning "Branch names are not validated. Don't forget to remove '--repositories-not-created' parameter when repositories will be created."
135142
else
136143
local gitBranch=$(cd $INSTALLATION_PATH && git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' -e 's/(//g' -e 's/)//g')
137-
local expectedGitBranch="$PHPBENCHMARKS_SLUG"_"$PHPBENCHMARKS_MAJOR_VERSION.$PHPBENCHMARKS_MINOR_VERSION"_"$RESULT_TYPE_SLUG"
144+
local expectedGitBranch="$PHPBENCHMARKS_SLUG"_"$PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION.$PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION"_"$RESULT_TYPE_SLUG"
138145
if [ $VALIDATE_DEV == true ]; then
139146
expectedGitBranch=$expectedGitBranch"_prepare"
140147
fi

docker/benchmarkKit/cli/Command/AbstractCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected function getCommonDevBranchName(): string
106106
'dev-'
107107
. ComponentConfiguration::SLUG
108108
. '_'
109-
. ComponentConfiguration::VERSION_MAJOR
109+
. ComponentConfiguration::DEPENDENCY_MAJOR_VERSION
110110
. '_'
111111
. $this->getResultTypeSlug()
112112
. '_prepare';
@@ -124,6 +124,6 @@ protected function getCommonProdBranchPrefix(OutputInterface $output): string
124124
);
125125
}
126126

127-
return ComponentConfiguration::VERSION_MAJOR . '.' . $commonMinorVersion . '.';
127+
return ComponentConfiguration::DEPENDENCY_MAJOR_VERSION . '.' . $commonMinorVersion . '.';
128128
}
129129
}

docker/benchmarkKit/cli/Command/ValidateComposerJsonCommand.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,32 @@ private function validateLicense(OutputInterface $output, array $data): self
7878

7979
private function validateRequireComponent(OutputInterface $output, array $data): self
8080
{
81-
if (is_null($data['require'][ComponentConfiguration::MAIN_REPOSITORY] ?? null)) {
81+
if (is_null($data['require'][ComponentConfiguration::DEPENDENCY_NAME] ?? null)) {
8282
$this->validationFailed(
8383
$output,
84-
'It should require ' . ComponentConfiguration::MAIN_REPOSITORY . '. See README.md for more informations.'
84+
'It should require ' . ComponentConfiguration::DEPENDENCY_NAME . '. See README.md for more informations.'
8585
);
8686
}
8787

8888
if (
89-
$data['require'][ComponentConfiguration::MAIN_REPOSITORY] === ComponentConfiguration::getVersion()
90-
|| $data['require'][ComponentConfiguration::MAIN_REPOSITORY] === 'v' . ComponentConfiguration::getVersion()
89+
$data['require'][ComponentConfiguration::DEPENDENCY_NAME] === ComponentConfiguration::getDependencyVersion()
90+
|| $data['require'][ComponentConfiguration::DEPENDENCY_NAME] === 'v' . ComponentConfiguration::getDependencyVersion()
9191
) {
9292
$this->validationSuccess(
9393
$output,
9494
'Require '
95-
. ComponentConfiguration::MAIN_REPOSITORY
95+
. ComponentConfiguration::DEPENDENCY_NAME
9696
. ': '
97-
. $data['require'][ComponentConfiguration::MAIN_REPOSITORY]
97+
. $data['require'][ComponentConfiguration::DEPENDENCY_NAME]
9898
. '.'
9999
);
100100
} else {
101101
$this->validationFailed(
102102
$output,
103103
'It should require '
104-
. ComponentConfiguration::MAIN_REPOSITORY
104+
. ComponentConfiguration::DEPENDENCY_NAME
105105
. ' as '
106-
. ComponentConfiguration::getVersion()
106+
. ComponentConfiguration::getDependencyVersion()
107107
. '. See README.md for more informations.'
108108
);
109109
}

docker/benchmarkKit/cli/Command/ValidateComposerLockCommand.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ private function validateComponentVersion(OutputInterface $output, array $data):
8787
{
8888
$packageFound = false;
8989
foreach ($data['packages'] as $package) {
90-
if ($package['name'] === ComponentConfiguration::MAIN_REPOSITORY) {
90+
if ($package['name'] === ComponentConfiguration::DEPENDENCY_NAME) {
9191
$packageFound = true;
9292

9393
if (
94-
$package['version'] !== ComponentConfiguration::getVersion()
95-
&& $package['version'] !== 'v' . ComponentConfiguration::getVersion())
94+
$package['version'] !== ComponentConfiguration::getDependencyVersion()
95+
&& $package['version'] !== 'v' . ComponentConfiguration::getDependencyVersion())
9696
{
9797
$this->validationFailed(
9898
$output,
9999
'Package '
100-
. ComponentConfiguration::MAIN_REPOSITORY
100+
. ComponentConfiguration::DEPENDENCY_NAME
101101
. ' version should be '
102-
. ComponentConfiguration::getVersion()
102+
. ComponentConfiguration::getDependencyVersion()
103103
. ', '
104104
. $package['version']
105105
. ' found.'
@@ -108,9 +108,9 @@ private function validateComponentVersion(OutputInterface $output, array $data):
108108
$this->validationSuccess(
109109
$output,
110110
'Package '
111-
. ComponentConfiguration::MAIN_REPOSITORY
111+
. ComponentConfiguration::DEPENDENCY_NAME
112112
. ' version is '
113-
. ComponentConfiguration::getVersion()
113+
. ComponentConfiguration::getDependencyVersion()
114114
. '.'
115115
);
116116
break;
@@ -119,7 +119,7 @@ private function validateComponentVersion(OutputInterface $output, array $data):
119119
}
120120

121121
if ($packageFound === false) {
122-
$this->validationFailed($output, 'Package ' . ComponentConfiguration::MAIN_REPOSITORY . ' not found.');
122+
$this->validationFailed($output, 'Package ' . ComponentConfiguration::DEPENDENCY_NAME . ' not found.');
123123
}
124124

125125
return $this;
@@ -165,7 +165,7 @@ private function validateCommonVersion(OutputInterface $output, array $data): se
165165
}
166166

167167
if ($packageFound === false) {
168-
$this->validationFailed($output, 'Package ' . ComponentConfiguration::MAIN_REPOSITORY . ' not found.');
168+
$this->validationFailed($output, 'Package ' . ComponentConfiguration::DEPENDENCY_NAME . ' not found.');
169169
}
170170
} else {
171171
$this->repositoriesNotCreatedWarning($output);

docker/benchmarkKit/cli/ComponentConfiguration.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ class ComponentConfiguration
1515
public const URL = "____PHPBENCHMARKS_BENCHMARK_URL____";
1616
public const SLUG = "____PHPBENCHMARKS_SLUG____";
1717

18-
public const MAIN_REPOSITORY = "____PHPBENCHMARKS_MAIN_REPOSITORY____";
1918
public const COMMON_REPOSITORY = '____PHPBENCHMARKS_SLUG____-common';
20-
public const VERSION_MAJOR = ____PHPBENCHMARKS_MAJOR_VERSION____;
21-
public const VERSION_MINOR = ____PHPBENCHMARKS_MINOR_VERSION____;
22-
public const VERSION_BUGFIX = ____PHPBENCHMARKS_BUGFIX_VERSION____;
2319

24-
public static function getVersion(): string
20+
public const DEPENDENCY_NAME = "____PHPBENCHMARKS_DEPENDENCY_NAME____";
21+
public const DEPENDENCY_MAJOR_VERSION = ____PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION____;
22+
public const DEPENDENCY_MINOR_VERSION = ____PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION____;
23+
public const DEPENDENCY_BUGFIX_VERSION = ____PHPBENCHMARKS_DEPENDENCY_BUGFIX_VERSION____;
24+
25+
public static function getDependencyVersion(): string
2526
{
26-
return static::VERSION_MAJOR . '.' . static::VERSION_MINOR . '.' . static::VERSION_BUGFIX;
27+
return
28+
static::DEPENDENCY_MAJOR_VERSION
29+
. '.'
30+
. static::DEPENDENCY_MINOR_VERSION
31+
. '.'
32+
. static::DEPENDENCY_BUGFIX_VERSION;
2733
}
2834

2935
public static function getEnabledPhpVersions(): array

documentation/initializeBranch.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Initialize code
1+
Initialize branch
22
-
33

44
To make benchmark kit works, some file are required in your `main` repository branch.
@@ -22,6 +22,10 @@ Without any parameter, it will ask you 3 informations:
2222
* benchmark type (hello-world or rest-api)
2323
* path to your code
2424

25+
Available options:
26+
* `-v`: view each validations performed
27+
* `-vv`: view each validations performed and wget output if configuration files are downloaded from github
28+
2529
```bash
2630
# will ask the 3 informations
2731
./initializeBranch.sh

initializeBranch.sh

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/env bash
2+
3+
source common.sh
4+
source validation/configurationValidation.sh
5+
6+
function downloadGithubFile {
7+
local file=$1
8+
local url="https://raw.githubusercontent.com/phpbenchmarks/$slugToCopy/$GITHUB_BRANCH/$file"
9+
local showValidationSuccess=true
10+
11+
if [ $VERBOSE_LEVEL -ge 2 ]; then
12+
wget -O $INSTALLATION_PATH/$file $url
13+
[ $? != "0" ] && showValidationSuccess=false && rm $INSTALLATION_PATH/$file && echoValidationWarning "Error while downloading $url."
14+
else
15+
wget -O $INSTALLATION_PATH/$file $url &>/tmp/phpbenchmarks.download
16+
[ $? != "0" ] && showValidationSuccess=false && rm $INSTALLATION_PATH/$file && cat /tmp/phpbenchmarks.download && echoValidationWarning "Error while downloading $url."
17+
fi
18+
19+
if [ $showValidationSuccess == true ]; then
20+
echoValidatedTest "[$file] File downloaded from github." "Downloaded"
21+
elif [ $VERBOSE_LEVEL -le 0 ]; then
22+
echo ""
23+
fi
24+
}
25+
26+
function downloadFilesFromGithub {
27+
echoAsk "Component slug to copy? (Example: symfony, laravel, cake-php)" false
28+
read slugToCopy
29+
30+
echoAsk "Version to copy? (major.minor)" false
31+
read versionToCopy
32+
33+
readonly GITHUB_BRANCH="$slugToCopy"_"$versionToCopy"_"$RESULT_TYPE_SLUG"
34+
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"
38+
source $RESULT_TYPE_PATH/downloadFilesFromGithub.sh
39+
echoValidationGroupEnd
40+
}
41+
42+
function createPhpbenchmarksDirectories {
43+
if [ ! -d "$INSTALLATION_PATH/.phpbenchmarks" ] || [ ! -d "$INSTALLATION_PATH/.phpbenchmarks/responseBody" ]; then
44+
echoValidationGroupStart "Create .phpbenchmarks directory"
45+
46+
if [ ! -d "$INSTALLATION_PATH/.phpbenchmarks" ]; then
47+
mkdir "$INSTALLATION_PATH/.phpbenchmarks"
48+
echoValidatedTest "[.phpbenchmarks] Directory created."
49+
fi
50+
51+
if [ ! -d "$INSTALLATION_PATH/.phpbenchmarks/responseBody" ]; then
52+
mkdir "$INSTALLATION_PATH/.phpbenchmarks/responseBody"
53+
echoValidatedTest "[.phpbenchmarks/responseBody] Directory created."
54+
fi
55+
56+
echoValidationGroupEnd
57+
fi
58+
}
59+
60+
function createCodeLinkFile {
61+
local codeLinkInstallationPath="$INSTALLATION_PATH/.phpbenchmarks/codeLink.sh"
62+
63+
echoValidationGroupStart "Create .phpbenchmarks/codeLink.sh"
64+
65+
source "$RESULT_TYPE_PATH/codeLink.sh"
66+
if [ -f "$INSTALLATION_PATH/.phpbenchmarks/codeLink.sh" ]; then
67+
source "$INSTALLATION_PATH/.phpbenchmarks/codeLink.sh"
68+
fi
69+
70+
echo "#!/usr/bin/env bash" > $codeLinkInstallationPath
71+
echo "" >> $codeLinkInstallationPath
72+
echo "declare -A codeLinks=(" >> $codeLinkInstallationPath
73+
for codeLinkName in "${codeLink[@]}"; do
74+
echo " [$codeLinkName]=\"${codeLinks[$codeLinkName]}\"" >> $codeLinkInstallationPath
75+
echoValidatedTest "\$codeLinks[$codeLinkName]=${codeLinks[$codeLinkName]}" "Writed"
76+
done
77+
echo ")" >> $codeLinkInstallationPath
78+
79+
echoValidationGroupEnd
80+
}
81+
82+
function defineVariableInConfigurationFile {
83+
local name=$1
84+
local value=$2
85+
local isString=$3
86+
local possibleValues=$4
87+
88+
if [ "$value" == "" ]; then
89+
local askValueMessage="Value for \$$name?"
90+
if [ "$possibleValues" != "" ]; then
91+
askValueMessage="$askValueMessage ($possibleValues)"
92+
fi
93+
echoAsk "$askValueMessage"
94+
read value
95+
fi
96+
97+
if [ "$isString" == "true" ]; then
98+
echo "readonly $name=\"$value\"" >> $INSTALLATION_PATH/.phpbenchmarks/configuration.sh
99+
else
100+
echo "readonly $name=$value" >> $INSTALLATION_PATH/.phpbenchmarks/configuration.sh
101+
fi
102+
[ $? != "0" ] && exitScript "Error while writing $name."
103+
echoValidatedTest "\$$name defined to $value." "Writed"
104+
}
105+
106+
function createConfigurationFile {
107+
local configurationFilePath="$INSTALLATION_PATH/.phpbenchmarks/configuration.sh"
108+
109+
echoValidationGroupStart "Create .phpbenchmarks/configuration.sh"
110+
111+
source "$RESULT_TYPE_PATH/defaultConfiguration.sh"
112+
if [ -f "$configurationFilePath" ]; then
113+
source "$configurationFilePath"
114+
fi
115+
116+
echo "#!/usr/bin/env bash" > $configurationFilePath
117+
echo "" >> $configurationFilePath
118+
119+
defineVariableInConfigurationFile "PHPBENCHMARKS_PHP_5_6_ENABLED" "$PHPBENCHMARKS_PHP_5_6_ENABLED" false "true/false"
120+
defineVariableInConfigurationFile "PHPBENCHMARKS_PHP_7_0_ENABLED" "$PHPBENCHMARKS_PHP_7_0_ENABLED" false "true/false"
121+
defineVariableInConfigurationFile "PHPBENCHMARKS_PHP_7_1_ENABLED" "$PHPBENCHMARKS_PHP_7_1_ENABLED" false "true/false"
122+
defineVariableInConfigurationFile "PHPBENCHMARKS_PHP_7_2_ENABLED" "$PHPBENCHMARKS_PHP_7_2_ENABLED" false "true/false"
123+
defineVariableInConfigurationFile "PHPBENCHMARKS_PHP_7_3_ENABLED" "$PHPBENCHMARKS_PHP_7_3_ENABLED" false "true/false"
124+
125+
echo "" >> $configurationFilePath
126+
defineVariableInConfigurationFile "PHPBENCHMARKS_NAME" "$PHPBENCHMARKS_NAME" true
127+
defineVariableInConfigurationFile "PHPBENCHMARKS_SLUG" "$PHPBENCHMARKS_SLUG" true
128+
129+
echo "" >> $configurationFilePath
130+
defineVariableInConfigurationFile "PHPBENCHMARKS_BENCHMARK_URL" "$PHPBENCHMARKS_BENCHMARK_URL" true
131+
132+
echo "" >> $configurationFilePath
133+
defineVariableInConfigurationFile "PHPBENCHMARKS_DEPENDENCY_NAME" "$PHPBENCHMARKS_DEPENDENCY_NAME" true
134+
135+
echo "" >> $configurationFilePath
136+
defineVariableInConfigurationFile "PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION" "$PHPBENCHMARKS_DEPENDENCY_MAJOR_VERSION" false
137+
defineVariableInConfigurationFile "PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION" "$PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION" false
138+
defineVariableInConfigurationFile "PHPBENCHMARKS_DEPENDENCY_BUGFIX_VERSION" "$PHPBENCHMARKS_DEPENDENCY_BUGFIX_VERSION" false
139+
140+
echoValidationGroupEnd
141+
}
142+
143+
createPhpbenchmarksDirectories
144+
145+
echoAsk "Copy configuration files from another location? [github/NONE]" false
146+
read copy
147+
copyFiles=false
148+
if [ "$copy" == "github" ] || [ "$copy" == "github" ]; then
149+
copyFiles=true
150+
downloadFilesFromGithub
151+
fi
152+
153+
if [ $copyFiles == false ]; then
154+
echo ""
155+
fi
156+
157+
createCodeLinkFile
158+
createConfigurationFile

0 commit comments

Comments
 (0)