From 59012d4918624f966537ac74c2d368b81f1a00f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Thu, 3 Mar 2022 11:01:49 +0100 Subject: [PATCH] feature: Provide proper job names for github UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This feature is based on the feedback from @ocramius in #76 and provides better namings to github UI. This will also prevent #31 with its extended commands where we do check for linting before actually executing the command itself. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- src/create-jobs.js | 37 +++++++++++++++++++++++-------------- src/job.js | 4 +++- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/create-jobs.js b/src/create-jobs.js index 0156ed13..908ca026 100644 --- a/src/create-jobs.js +++ b/src/create-jobs.js @@ -22,13 +22,14 @@ const fileTest = function (filename) { }; /** + * @param {String} name * @param {String} command * @param {Config} config * @return {Array} */ -const createQaJobs = function (command, config) { +const createQaCheck = function (name, command, config) { return [new Job( - command + ' on PHP ' + config.minimum_version, + name + ' on PHP ' + config.minimum_version, JSON.stringify(new Command( command, config.minimum_version, @@ -37,7 +38,8 @@ const createQaJobs = function (command, config) { 'locked', config.ignore_php_platform_requirements[config.minimum_version] ?? false, config.additional_composer_arguments - )) + )), + command + ' on PHP ' + config.minimum_version )]; }; @@ -136,7 +138,7 @@ function checks (config) { * @return {Array} */ function (config) { - return createQaJobs('./vendor/bin/phpcs -q --report=checkstyle | cs2pr', config); + return createQaCheck('Codestandard', './vendor/bin/phpcs -q --report=checkstyle | cs2pr', config); } ), new Check( @@ -147,7 +149,7 @@ function checks (config) { * @return {Array} */ function (config) { - return createQaJobs('./vendor/bin/psalm --shepherd --stats --output-format=github --no-cache', config); + return createQaCheck('Static Code Analysis', './vendor/bin/psalm --shepherd --stats --output-format=github --no-cache', config); } ), new Check( @@ -158,7 +160,7 @@ function checks (config) { * @return {Array} */ function (config) { - return createQaJobs('./vendor/bin/composer-require-checker check --config-file=composer-require-checker.json -n -v composer.json', config); + return createQaCheck('Composer Require Checker', './vendor/bin/composer-require-checker check --config-file=composer-require-checker.json -n -v composer.json', config); } ), new Check( @@ -169,7 +171,7 @@ function checks (config) { * @return {Array} */ function (config) { - return createQaJobs('./vendor/bin/phpbench run --revs=2 --iterations=2 --report=aggregate', config); + return createQaCheck('Benchmarks','./vendor/bin/phpbench run --revs=2 --iterations=2 --report=aggregate', config); } ), new Check( @@ -183,10 +185,10 @@ function checks (config) { const composerFile = parseJsonFile('composer.json', false); if (composerFile.hasOwnProperty('require-dev') && composerFile['require-dev'].hasOwnProperty('roave/infection-static-analysis-plugin')) { - return createQaJobs('phpdbg -qrr ./vendor/bin/roave-infection-static-analysis-plugin', config); + return createQaCheck('Infection (via Roave static analysis plugin)', 'phpdbg -qrr ./vendor/bin/roave-infection-static-analysis-plugin', config); } - return createQaJobs('phpdbg -qrr ./vendor/bin/infection', config); + return createQaCheck('Infection', 'phpdbg -qrr ./vendor/bin/infection', config); } ), new Check( @@ -197,7 +199,7 @@ function checks (config) { * @return {Array} */ function (config) { - return createQaJobs('yamllint -d relaxed --no-warnings mkdocs.yml', config); + return createQaCheck('YAML lint', 'yamllint -d relaxed --no-warnings mkdocs.yml', config); } ), new Check( @@ -208,7 +210,7 @@ function checks (config) { * @return {Array} */ function (config) { - return createQaJobs('markdownlint doc/book/**/*.md', config); + return createQaCheck('Markdown lint (doc/book/*)', 'markdownlint doc/book/**/*.md', config); } ), new Check( @@ -219,7 +221,7 @@ function checks (config) { * @return {Array} */ function (config) { - return createQaJobs('markdownlint docs/book/**/*.md', config); + return createQaCheck('Markdown lint (docs/book/*)', 'markdownlint docs/book/**/*.md', config); } ), new Check( @@ -230,12 +232,13 @@ function checks (config) { * @return {Array} */ function (config) { - return createQaJobs('./vendor/bin/codecept run', config); + return createQaCheck('Codeception', './vendor/bin/codecept run', config); } ) ]; } +/** @var {Job} job */ const excludeJob = function (job, exclusion) { let matches = 0; Object.keys(job).forEach(function (jobKey) { @@ -244,7 +247,13 @@ const excludeJob = function (job, exclusion) { return; } - if (job[jobKey] === exclusion[excludeKey]) { + let jobValue = job[jobKey], + exclusionValue = exclusion[excludeKey]; + + if (jobValue === exclusionValue) { + matches += 1; + } else if (excludeKey === 'name' && job.deprecatedName !== '' && exclusionValue === job.deprecatedName) { + // BC compatibility to ensure projects which are excluding jobs by name will continue to work matches += 1; } }); diff --git a/src/job.js b/src/job.js index f94df8d3..156c0b22 100644 --- a/src/job.js +++ b/src/job.js @@ -6,10 +6,12 @@ export class Job { job = ''; os = OS; action = ACTION; + deprecatedName = ''; - constructor(name, job) { + constructor(name, job, deprecatedName = '') { this.name = name; this.job = job; + this.deprecatedName = deprecatedName; } toJSON() {