From 5ac623075db901e2bd67096c5c7cf64a45d826f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 17 Nov 2016 22:29:40 +0100 Subject: [PATCH 1/3] add "deploy to packagist" stage during ci --- .gitlab-ci.yml | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 877e63b85..2b091ce22 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,18 +1,28 @@ -services: - - chill/database:latest - -before_script: - - composer config github-oauth.github.com $GITHUB_TOKEN - - composer install --no-interaction - - cp Tests/Fixtures/App/app/config/parameters.gitlab-ci.yml Tests/Fixtures/App/app/config/parameters.yml - - php Tests/Fixtures/App/app/console.php --env=test cache:warmup - - php Tests/Fixtures/App/app/console.php doctrine:migrations:migrate --env=test --no-interaction - - php Tests/Fixtures/App/app/console.php doctrine:fixtures:load --env=test --no-interaction +.test_definition: &test_definition + services: + - chill/database:latest + before_script: + - composer config github-oauth.github.com $GITHUB_TOKEN + - composer install --no-interaction + - cp Tests/Fixtures/App/app/config/parameters.gitlab-ci.yml Tests/Fixtures/App/app/config/parameters.yml + - php Tests/Fixtures/App/app/console.php --env=test cache:warmup + - php Tests/Fixtures/App/app/console.php doctrine:migrations:migrate --env=test --no-interaction + - php Tests/Fixtures/App/app/console.php doctrine:fixtures:load --env=test --no-interaction test:php-5.6: stage: test + image: chill/ci-image:php-5.6 + <<: *test_definition script: phpunit test:php-7: image: chill/ci-image:php-7 stage: test + <<: *test_definition script: phpunit + +deploy-packagist: + stage: deploy + image: chill/ci-image:php-7 + before_script: ~ + script: + - curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=$PACKAGIST_USERNAME&apiToken=$PACKAGIST_TOKEN" -d"{\"repository\":{\"url\":\"$CI_PROJECT_PATH.git\"}}" From 6ec1d44978cb924a8364e5b3bc5501beaa4230a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 19 Nov 2016 19:15:18 +0100 Subject: [PATCH 2/3] fix deploy command and improve scripts The scripts now test that variables are set. The "deploy to packagist" build should return an error if not successful. --- .gitlab-ci.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b091ce22..5ec74908c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ services: - chill/database:latest before_script: - - composer config github-oauth.github.com $GITHUB_TOKEN + - if [ -z ${GITHUB_TOKEN+x} ]; then composer config github-oauth.github.com $GITHUB_TOKEN; fi - composer install --no-interaction - cp Tests/Fixtures/App/app/config/parameters.gitlab-ci.yml Tests/Fixtures/App/app/config/parameters.yml - php Tests/Fixtures/App/app/console.php --env=test cache:warmup @@ -23,6 +23,10 @@ test:php-7: deploy-packagist: stage: deploy image: chill/ci-image:php-7 - before_script: ~ + before_script: + # test that PACKAGIST USERNAME and PACKAGIST_TOKEN variable are set + - if [ -z ${PACKAGIST_USERNAME+x} ]; then echo "Please set PACKAGIST_USERNAME variable"; exit -1; fi + - if [ -z ${PACKAGIST_TOKEN+x} ]; then echo "Please set PACKAGIST_TOKEN variable"; exit -1; fi script: - - curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=$PACKAGIST_USERNAME&apiToken=$PACKAGIST_TOKEN" -d"{\"repository\":{\"url\":\"$CI_PROJECT_PATH.git\"}}" + - STATUSCODE=$(curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=$PACKAGIST_USERNAME&apiToken=$PACKAGIST_TOKEN" -d"{\"repository\":{\"url\":\"$CI_PROJECT_URL.git\"}}") + - if [ $STATUSCODE = "202" ]; then exit 0; else exit $STATUSCODE; fi From e4f5fe4e0486f1e954fdd9697ee7feb7209ca69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 19 Nov 2016 19:28:00 +0100 Subject: [PATCH 3/3] fix update packagist script --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5ec74908c..63497ab77 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,5 +28,5 @@ deploy-packagist: - if [ -z ${PACKAGIST_USERNAME+x} ]; then echo "Please set PACKAGIST_USERNAME variable"; exit -1; fi - if [ -z ${PACKAGIST_TOKEN+x} ]; then echo "Please set PACKAGIST_TOKEN variable"; exit -1; fi script: - - STATUSCODE=$(curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=$PACKAGIST_USERNAME&apiToken=$PACKAGIST_TOKEN" -d"{\"repository\":{\"url\":\"$CI_PROJECT_URL.git\"}}") + - STATUSCODE=$(curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=$PACKAGIST_USERNAME&apiToken=$PACKAGIST_TOKEN" -d"{\"repository\":{\"url\":\"$CI_PROJECT_URL.git\"}}" --silent --output /dev/stderr --write-out "%{http_code}") - if [ $STATUSCODE = "202" ]; then exit 0; else exit $STATUSCODE; fi