From 083a0a289535d09cad5ee17a9a4efd6197bd2596 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Mon, 18 Feb 2019 11:53:27 +0800 Subject: [PATCH] enhance ci --- azure-pipelines.yml | 19 ++++--------------- scripts/distribute-test.js | 21 +++++++++++++++++++++ scripts/release.js | 1 + 3 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 scripts/distribute-test.js diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e978b8e8..73e9fd5d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -4,6 +4,7 @@ jobs: pool: vmImage: 'Ubuntu-16.04' strategy: + parallel: 3 matrix: '7.1': phpVersion: 7.1 @@ -25,13 +26,6 @@ jobs: php -version displayName: 'Use PHP version $(phpVersion)' - - task: DownloadPipelineArtifact@0 - continueOnError: true - inputs: - artifactName: php-vendor-$(phpVersion) - targetPath: vendor - pipelineId: $($(Build.BuildId) - 1) - - script: composer install --no-interaction --prefer-dist displayName: 'composer install' @@ -40,9 +34,10 @@ jobs: php artisan key:random php artisan salt:random mysql -uroot -proot -e 'CREATE DATABASE IF NOT EXISTS test;' + mkdir junitReports displayName: 'Prepare testing environment' - - script: ./vendor/bin/phpunit --log-junit junit.xml + - script: node scripts/distribute-test.js displayName: Test - task: PublishTestResults@2 @@ -51,12 +46,6 @@ jobs: testRunner: JUnit testResultsFiles: './junit.xml' - - task: PublishPipelineArtifact@0 - continueOnError: true - inputs: - artifactName: php-vendor-$(phpVersion) - targetPath: vendor - - job: javascript displayName: JavaScript pool: @@ -88,7 +77,7 @@ jobs: - script: yarn displayName: Install dependencies - script: mkdir dist - - script: yarn release dist/blessing-skin-server.zip + - script: yarn release dist/blessing-skin-server.zip --ci displayName: Generate package - task: PublishPipelineArtifact@0 inputs: diff --git a/scripts/distribute-test.js b/scripts/distribute-test.js new file mode 100644 index 00000000..1154fc9d --- /dev/null +++ b/scripts/distribute-test.js @@ -0,0 +1,21 @@ +const execa = require('execa'); + +const TOTAL_AGENTS = +process.env.SYSTEM_TOTALJOBSINPHASE || 1; +const AGENT_NUMBER = +process.env.SYSTEM_JOBPOSITIONINPHASE || 1; + +const tests = execa + .sync('./vendor/bin/phpunit', ['--list-tests']) + .stdout + .split(/\r?\n/) + .filter(line => line.startsWith(' - Tests')) + .map(line => line.replace(' - Tests\\', '')); + +const toBeRun = []; +for (let i = AGENT_NUMBER, length = tests.length; i <= length; i = i + TOTAL_AGENTS) { + toBeRun.push(test[i - 1]); +} + +execa('./vendor/bin/phpunit', [ + `--filter='(${toBeRun.join('|')})'`, + `--log-junit=./junitReports/junit_${AGENT_NUMBER}.xml` +]).stdout.pipe(process.stdout); diff --git a/scripts/release.js b/scripts/release.js index b10bbd78..cdd5dc9b 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -47,6 +47,7 @@ const tasks = new Listr([ }, { title: 'Install PHP dependencies for development', + enabled: () => !process.argv.includes('--ci'), task: () => execa('composer', ['install']) }, ]);