Skip to content

Commit

Permalink
Merge pull request #184 from boesing/feature/exclude-php-and-dependen…
Browse files Browse the repository at this point in the history
…cies

Extend `exclude` with `php` and `dependencies` settings
  • Loading branch information
boesing committed May 5, 2024
2 parents f25365c + 64b9e8b commit 5c34e3c
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 34 deletions.
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ The "job" element will have the following elements, but is not restricted to the
],
"dependencies": "(optional) dependencies to test against; one of lowest, locked, latest. default: locked",
"command": "(required) command to run to perform the check",
"ignore_platform_reqs_8": "(optional; deprecated) boolean; whether to add `--ignore-platform-req=php` to composer for PHP 8.0. default: true",
"ignore_php_platform_requirement": "(optional) boolean; whether to add `--ignore-platform-req=php` to composer for this job.",
"ignore_platform_reqs_8": "(optional; deprecated) boolean; whether to add `--ignore-platform-req=php` to Composer for PHP 8.0. default: true",
"ignore_php_platform_requirement": "(optional) boolean; whether to add `--ignore-platform-req=php` to Composer for this job.",
"additional_composer_arguments": [
"(optional) list of arguments to be passed to `composer install` and `composer update`"
]
Expand Down Expand Up @@ -200,18 +200,45 @@ The tool discovers checks first, then appends any `additional_checks` are concat

### Excluding specific jobs

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

```json
{
"exclude": [
{
"name": "PHPUnit on PHP 8.0 with latest dependencies"
"name": "PHPUnit"
}
]
}
```

If you want to limit the exclusion to specific PHP versions, you can additionally add a PHP version:

```json
{
"exclude": [
{
"name": "PHPUnit",
"php": "8.0"
}
]
}
```

In case you only want to exclude jobs for specific Composer dependency sets, add `dependencies` to the `exclude` configuration:

```json
{
"exclude": [
{
"name": "PHPUnit",
"php": "8.0",
"dependencies": "latest"
}
]
}
```

## Testing matrix generation locally using Docker

To test matrix generation in a local checkout on your own machine, you can do the following:
Expand Down
89 changes: 66 additions & 23 deletions laminas-ci.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"exclude": [
{
"name": "Codeception [7.4, latest]"
},
{
"name": "Codeception",
"php": "7.4",
"dependencies": "latest"
}
],
"ignore_php_platform_requirements": {
Expand Down Expand Up @@ -243,6 +248,39 @@
}
],
"definitions": {
"installablePhpVersion": {
"type": "string",
"title": "Installable PHP versions from available from within the container.",
"enum": [
"5.6",
"7.0",
"7.1",
"7.2",
"7.3",
"7.4",
"8.0",
"8.1",
"8.2",
"8.3",
"@default"
]
},
"php": {
"title": "The PHP version",
"type": "string",
"anyOf": [
{
"$ref": "#/definitions/installablePhpVersion"
},
{
"enum": [
"*",
"@latest",
"@lowest"
]
}
]
},
"extensions": {
"type": "array",
"title": "A list of PHP extensions",
Expand Down Expand Up @@ -285,6 +323,11 @@
[
{
"name": "Codeception [7.4, latest]"
},
{
"name": "Codeception",
"php": "7.4",
"dependencies": "latest"
}
]
],
Expand All @@ -294,6 +337,11 @@
"examples": [
{
"name": "Codeception [7.4, latest]"
},
{
"name": "Codeception",
"php": "7.4",
"dependencies": "latest"
}
],
"required": [
Expand All @@ -306,8 +354,21 @@
"description": "The name of the job to be excluded. Must be an exact match.",
"minLength": 1,
"examples": [
"Codeception [7.4, latest]"
"Codeception [7.4, latest]",
"Codeception"
]
},
"php": {
"ref": "#/definitions/php",
"description": "The PHP version to to be excluded.",
"default": "*"
},
"dependencies": {
"type": "string",
"enum": ["latest", "lowest", "locked", "*"],
"title": "The composer dependencies to be excluded",
"description": "The composer dependencies to be excluded. If the wildcard `*` is passed, all dependencies are being excluded",
"default": "*"
}
},
"additionalProperties": false
Expand All @@ -331,13 +392,10 @@
}
},
"stablePHP": {
"type": "string",
"minLength": 1,
"$ref": "#/definitions/installablePhpVersion",
"title": "The PHP version to be used for stable checks",
"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.",
"examples": [
"8.0"
]
"default": "8.0"
},
"backwardCompatibilityCheck": {
"type": "boolean",
Expand All @@ -361,24 +419,9 @@
],
"properties": {
"php": {
"type": "string",
"title": "The php version",
"$ref": "#/definitions/php",
"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.",
"enum": [
"5.6",
"7.0",
"7.1",
"7.2",
"7.3",
"7.4",
"8.0",
"8.1",
"8.2",
"8.3",
"*",
"@latest",
"@lowest"
]
"default": "*"
},
"dependencies": {
"type": "string",
Expand Down
89 changes: 85 additions & 4 deletions src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,28 @@ import semver from 'semver';
import parseJsonFile from '../json';
import {isToolRunningContainerDefaultPhpVersion, Tool, ToolExecutionType} from '../tools';
import {Logger} from '../logging';
import {CURRENT_STABLE, INSTALLABLE_VERSIONS, InstallablePhpVersionType, isInstallableVersion} from './php';
import {
CONTAINER_DEFAULT_PHP_VERSION,
CURRENT_STABLE,
INSTALLABLE_VERSIONS,
InstallablePhpVersionType,
isInstallableVersion
} from './php';
import {ComposerJson} from './composer';
import {ConfigurationFromFile, isAdditionalChecksConfiguration, isAnyComposerDependencySet, isAnyPhpVersionType, isConfigurationContainingJobExclusions, isExplicitChecksConfiguration, isLatestPhpVersionType, isLowestPhpVersionType, JobDefinitionFromFile, JobFromFile, JobToExcludeFromFile} from './input';
import {
ConfigurationFromFile,
isAdditionalChecksConfiguration,
isAnyComposerDependencySet,
isAnyPhpVersionType,
isConfigurationContainingJobExclusions,
isExplicitChecksConfiguration,
isLatestPhpVersionType,
isLowestPhpVersionType,
JobDefinitionFromFile,
JobFromFile,
JobToExcludeFromFile,
WILDCARD_ALIAS
} from './input';

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

function isJobExcludedByName(job: Job, exclude: JobToExcludeFromFile): boolean {
if (job.name === exclude.name) {
return true;
}

if (isJobFromTool(job)) {
return job.tool.name === exclude.name;
}

return false;
}

function isJobExcludedByConfiguration(
job: Job,
exclude: JobToExcludeFromFile,
config: Config,
logger: Logger
): boolean {
if (!isJobExcludedByName(job, exclude)) {
return false;
}

const jobName = isJobFromTool(job) ? job.tool.name : job.name;

const phpVersionToExclude = exclude.php ?? WILDCARD_ALIAS;
const dependenciesToExclude = exclude.dependencies ?? WILDCARD_ALIAS;

if (!isAnyPhpVersionType(phpVersionToExclude)) {
const nonExcludedPhpVersionDebugMessage = `Job with name ${ jobName } is not matching exclusion rule`
+ ` with name ${ exclude.name } due to non-excluded php version.`;

if (isLowestPhpVersionType(phpVersionToExclude) && job.job.php !== config.minimumPhpVersion) {
logger.debug(nonExcludedPhpVersionDebugMessage);

return false;
}

if (isLatestPhpVersionType(phpVersionToExclude) && job.job.php !== config.latestPhpVersion) {
logger.debug(nonExcludedPhpVersionDebugMessage);

return false;
}

if (phpVersionToExclude !== job.job.php) {
logger.debug(nonExcludedPhpVersionDebugMessage);

return false;
}
}

if (!isAnyComposerDependencySet(dependenciesToExclude) && dependenciesToExclude !== job.job.composerDependencySet) {
logger.debug(
`Job with name ${ jobName } is not matching exclusion rule`
+ ` with name ${ exclude.name } due to non-excluded Composer dependencies.`
);

return false;
}

return true;
}

function isJobExcluded(job: Job, exclusions: JobToExcludeFromFile[], config: Config, logger: Logger): boolean {
if (exclusions.length === 0) {
return false;
}

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

return true;
Expand Down Expand Up @@ -385,7 +466,7 @@ function createNoOpCheck(config: Config): Job {
operatingSystem : OPERATING_SYSTEM,
action : ACTION,
job : {
php : config.stablePhpVersion,
php : CONTAINER_DEFAULT_PHP_VERSION,
phpExtensions : [],
command : '',
composerDependencySet : ComposerDependencySet.LOCKED,
Expand Down
4 changes: 3 additions & 1 deletion src/config/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {ComposerDependencySet, IgnorePhpPlatformRequirements} from './app';

export interface JobToExcludeFromFile {
name: string;
php?: InstallablePhpVersionType,
dependencies?: ComposerDependencySet,
}

export interface ConfigurationFromFile {
extensions?: string[];
ini?: string[];
ignore_php_platform_requirements?: IgnorePhpPlatformRequirements;
stablePHP?: string;
stablePHP?: InstallablePhpVersionType;
additional_composer_arguments?: string[];
backwardCompatibilityCheck?: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"exclude": [
{
"name": "PHPUnit",
"php": "8.1",
"dependencies": "latest"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"php": "~8.0.0 || ~8.1.0 || ~8.2.0"
}
}
34 changes: 34 additions & 0 deletions tests/configuration-exclude-php-dependency-combination/matrix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"include": [
{
"name": "PHPUnit [8.0, lowest]",
"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\"]}",
"operatingSystem": "ubuntu-latest",
"action": "laminas/laminas-continuous-integration-action@v1"
},
{
"name": "PHPUnit [8.0, latest]",
"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\"]}",
"operatingSystem": "ubuntu-latest",
"action": "laminas/laminas-continuous-integration-action@v1"
},
{
"name": "PHPUnit [8.1, lowest]",
"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\"]}",
"operatingSystem": "ubuntu-latest",
"action": "laminas/laminas-continuous-integration-action@v1"
},
{
"name": "PHPUnit [8.2, lowest]",
"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\"]}",
"operatingSystem": "ubuntu-latest",
"action": "laminas/laminas-continuous-integration-action@v1"
},
{
"name": "PHPUnit [8.2, latest]",
"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\"]}",
"operatingSystem": "ubuntu-latest",
"action": "laminas/laminas-continuous-integration-action@v1"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" ?>
<dummy/>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"exclude": [
{
"name": "PHPUnit",
"php": "8.1"
}
]
}

0 comments on commit 5c34e3c

Please sign in to comment.