Skip to content

Commit ade4a2e

Browse files
committed
add bin files
1 parent dcb2399 commit ade4a2e

File tree

7 files changed

+279
-1
lines changed

7 files changed

+279
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
*~
22
/.idea/
3-
bin
3+
bin/doctrine*
4+
bin/php-cs-fixer
5+
bin/phpunit
6+
bin/sql-formatter
47
vendor

bin/dev

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -x
4+
set -e
5+
6+
while getopts "buste" OPTION; do
7+
case $OPTION in
8+
b)
9+
COMPOSE_PROJECT_NAME=mqdev docker-compose build
10+
;;
11+
u)
12+
COMPOSE_PROJECT_NAME=mqdev docker-compose up
13+
;;
14+
s)
15+
COMPOSE_PROJECT_NAME=mqdev docker-compose stop
16+
;;
17+
e)
18+
docker exec -it mqdev_dev_1 /bin/bash
19+
;;
20+
t)
21+
COMPOSE_PROJECT_NAME=mqdev docker-compose run --workdir="/mqdev" --rm dev ./bin/test
22+
;;
23+
24+
\?)
25+
echo "Invalid option: -$OPTARG" >&2
26+
exit 1
27+
;;
28+
:)
29+
echo "Option -$OPTARG requires an argument." >&2
30+
exit 1
31+
;;
32+
esac
33+
done

bin/pre-commit

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use Symfony\Component\Process\PhpExecutableFinder;
5+
6+
/**
7+
* This script fixes code style for files which are going to be committed.
8+
* If errors were found commit will be interrupted and errors will be fixed.
9+
* Then you need to manually stage your changes and run commit again
10+
*
11+
* To install this hook just run "pre-commit -i"
12+
*/
13+
14+
include_once __DIR__.'/../vendor/autoload.php';
15+
$projectRootDir = realpath(__DIR__ . '/..');
16+
if (!$projectRootDir) {
17+
throw new \LogicException('The project root dir was not guessed');
18+
}
19+
20+
$phpExecutableFinder = new PhpExecutableFinder();
21+
$phpBin = $phpExecutableFinder->find();
22+
if (!$phpBin) {
23+
echo 'Php executable could not be found.'.PHP_EOL;
24+
}
25+
26+
$options = getopt('i', array('install'));
27+
if (isset($options['i']) || isset($options['install'])) {
28+
install();
29+
30+
echo "Git hook successfully installed" . PHP_EOL;
31+
exit(1);
32+
}
33+
34+
$options = getopt('u', array('uninstall'));
35+
if (isset($options['u']) || isset($options['uninstall'])) {
36+
uninstall();
37+
38+
echo "Git hook successfully uninstalled" . PHP_EOL;
39+
exit(1);
40+
}
41+
42+
function install()
43+
{
44+
global $projectRootDir;
45+
46+
uninstall();
47+
48+
//create link
49+
$link = $projectRootDir . '/.git/hooks/pre-commit';
50+
exec(sprintf('ln -s %s %s', __FILE__, $link));
51+
}
52+
53+
function uninstall()
54+
{
55+
global $projectRootDir;
56+
57+
//create link
58+
$link = $projectRootDir . '/.git/hooks/pre-commit';
59+
@unlink($link);
60+
}
61+
62+
function getFilesToFix()
63+
{
64+
$files = array();
65+
exec('git diff-index --name-only --cached --diff-filter=ACMR HEAD --', $files);
66+
67+
$stagedFiles = array_filter($files, function ($file) {
68+
return (bool) preg_match('/\.(php|twig|translations\/*.yml)$/', $file);
69+
});
70+
71+
echo sprintf('Found %s staged files', count($stagedFiles)).PHP_EOL;
72+
73+
return $stagedFiles;
74+
}
75+
76+
function runPhpLint()
77+
{
78+
global $phpBin, $projectRootDir;
79+
80+
$filesWithErrors = array();
81+
foreach (getFilesToFix() as $file) {
82+
$output = '';
83+
$returnCode = null;
84+
exec(sprintf('%s -l %s 2>/dev/null', $phpBin, $projectRootDir.'/'.$file), $output, $returnCode);
85+
86+
if ($returnCode) {
87+
$filesWithErrors[] = $file;
88+
}
89+
}
90+
91+
return $filesWithErrors;
92+
}
93+
94+
function runPhpCsFixer()
95+
{
96+
global $phpBin, $projectRootDir;
97+
98+
$phpCsFixerBin = $projectRootDir . '/bin/php-cs-fixer';
99+
if (!file_exists($phpCsFixerBin)) {
100+
echo $phpCsFixerBin.' File could not be found. Make sure you run command from project\'s root directory'.PHP_EOL;
101+
}
102+
103+
$filesWithErrors = array();
104+
foreach (getFilesToFix() as $file) {
105+
$output = '';
106+
$returnCode = null;
107+
exec(sprintf(
108+
'%s %s fix %s --config-file=%s',
109+
$phpBin,
110+
$phpCsFixerBin,
111+
$projectRootDir.'/'.$file,
112+
$projectRootDir.'/.php_cs'
113+
), $output, $returnCode);
114+
115+
if ($returnCode) {
116+
$filesWithErrors[] = $file;
117+
}
118+
}
119+
120+
return $filesWithErrors;
121+
}
122+
123+
$phpSyntaxErrors = runPhpLint();
124+
if ($phpSyntaxErrors) {
125+
echo "Php syntax errors were found in next files:" . PHP_EOL;
126+
127+
foreach ($phpSyntaxErrors as $error) {
128+
echo $error . PHP_EOL;
129+
}
130+
131+
exit(1);
132+
}
133+
134+
$phpCSFixerErrors = runPhpCsFixer();
135+
if ($phpCSFixerErrors) {
136+
echo "Incorrect coding standards were detected and fixed." . PHP_EOL;
137+
echo "Please stash changes and run commit again." . PHP_EOL;
138+
echo "List of changed files:" . PHP_EOL;
139+
140+
foreach ($phpCSFixerErrors as $error) {
141+
echo $error . PHP_EOL;
142+
}
143+
144+
exit(1);
145+
}
146+
147+
exit(0);

bin/splitsh-lite

8.01 MB
Binary file not shown.

bin/subtree-split

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -x
5+
6+
CURRENT_BRANCH=`git name-rev --name-only HEAD`
7+
8+
function split()
9+
{
10+
# split_new_repo $1 $2
11+
12+
CURRENT_BRANCH=`git name-rev --name-only HEAD`
13+
14+
SHA1=`./bin/splitsh-lite --prefix=$1`
15+
git push $2 "$SHA1:$CURRENT_BRANCH"
16+
}
17+
18+
function split_new_repo()
19+
{
20+
TMP_DIR="/tmp/enqueue-repo"
21+
REMOTE_URL=`git remote get-url $2`
22+
23+
rm -rf $TMP_DIR;
24+
mkdir $TMP_DIR;
25+
26+
(
27+
cd $TMP_DIR;
28+
git clone $REMOTE_URL .;
29+
git checkout -b master;
30+
touch foo;
31+
git add foo;
32+
git commit -m "foo";
33+
git push origin master;
34+
);
35+
36+
CURRENT_BRANCH=`git name-rev --name-only HEAD`
37+
38+
SHA1=`./bin/splitsh-lite --prefix=$1`
39+
git fetch $2
40+
git push $2 "$SHA1:$CURRENT_BRANCH" -f
41+
}
42+
43+
44+
function remote()
45+
{
46+
git remote add $1 $2 || true
47+
}
48+
49+
remote psr-queue [email protected]:php-enqueue/psr-queue.git
50+
remote enqueue [email protected]:php-enqueue/enqueue.git
51+
remote stomp [email protected]:php-enqueue/stomp.git
52+
remote amqp-ext [email protected]:php-enqueue/amqp-ext.git
53+
remote enqueue-bundle [email protected]:php-enqueue/enqueue-bundle.git
54+
remote job-queue [email protected]:php-enqueue/job-queue.git
55+
remote test [email protected]:php-enqueue/test.git
56+
57+
split 'pkg/psr-queue' psr-queue
58+
split 'pkg/enqueue' enqueue
59+
split 'pkg/stomp' stomp
60+
split 'pkg/amqp-ext' amqp-ext
61+
split 'pkg/enqueue-bundle' enqueue-bundle
62+
split 'pkg/job-queue' job-queue
63+
split 'pkg/test' test

bin/test

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
# wait for service
4+
# $1 host
5+
# $2 port
6+
# $3 attempts
7+
function waitForService()
8+
{
9+
ATTEMPTS=0
10+
until nc -z $1 $2; do
11+
printf "wait for service %s:%s\n" $1 $2
12+
((ATTEMPTS++))
13+
if [ $ATTEMPTS -ge $3 ]; then
14+
printf "service is not running %s:%s\n" $1 $2
15+
exit 1
16+
fi
17+
sleep 1
18+
done
19+
20+
printf "service is online %s:%s\n" $1 $2
21+
}
22+
23+
waitForService rabbitmq 5672 50
24+
waitForService mysql 3306 50
25+
26+
php pkg/job-queue/Tests/Functional/app/console doctrine:database:create
27+
php pkg/job-queue/Tests/Functional/app/console doctrine:schema:update --force
28+
29+
bin/phpunit "$@"

docker/bin/dev_entrypoiny.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
while true; do sleep 1; done

0 commit comments

Comments
 (0)