Skip to content

Commit 5c34e3c

Browse files
authored
Merge pull request #184 from boesing/feature/exclude-php-and-dependencies
Extend `exclude` with `php` and `dependencies` settings
2 parents f25365c + 64b9e8b commit 5c34e3c

File tree

16 files changed

+280
-34
lines changed

16 files changed

+280
-34
lines changed

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ The "job" element will have the following elements, but is not restricted to the
111111
],
112112
"dependencies": "(optional) dependencies to test against; one of lowest, locked, latest. default: locked",
113113
"command": "(required) command to run to perform the check",
114-
"ignore_platform_reqs_8": "(optional; deprecated) boolean; whether to add `--ignore-platform-req=php` to composer for PHP 8.0. default: true",
115-
"ignore_php_platform_requirement": "(optional) boolean; whether to add `--ignore-platform-req=php` to composer for this job.",
114+
"ignore_platform_reqs_8": "(optional; deprecated) boolean; whether to add `--ignore-platform-req=php` to Composer for PHP 8.0. default: true",
115+
"ignore_php_platform_requirement": "(optional) boolean; whether to add `--ignore-platform-req=php` to Composer for this job.",
116116
"additional_composer_arguments": [
117117
"(optional) list of arguments to be passed to `composer install` and `composer update`"
118118
]
@@ -200,18 +200,45 @@ The tool discovers checks first, then appends any `additional_checks` are concat
200200

201201
### Excluding specific jobs
202202

203-
The easiest way to exclude a single job is via the `name` parameter:
203+
You can exclude specific jobs by using their names:
204204

205205
```json
206206
{
207207
"exclude": [
208208
{
209-
"name": "PHPUnit on PHP 8.0 with latest dependencies"
209+
"name": "PHPUnit"
210210
}
211211
]
212212
}
213213
```
214214

215+
If you want to limit the exclusion to specific PHP versions, you can additionally add a PHP version:
216+
217+
```json
218+
{
219+
"exclude": [
220+
{
221+
"name": "PHPUnit",
222+
"php": "8.0"
223+
}
224+
]
225+
}
226+
```
227+
228+
In case you only want to exclude jobs for specific Composer dependency sets, add `dependencies` to the `exclude` configuration:
229+
230+
```json
231+
{
232+
"exclude": [
233+
{
234+
"name": "PHPUnit",
235+
"php": "8.0",
236+
"dependencies": "latest"
237+
}
238+
]
239+
}
240+
```
241+
215242
## Testing matrix generation locally using Docker
216243

217244
To test matrix generation in a local checkout on your own machine, you can do the following:

laminas-ci.schema.json

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
"exclude": [
2626
{
2727
"name": "Codeception [7.4, latest]"
28+
},
29+
{
30+
"name": "Codeception",
31+
"php": "7.4",
32+
"dependencies": "latest"
2833
}
2934
],
3035
"ignore_php_platform_requirements": {
@@ -243,6 +248,39 @@
243248
}
244249
],
245250
"definitions": {
251+
"installablePhpVersion": {
252+
"type": "string",
253+
"title": "Installable PHP versions from available from within the container.",
254+
"enum": [
255+
"5.6",
256+
"7.0",
257+
"7.1",
258+
"7.2",
259+
"7.3",
260+
"7.4",
261+
"8.0",
262+
"8.1",
263+
"8.2",
264+
"8.3",
265+
"@default"
266+
]
267+
},
268+
"php": {
269+
"title": "The PHP version",
270+
"type": "string",
271+
"anyOf": [
272+
{
273+
"$ref": "#/definitions/installablePhpVersion"
274+
},
275+
{
276+
"enum": [
277+
"*",
278+
"@latest",
279+
"@lowest"
280+
]
281+
}
282+
]
283+
},
246284
"extensions": {
247285
"type": "array",
248286
"title": "A list of PHP extensions",
@@ -285,6 +323,11 @@
285323
[
286324
{
287325
"name": "Codeception [7.4, latest]"
326+
},
327+
{
328+
"name": "Codeception",
329+
"php": "7.4",
330+
"dependencies": "latest"
288331
}
289332
]
290333
],
@@ -294,6 +337,11 @@
294337
"examples": [
295338
{
296339
"name": "Codeception [7.4, latest]"
340+
},
341+
{
342+
"name": "Codeception",
343+
"php": "7.4",
344+
"dependencies": "latest"
297345
}
298346
],
299347
"required": [
@@ -306,8 +354,21 @@
306354
"description": "The name of the job to be excluded. Must be an exact match.",
307355
"minLength": 1,
308356
"examples": [
309-
"Codeception [7.4, latest]"
357+
"Codeception [7.4, latest]",
358+
"Codeception"
310359
]
360+
},
361+
"php": {
362+
"ref": "#/definitions/php",
363+
"description": "The PHP version to to be excluded.",
364+
"default": "*"
365+
},
366+
"dependencies": {
367+
"type": "string",
368+
"enum": ["latest", "lowest", "locked", "*"],
369+
"title": "The composer dependencies to be excluded",
370+
"description": "The composer dependencies to be excluded. If the wildcard `*` is passed, all dependencies are being excluded",
371+
"default": "*"
311372
}
312373
},
313374
"additionalProperties": false
@@ -331,13 +392,10 @@
331392
}
332393
},
333394
"stablePHP": {
334-
"type": "string",
335-
"minLength": 1,
395+
"$ref": "#/definitions/installablePhpVersion",
336396
"title": "The PHP version to be used for stable checks",
337397
"description": "This PHP version is used for all QA check jobs. The default depends on the `composer.json` of the project and usually reflects the minimum supported PHP version of that project.",
338-
"examples": [
339-
"8.0"
340-
]
398+
"default": "8.0"
341399
},
342400
"backwardCompatibilityCheck": {
343401
"type": "boolean",
@@ -361,24 +419,9 @@
361419
],
362420
"properties": {
363421
"php": {
364-
"type": "string",
365-
"title": "The php version",
422+
"$ref": "#/definitions/php",
366423
"description": "The PHP version to be used. If the wildcard `*` is passed, a list of checks is created containing *every* supported PHP version by the project and the matrix action.",
367-
"enum": [
368-
"5.6",
369-
"7.0",
370-
"7.1",
371-
"7.2",
372-
"7.3",
373-
"7.4",
374-
"8.0",
375-
"8.1",
376-
"8.2",
377-
"8.3",
378-
"*",
379-
"@latest",
380-
"@lowest"
381-
]
424+
"default": "*"
382425
},
383426
"dependencies": {
384427
"type": "string",

src/config/app.ts

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,28 @@ import semver from 'semver';
33
import parseJsonFile from '../json';
44
import {isToolRunningContainerDefaultPhpVersion, Tool, ToolExecutionType} from '../tools';
55
import {Logger} from '../logging';
6-
import {CURRENT_STABLE, INSTALLABLE_VERSIONS, InstallablePhpVersionType, isInstallableVersion} from './php';
6+
import {
7+
CONTAINER_DEFAULT_PHP_VERSION,
8+
CURRENT_STABLE,
9+
INSTALLABLE_VERSIONS,
10+
InstallablePhpVersionType,
11+
isInstallableVersion
12+
} from './php';
713
import {ComposerJson} from './composer';
8-
import {ConfigurationFromFile, isAdditionalChecksConfiguration, isAnyComposerDependencySet, isAnyPhpVersionType, isConfigurationContainingJobExclusions, isExplicitChecksConfiguration, isLatestPhpVersionType, isLowestPhpVersionType, JobDefinitionFromFile, JobFromFile, JobToExcludeFromFile} from './input';
14+
import {
15+
ConfigurationFromFile,
16+
isAdditionalChecksConfiguration,
17+
isAnyComposerDependencySet,
18+
isAnyPhpVersionType,
19+
isConfigurationContainingJobExclusions,
20+
isExplicitChecksConfiguration,
21+
isLatestPhpVersionType,
22+
isLowestPhpVersionType,
23+
JobDefinitionFromFile,
24+
JobFromFile,
25+
JobToExcludeFromFile,
26+
WILDCARD_ALIAS
27+
} from './input';
928

1029
export const OPERATING_SYSTEM = 'ubuntu-latest';
1130
export const ACTION = 'laminas/laminas-continuous-integration-action@v1';
@@ -242,12 +261,74 @@ function isJobExcludedByDeprecatedCommandName(job: Job, exclusions: JobToExclude
242261
);
243262
}
244263

264+
function isJobExcludedByName(job: Job, exclude: JobToExcludeFromFile): boolean {
265+
if (job.name === exclude.name) {
266+
return true;
267+
}
268+
269+
if (isJobFromTool(job)) {
270+
return job.tool.name === exclude.name;
271+
}
272+
273+
return false;
274+
}
275+
276+
function isJobExcludedByConfiguration(
277+
job: Job,
278+
exclude: JobToExcludeFromFile,
279+
config: Config,
280+
logger: Logger
281+
): boolean {
282+
if (!isJobExcludedByName(job, exclude)) {
283+
return false;
284+
}
285+
286+
const jobName = isJobFromTool(job) ? job.tool.name : job.name;
287+
288+
const phpVersionToExclude = exclude.php ?? WILDCARD_ALIAS;
289+
const dependenciesToExclude = exclude.dependencies ?? WILDCARD_ALIAS;
290+
291+
if (!isAnyPhpVersionType(phpVersionToExclude)) {
292+
const nonExcludedPhpVersionDebugMessage = `Job with name ${ jobName } is not matching exclusion rule`
293+
+ ` with name ${ exclude.name } due to non-excluded php version.`;
294+
295+
if (isLowestPhpVersionType(phpVersionToExclude) && job.job.php !== config.minimumPhpVersion) {
296+
logger.debug(nonExcludedPhpVersionDebugMessage);
297+
298+
return false;
299+
}
300+
301+
if (isLatestPhpVersionType(phpVersionToExclude) && job.job.php !== config.latestPhpVersion) {
302+
logger.debug(nonExcludedPhpVersionDebugMessage);
303+
304+
return false;
305+
}
306+
307+
if (phpVersionToExclude !== job.job.php) {
308+
logger.debug(nonExcludedPhpVersionDebugMessage);
309+
310+
return false;
311+
}
312+
}
313+
314+
if (!isAnyComposerDependencySet(dependenciesToExclude) && dependenciesToExclude !== job.job.composerDependencySet) {
315+
logger.debug(
316+
`Job with name ${ jobName } is not matching exclusion rule`
317+
+ ` with name ${ exclude.name } due to non-excluded Composer dependencies.`
318+
);
319+
320+
return false;
321+
}
322+
323+
return true;
324+
}
325+
245326
function isJobExcluded(job: Job, exclusions: JobToExcludeFromFile[], config: Config, logger: Logger): boolean {
246327
if (exclusions.length === 0) {
247328
return false;
248329
}
249330

250-
if (exclusions.some((exclude) => job.name === exclude.name)) {
331+
if (exclusions.some((exclude) => isJobExcludedByConfiguration(job, exclude, config, logger))) {
251332
logger.info(`Job with name ${ job.name } is excluded due to application config.`);
252333

253334
return true;
@@ -385,7 +466,7 @@ function createNoOpCheck(config: Config): Job {
385466
operatingSystem : OPERATING_SYSTEM,
386467
action : ACTION,
387468
job : {
388-
php : config.stablePhpVersion,
469+
php : CONTAINER_DEFAULT_PHP_VERSION,
389470
phpExtensions : [],
390471
command : '',
391472
composerDependencySet : ComposerDependencySet.LOCKED,

src/config/input.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import {ComposerDependencySet, IgnorePhpPlatformRequirements} from './app';
33

44
export interface JobToExcludeFromFile {
55
name: string;
6+
php?: InstallablePhpVersionType,
7+
dependencies?: ComposerDependencySet,
68
}
79

810
export interface ConfigurationFromFile {
911
extensions?: string[];
1012
ini?: string[];
1113
ignore_php_platform_requirements?: IgnorePhpPlatformRequirements;
12-
stablePHP?: string;
14+
stablePHP?: InstallablePhpVersionType;
1315
additional_composer_arguments?: string[];
1416
backwardCompatibilityCheck?: boolean;
1517
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"exclude": [
3+
{
4+
"name": "PHPUnit",
5+
"php": "8.1",
6+
"dependencies": "latest"
7+
}
8+
]
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"php": "~8.0.0 || ~8.1.0 || ~8.2.0"
4+
}
5+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"include": [
3+
{
4+
"name": "PHPUnit [8.0, lowest]",
5+
"job": "{\"command\":\"./vendor/bin/phpunit\",\"php\":\"8.0\",\"extensions\":[],\"ini\":[],\"dependencies\":\"lowest\",\"ignore_platform_reqs_8\":false,\"ignore_php_platform_requirement\":false,\"additional_composer_arguments\":[],\"before_script\":[\"xmllint --schema vendor/phpunit/phpunit/phpunit.xsd phpunit.xml.dist\"]}",
6+
"operatingSystem": "ubuntu-latest",
7+
"action": "laminas/laminas-continuous-integration-action@v1"
8+
},
9+
{
10+
"name": "PHPUnit [8.0, latest]",
11+
"job": "{\"command\":\"./vendor/bin/phpunit\",\"php\":\"8.0\",\"extensions\":[],\"ini\":[],\"dependencies\":\"latest\",\"ignore_platform_reqs_8\":false,\"ignore_php_platform_requirement\":false,\"additional_composer_arguments\":[],\"before_script\":[\"xmllint --schema vendor/phpunit/phpunit/phpunit.xsd phpunit.xml.dist\"]}",
12+
"operatingSystem": "ubuntu-latest",
13+
"action": "laminas/laminas-continuous-integration-action@v1"
14+
},
15+
{
16+
"name": "PHPUnit [8.1, lowest]",
17+
"job": "{\"command\":\"./vendor/bin/phpunit\",\"php\":\"8.1\",\"extensions\":[],\"ini\":[],\"dependencies\":\"lowest\",\"ignore_platform_reqs_8\":false,\"ignore_php_platform_requirement\":false,\"additional_composer_arguments\":[],\"before_script\":[\"xmllint --schema vendor/phpunit/phpunit/phpunit.xsd phpunit.xml.dist\"]}",
18+
"operatingSystem": "ubuntu-latest",
19+
"action": "laminas/laminas-continuous-integration-action@v1"
20+
},
21+
{
22+
"name": "PHPUnit [8.2, lowest]",
23+
"job": "{\"command\":\"./vendor/bin/phpunit\",\"php\":\"8.2\",\"extensions\":[],\"ini\":[],\"dependencies\":\"lowest\",\"ignore_platform_reqs_8\":false,\"ignore_php_platform_requirement\":false,\"additional_composer_arguments\":[],\"before_script\":[\"xmllint --schema vendor/phpunit/phpunit/phpunit.xsd phpunit.xml.dist\"]}",
24+
"operatingSystem": "ubuntu-latest",
25+
"action": "laminas/laminas-continuous-integration-action@v1"
26+
},
27+
{
28+
"name": "PHPUnit [8.2, latest]",
29+
"job": "{\"command\":\"./vendor/bin/phpunit\",\"php\":\"8.2\",\"extensions\":[],\"ini\":[],\"dependencies\":\"latest\",\"ignore_platform_reqs_8\":false,\"ignore_php_platform_requirement\":false,\"additional_composer_arguments\":[],\"before_script\":[\"xmllint --schema vendor/phpunit/phpunit/phpunit.xsd phpunit.xml.dist\"]}",
30+
"operatingSystem": "ubuntu-latest",
31+
"action": "laminas/laminas-continuous-integration-action@v1"
32+
}
33+
]
34+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<dummy/>

tests/configuration-exclude-php-dependency-combination/test.env

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"exclude": [
3+
{
4+
"name": "PHPUnit",
5+
"php": "8.1"
6+
}
7+
]
8+
}

0 commit comments

Comments
 (0)