Skip to content

Commit

Permalink
chore: set up CI with Azure Pipelines (#2767)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Jun 12, 2019
1 parent 73592fc commit 679e3ea
Show file tree
Hide file tree
Showing 20 changed files with 2,059 additions and 8 deletions.
34 changes: 34 additions & 0 deletions .azure/build-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
jobs:
- job: build
pool:
vmImage: 'ubuntu-latest'
steps:
- template: prepare-environment-step.yml
- template: composer-install-step.yml

- bash: |
yarn global add greenkeeper-lockfile@1
displayName: 'Install greenkeeper'
# SYSTEM_PULLREQUEST_PULLREQUESTID=$(test "$BUILD_SOURCEBRANCHNAME" != "master" -a "greenkeeper[bot]" = "`git log --format="%an" -n 1`" || echo '') GK_LOCK_YARN_OPTS="--ignore-engines" $(yarn global bin)/greenkeeper-lockfile-update
- bash: |
TRAVIS=true TRAVIS_REPO_SLUG=$BUILD_REPOSITORY_NAME TRAVIS_BRANCH=$SYSTEM_PULLREQUEST_SOURCEBRANCH TRAVIS_PULL_REQUEST=false TRAVIS_JOB_NUMBER=1 GK_LOCK_YARN_OPTS="--ignore-engines" $(yarn global bin)/greenkeeper-lockfile-update
displayName: 'Update yarn lockfile'
- bash: yarn inst
displayName: 'yarn install'
# SYSTEM_PULLREQUEST_PULLREQUESTID=$(test "$BUILD_SOURCEBRANCHNAME" != "master" -a "greenkeeperio-bot" = "`git log --format="%an" -n 1`" || echo '') $(yarn global bin)/greenkeeper-lockfile-upload
- bash: |
TRAVIS=true TRAVIS_REPO_SLUG=$BUILD_REPOSITORY_NAME TRAVIS_BRANCH=$SYSTEM_PULLREQUEST_SOURCEBRANCH TRAVIS_PULL_REQUEST=false TRAVIS_JOB_NUMBER=1 $(yarn global bin)/greenkeeper-lockfile-upload
cat gk-lockfile-git-push.err || true
rm -f gk-lockfile-git-push.err || true
displayName: 'Upload yarn lockfile'
# Update js and css assets eventually
- bash: yarn lint
displayName: 'Check js and vue lint'
- bash: scripts/ci/update-assets.sh
displayName: 'Update assets'
env:
ASSETS_EMAIL: $(ASSETS_EMAIL)
ASSETS_USERNAME: $(ASSETS_EMAIL)
ASSETS_GITHUB_TOKEN: $(ASSETS_GITHUB_TOKEN)
9 changes: 9 additions & 0 deletions .azure/composer-install-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
no_dev: 'false'
steps:
- bash: |
sudo composer self-update
composer global require hirak/prestissimo
test "${{ parameters.no_dev }}" == "true" && EXTRA_PARAM = "--no-dev"
composer install --no-interaction --no-suggest --no-progress --ignore-platform-reqs $EXTRA_PARAM
displayName: 'composer install'
5 changes: 5 additions & 0 deletions .azure/docker-build-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
steps:
- bash: |
docker-compose --version
make docker_build
displayName: Make docker image
9 changes: 9 additions & 0 deletions .azure/docker-push-bintray-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
steps:
- bash: |
echo $BINTRAY_APIKEY | docker login -u $BINTRAY_USER --password-stdin $BINTRAY_DOCKER_URL
make docker_push_bintray
displayName: Publish docker image
env:
BINTRAY_USER: $(BINTRAY_USER)
BINTRAY_APIKEY: $(BINTRAY_APIKEY)
BINTRAY_DOCKER_URL: monicahq-docker-docker.bintray.io
8 changes: 8 additions & 0 deletions .azure/prepare-db-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# database.test.sql file is generated with:
# mysqldump -u homestead -psecret -n --skip-add-drop-table --skip-add-locks --skip-comments monica_test > scripts/database.test.sql
steps:
- bash: |
mysql --protocol=tcp -u root -proot -e "CREATE DATABASE IF NOT EXISTS monica CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql -u root -proot monica < scripts/database.test.sql
php artisan migrate --no-interaction -vvv
displayName: 'Prepare db'
14 changes: 14 additions & 0 deletions .azure/prepare-environment-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
steps:
- bash: |
sudo update-alternatives --set php /usr/bin/php$(phpVersion)
sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
php -version
displayName: 'Use PHP version $(phpVersion)'
- bash: |
mkdir -p results/coverage
sed 's/DB_TEST_PASSWORD=/DB_TEST_PASSWORD=root/' scripts/tests/.env.mysql > .env
touch .sentry-release
displayName: Prepare environment
3 changes: 3 additions & 0 deletions .azure/remove-xdebug-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
steps:
- bash: sudo rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
displayName: 'Remove xdebug'
10 changes: 10 additions & 0 deletions .azure/runsonar-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
steps:
- bash: |
export SONAR_COVERAGE=$(ls -m ./results/coverage*.xml | sed 's/ //g' | sed ':a;N;$!ba;s/\n//g')
scripts/tests/runsonar.sh
displayName: 'Run sonar scanner'
env:
SONAR_RESULT: '$(System.DefaultWorkingDirectory)/results/results.xml'
GITHUB_TOKEN: $(GITHUB_TOKEN)
SONAR_TOKEN: $(SONAR_TOKEN)
SONAR_VERSION: $(SONAR_VERSION)
5 changes: 5 additions & 0 deletions .azure/seed-test-db-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
steps:
- bash: |
php artisan db:seed --no-interaction -vvv
php artisan passport:keys --no-interaction -vvv
displayName: 'Seed database'
28 changes: 28 additions & 0 deletions .azure/test-browser-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- job: tests_browser
dependsOn: build
pool:
vmImage: 'ubuntu-latest'
steps:
- template: checkout-step.yml
- template: prepare-environment-step.yml
- template: composer-install-step.yml
- template: prepare-db-step.yml
- template: seed-test-db-step.yml
# - bash: vendor/bin/chromedriver &
# displayName: 'Run selenium chromedriver'
- bash: scripts/tests/start-selenium.sh
displayName: 'Run selenium chromedriver'
- bash: php -S localhost:8000 -t public scripts/tests/server-cc.php &
displayName: 'Run http server'
- bash: until $(nc -z localhost 8000); do sleep 1; done
displayName: 'Wait for http server'
- bash: php artisan dusk --log-junit results/junit/dusk/results3.xml
displayName: 'Run browser tests'
- bash: |
vendor/bin/phpcov merge --clover=results/coverage3.xml results/coverage/
rm -rf results/coverage
displayName: 'Fix coverage'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'results'
targetPath: 'results/junit'
42 changes: 42 additions & 0 deletions .azure/unit-tests-step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
steps:
- bash: |
IFS='|' read -r -a TESTS <<< "$TESTSUITES"
TESTSUITE=${TESTS[$SYSTEM_JOBPOSITIONINPHASE-1]}
echo "TestSuite $TESTSUITE"
echo "##vso[task.setvariable variable=TESTSUITE]$TESTSUITE"
displayName: 'Select testsuite'
env:
TESTSUITES: "Api|Feature|Unit-Models|Unit-Services"

- bash: |
php artisan route:cache
ulimit -S unlimited
phpdbg -dmemory_limit=4G -qrr vendor/bin/phpunit -c phpunit.xml --log-junit ./results/junit/unit/results${SYSTEM_JOBPOSITIONINPHASE}.xml --coverage-clover ./results/coverage${SYSTEM_JOBPOSITIONINPHASE}.xml --testsuite $TESTSUITE
displayName: 'Run unit tests'

- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: JUnit
testResultsFiles: 'results*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/results/junit/unit'
mergeTestResults: true
condition: succeededOrFailed()

#- task: ReportGenerator@4
# inputs:
# reports: 'results/coverage*.xml'
# targetdir: 'coveragereport'
# reporttypes: 'Cobertura'
# condition: succeededOrFailed()

#- task: PublishCodeCoverageResults@1
# displayName: 'Publish code coverage'
# inputs:
# summaryFileLocation: 'coveragereport/*.xml'
# condition: succeededOrFailed()

- task: PublishPipelineArtifact@0
inputs:
artifactName: 'results$(System.JobPositionInPhase)'
targetPath: 'results'
12 changes: 9 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ aliases:
name: Run unit tests
command: |
php artisan route:cache
TESTSUITE=$(echo -e "Api-and-Feature\nUnit" | circleci tests split)
TESTSUITE=$(echo -e "Api,Feature\nUnit-Models,Unit-Services" | circleci tests split)
phpdbg -dmemory_limit=4G -qrr vendor/bin/phpunit -c phpunit.xml --log-junit ./results/junit/unit/results${CIRCLE_NODE_INDEX}.xml --coverage-clover ./results/coverage${CIRCLE_NODE_INDEX}.xml --testsuite $TESTSUITE
- &psalm
run:
Expand Down Expand Up @@ -174,7 +174,10 @@ jobs:
## COMPOSER
- *restore_composer
- run: composer install --no-interaction --no-suggest --ignore-platform-reqs
- run:
command: |
composer global require hirak/prestissimo
composer install --no-interaction --no-suggest --ignore-platform-reqs
- save_cache:
key: *composer_key
paths: ~/.composer/cache/
Expand Down Expand Up @@ -383,7 +386,10 @@ jobs:
<<: *post_checkout
- attach_workspace:
at: *root
- run: composer install --no-interaction --no-suggest --ignore-platform-reqs --no-dev
- run:
command: |
composer global require hirak/prestissimo
composer install --no-interaction --no-suggest --ignore-platform-reqs --no-dev
- run: make dist
- run: make push_bintray_dist

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ monicadump.sql
.scannerwork/
.sentry-release
.phpunit.result.cache
.composer
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ else ifeq ($(TRAVIS),true)
GIT_COMMIT := $(if $(TRAVIS_PULL_REQUEST_SHA),$(TRAVIS_PULL_REQUEST_SHA),$(TRAVIS_COMMIT))
GIT_TAG := $(TRAVIS_TAG)
COMMIT_MESSAGE := $(TRAVIS_COMMIT_MESSAGE)
else ifeq ($(TF_BUILD),True)
REPO := $(BUILD_REPOSITORY_NAME)
BRANCH := $(if $(SYSTEM_PULLREQUEST_SOURCEBRANCH),$(SYSTEM_PULLREQUEST_SOURCEBRANCH),$(BUILD_SOURCEBRANCHNAME))
PR_NUMBER := $(if $(SYSTEM_PULLREQUEST_PULLREQUESTNUMBER),$(SYSTEM_PULLREQUEST_PULLREQUESTNUMBER),false)
BUILD_NUMBER := $(BUILD_BUILDNUMBER)
GIT_COMMIT := $(shell git rev-parse HEAD^2)
ifeq ($(GIT_COMMIT),)
GIT_COMMIT :?= $(BUILD_SOURCEVERSION)
endif
else
REPO := $(subst https://github.com/,,$(CHANGE_URL))
ifneq ($(CHANGE_ID),)
Expand Down
Loading

0 comments on commit 679e3ea

Please sign in to comment.