[TEST] Scripts to run the tests with docker

This commit is contained in:
Tristan Darricau 2016-02-01 14:51:19 +01:00
parent 3a4dae369d
commit e82bbbba14
10 changed files with 131 additions and 0 deletions

View file

@ -0,0 +1,9 @@
#!/usr/bin/env bash
export IMAGES_TAG=${bamboo_images_tag}
export WORKING_DIR=${bamboo_working_directory}
export PR_NUMBER=${bamboo_PRnumber}
export COMPOSER_HOME=${bamboo_composer_home}
export GITHUB_TOKEN=${bamboo_github_token_password}
export BUILD_RESULT_URL=${bamboo_buildResultsUrl}

14
docker/scripts/cleanup.sh Executable file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# We assume the docker daemon is dedicated to the current job (the jobs runs on isolated docker daemon)
# Stop running containers
for container in $(docker ps -q)
do
docker stop $container || true
done
# Removing containers
for container in $(docker ps -a -q)
do
docker rm -v $container || true
done

7
docker/scripts/fetch-pr.sh Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
docker run \
--user $(id -u):$(id -g) \
--volume ${WORKING_DIR}:/data \
--workdir /data \
phpbb/build${IMAGES_TAG} sh -c 'git remote set-url origin "https://github.com/phpbb/phpbb.git" && git fetch origin +refs/pull/'${PR_NUMBER}'/merge && git checkout FETCH_HEAD'

View file

@ -0,0 +1,17 @@
#!/usr/bin/env bas
cat <<EOL > generate-archive.sh
git remote set-url origin "https://github.com/phpbb/phpbb.git"
git fetch origin +refs/pull/${PR_NUMBER}/head
last_commit=\$(git rev-parse FETCH_HEAD)
echo "\$last_commit" > build/logs/last_commit
tar --exclude-backups --exclude-vcs --exclude='.git' --exclude='generate-archive.sh' -p -c -z -f source_code.tar.gz *
EOL
docker run \
--user $(id -u):$(id -g) \
--volume ${WORKING_DIR}:/data \
--workdir /data \
phpbb/build{IMAGES_TAG} sh generate-archive.sh
rm generate-archive.sh

View file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
if [ -s build/logs/phpunit.xml ]; then
res=$(cat build/logs/sniffs_res 2>/dev/null)
if ( grep 'failures="[^0]"' build/logs/phpunit.xml ); then
res=1
elif ( grep 'errors="[^0]"' build/logs/phpunit.xml ); then
res=2
else
res=0
fi
else
res=2
fi
echo ${res}

7
docker/scripts/jobs/sniffer.sh Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
docker run \
--user $(id -u):$(id -g) \
--volume ${WORKING_DIR}:/data \
--workdir /data \
php:5.6 sh -c 'cd build && ../phpBB/vendor/bin/phing sniff && echo 0 > logs/sniffs_res || echo 1 > logs/sniffs_res'

7
docker/scripts/prepare-code.sh Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
docker run \
--user $(id -u):$(id -g) \
--volume ${WORKING_DIR}:/data \
--workdir /data \
debian tar -p -x -z -f source_code.tar.gz

View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Ensure the github oauth token is set
docker run \
--user $(id -u):$(id -g) \
--volume ${WORKING_DIR}:/data \
--volume ${COMPOSER_HOME}:/composer/ \
--workdir /data \
phpbb/build{IMAGES_TAG} sh -c "COMPOSER_HOME=/composer php composer.phar config -g github-oauth.github.com ${GITHUB_TOKEN}"
docker run \
--user $(id -u):$(id -g) \
--volume ${WORKING_DIR}:/data \
--volume ${COMPOSER_HOME}:/composer/ \
--workdir /data \
phpbb/build{IMAGES_TAG} sh -c 'cd phpBB; COMPOSER_HOME=/composer php ../composer.phar install --dev'
docker run \
--user $(id -u):$(id -g) \
--volume ${WORKING_DIR}:/data \
--workdir /data \
phpbb/build{IMAGES_TAG} sh -c 'cd build; ../phpBB/vendor/bin/phing clean prepare'

View file

@ -0,0 +1,23 @@
#!/usr/bin/env bash
last_commit=$(cat build/logs/last_commit)
result_file=$1
step=$2
if [ -s build/logs/${result_file} ]; then
res=$(cat build/logs/${result_file} 2>/dev/null)
else
res=2
fi
if [ $res -eq 0 ]; then
echo Send success
./set-status.sh 'success' 'The Bamboo build is a success' ${step}
elif [ $res -eq 1 ]; then
echo Send Failure
./set-status.sh 'failure' 'The Bamboo build failed' ${step}
else
echo Send error
./set-status.sh 'error' 'The Bamboo build is in error' ${step}
fi

9
docker/scripts/set-status.sh Executable file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env bash
last_commit=$(cat build/logs/last_commit)
status=$1
description=$2
step=$3
curl -H "Authorization: token ${GITHUB_TOKEN}" --request POST --data '{"state": "'${status}'", "description": "'${description}'", "target_url": "'${BUILD_RESULT_URL}'", "context": "phpBB continuous integration - '${step}'"}' https://api.github.com/repos/phpbb/phpbb/statuses/${last_commit} > /dev/null