Skip to content

Commit 059424a

Browse files
Merge pull request #46 from boesing/feature/ignore-platform-reqs
Ignore platform requirements object
2 parents faf2720 + 5cbbc0c commit 059424a

File tree

6 files changed

+106
-44
lines changed

6 files changed

+106
-44
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ The "job" element will have the following elements, but is not restricted to the
9292
"(optional) php.ini directives, one per element; e.g. 'memory_limit=-1'"
9393
],
9494
"dependencies": "(optional) dependencies to test against; one of lowest, locked, latest. default: locked",
95-
"command": "(required) command to run to perform the check",
96-
"ignore_platform_reqs_8": "(optional) boolean; whether to add `--ignore-platform-req=php` to composer for PHP 8.0. default: true"
95+
"command": "(required) command to run to perform the check",
96+
"ignore_platform_reqs_8": "(optional; deprecated) boolean; whether to add `--ignore-platform-req=php` to composer for PHP 8.0. default: true",
97+
"ignore_php_platform_requirement": "(optional) boolean; whether to add `--ignore-platform-req=php` to composer for this job."
9798
}
9899
```
99100

@@ -121,7 +122,9 @@ The package can include a configuration file in its root, `.laminas-ci.json`, wh
121122
{
122123
}
123124
],
124-
"ignore_platform_reqs_8": true,
125+
"ignore_php_platform_requirements": {
126+
"8.0": true
127+
},
125128
"stablePHP": "7.4"
126129
}
127130
```
@@ -168,6 +171,7 @@ The syntax for the `additional_checks` key is as follows:
168171

169172
A job per PHP version per dependency set will be created, and the "name" will be appended with "on PHP {VERSION} with {DEPS} dependencies" during an actual run.
170173
The "job" element MUST have the structure as shown [here](#job-element) **but** the "php" element is mandatory in here and MUST contain either the minor PHP version to run the check against or a wildcard `*` to run the against **all** supported PHP versions.
174+
You can pass the wildcard, "*", for the "php" element; when you do, the `ignore_php_platform_requirement` element will be ignored. It is possible to provide per-version flags by adding the `ignore_php_platform_requirements` element instead.
171175

172176
The tool discovers checks first, then appends any `additional_checks` are concatenated, and then any `exclude` rules are applied.
173177

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {Validator} from "@cfworker/json-schema";
1010
* Do early composer.json schema validation to avoid unnecessary ramp-ups of jobs which may fail
1111
* due to an incompatible composer.json.
1212
*/
13-
if (fs.existsSync('composer.json')) {
13+
if (fs.existsSync('composer.json') && fs.existsSync('/action/composer.schema.json')) {
1414
core.info(`Running composer.json linting.`);
1515
const composerJsonContents = fs.readFileSync('composer.json');
1616
const composerJsonSchemaString = fs.readFileSync('/action/composer.schema.json');
@@ -20,10 +20,7 @@ if (fs.existsSync('composer.json')) {
2020

2121
if (!validationResult.valid) {
2222
validationResult.errors.forEach(function (outputUnit) {
23-
core.error("There is an error in the keyword located by {0}: {1}".format(
24-
outputUnit.keywordLocation,
25-
outputUnit.error
26-
));
23+
core.error(`There is an error in the keyword located by ${outputUnit.keywordLocation}: ${outputUnit.error}`);
2724
});
2825
core.setFailed('composer.json schema validation failed');
2926
process.exit(1);
@@ -48,7 +45,9 @@ core.info(`Using php extensions: ${JSON.stringify(config.extensions)}`);
4845
core.info(`Providing php.ini settings: ${JSON.stringify(config.php_ini)}`);
4946
core.info(`Dependency sets found: ${JSON.stringify(config.dependencies)}`);
5047
core.info(`Additional checks found: ${JSON.stringify(config.additional_checks)}`);
51-
core.info(`Ignore platform reqs on version 8: ${config.ignore_platform_reqs_8 ? "Yes" : "No"}`);
48+
for (const [IGNORE_PLATFORM_REQS_PHP_VERSION, IGNORE_PLATFORM_REQS] of Object.entries(config.ignore_php_platform_requirements)) {
49+
core.info(`Ignoring php platform requirement for PHP ${IGNORE_PLATFORM_REQS_PHP_VERSION}: ${IGNORE_PLATFORM_REQS ? "Yes" : "No"}`);
50+
}
5251

5352
let matrix = {include: createJobs(config)};
5453

src/additional-checks.js

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,59 @@ const discoverDependencySetsForCheck = function (job, config) {
105105
return false;
106106
};
107107

108+
/**
109+
* @param {Object} job
110+
* @param {Object} ignore_php_platform_requirements
111+
* @return {Object}
112+
*/
113+
const discoverIgnorePhpPlatformDetailsForCheck = function (job, ignore_php_platform_requirements) {
114+
let ignore_php_platform_requirements_for_job = ignore_php_platform_requirements;
115+
116+
if (typeof job.php !== 'string') {
117+
return ignore_php_platform_requirements_for_job;
118+
}
119+
120+
if (job.php === '*') {
121+
ignore_php_platform_requirements_for_job = Object.assign(
122+
ignore_php_platform_requirements_for_job,
123+
job.ignore_php_platform_requirements ?? {}
124+
);
125+
126+
return ignore_php_platform_requirements_for_job;
127+
}
128+
129+
if (job.ignore_php_platform_requirement !== undefined && typeof job.ignore_php_platform_requirement === 'boolean') {
130+
ignore_php_platform_requirements_for_job[job.php] = job.ignore_php_platform_requirement;
131+
} else if (job.ignore_platform_reqs_8 !== undefined && typeof job.ignore_platform_reqs_8 === 'boolean') {
132+
core.warning('WARNING: You are using `ignore_platform_reqs_8` in your projects configuration.');
133+
core.warning('This is deprecated as of v1.9.0 of the matrix action and will be removed in future versions.');
134+
core.warning('Please use `ignore_php_platform_requirement` or `ignore_php_platform_requirements` in your additional check configuration instead.');
135+
136+
ignore_php_platform_requirements_for_job['8.0'] = job.ignore_platform_reqs_8;
137+
}
138+
139+
return Object.assign(ignore_php_platform_requirements, ignore_php_platform_requirements_for_job);
140+
};
141+
108142
/**
109143
* @param {String} name
110144
* @param {String} command
111145
* @param {Array} versions
112146
* @param {Array} dependencies
113147
* @param {Array} extensions
114148
* @param {Array} ini
149+
* @param {Object} ignore_php_platform_requirements
115150
* @return {Array} Array of jobs
116151
*/
117-
const createAdditionalJobList = function (name, command, versions, dependencies, extensions, ini) {
152+
const createAdditionalJobList = function (
153+
name,
154+
command,
155+
versions,
156+
dependencies,
157+
extensions,
158+
ini,
159+
ignore_php_platform_requirements
160+
) {
118161
return versions.reduce(function (jobs, version) {
119162
return jobs.concat(dependencies.reduce(function (jobs, deps) {
120163
return jobs.concat(new Job(
@@ -124,7 +167,8 @@ const createAdditionalJobList = function (name, command, versions, dependencies,
124167
version,
125168
extensions,
126169
ini,
127-
deps
170+
deps,
171+
ignore_php_platform_requirements[version] ?? false
128172
))
129173
));
130174
}, []));
@@ -157,7 +201,8 @@ export default function (config) {
157201
versions,
158202
dependencies,
159203
discoverExtensionsForCheck(checkConfig.job, config),
160-
discoverIniSettingsForCheck(checkConfig.job, config)
204+
discoverIniSettingsForCheck(checkConfig.job, config),
205+
discoverIgnorePhpPlatformDetailsForCheck(checkConfig.job, config.ignore_php_platform_requirements)
161206
));
162207
}, []);
163208
};

src/command.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import { CURRENT_STABLE } from './config.js';
22

33
export class Command {
4-
command = '';
5-
php = CURRENT_STABLE;
6-
extensions = [];
7-
ini = [];
8-
dependencies = 'locked';
9-
ignore_platform_reqs_8 = true;
4+
command = '';
5+
php = CURRENT_STABLE;
6+
extensions = [];
7+
ini = [];
8+
dependencies = 'locked';
9+
ignore_php_platform_requirement = false;
1010

1111
/**
1212
* @param {String} command
1313
* @param {String} php
1414
* @param {Array<String>} extensions
1515
* @param {Array<String>} ini
1616
* @param {String} dependencies
17-
* @param {Boolean} ignore_platform_reqs_8
17+
* @param {Boolean} ignore_php_platform_requirement
1818
*/
19-
constructor(command, php, extensions, ini, dependencies, ignore_platform_reqs_8) {
20-
this.command = command;
21-
this.php = php;
22-
this.extensions = extensions;
23-
this.ini = ini;
24-
this.dependencies = dependencies;
25-
this.ignore_platform_reqs_8 = ignore_platform_reqs_8;
19+
constructor(command, php, extensions, ini, dependencies, ignore_php_platform_requirement) {
20+
this.command = command;
21+
this.php = php;
22+
this.extensions = extensions;
23+
this.ini = ini;
24+
this.dependencies = dependencies;
25+
this.ignore_php_platform_requirement = ignore_php_platform_requirement;
2626
}
2727

2828
toJSON() {
@@ -32,7 +32,8 @@ export class Command {
3232
extensions: this.extensions,
3333
ini: this.ini,
3434
dependencies: this.dependencies,
35-
ignore_platform_reqs_8: this.ignore_platform_reqs_8,
35+
ignore_platform_reqs_8: this.ignore_php_platform_requirement,
36+
ignore_php_platform_requirement: this.ignore_php_platform_requirement,
3637
};
3738
}
3839
};

src/config.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import core from '@actions/core';
12
import fs from 'fs';
23
import semver from 'semver';
34
import { Requirements } from './check-requirements.js';
@@ -58,19 +59,21 @@ function gatherVersions (composerJson) {
5859
}
5960

6061
class Config {
61-
code_checks = true;
62-
doc_linting = true;
63-
versions = [];
64-
stable_version = CURRENT_STABLE;
65-
minimum_version = CURRENT_STABLE;
66-
locked_dependencies = false;
67-
extensions = [];
68-
php_ini = ['memory_limit = -1'];
69-
dependencies = ['lowest', 'latest'];
70-
checks = [];
71-
exclude = [];
72-
additional_checks = [];
73-
ignore_platform_reqs_8 = true;
62+
code_checks = true;
63+
doc_linting = true;
64+
versions = [];
65+
stable_version = CURRENT_STABLE;
66+
minimum_version = CURRENT_STABLE;
67+
locked_dependencies = false;
68+
extensions = [];
69+
php_ini = ['memory_limit = -1'];
70+
dependencies = ['lowest', 'latest'];
71+
checks = [];
72+
exclude = [];
73+
additional_checks = [];
74+
ignore_php_platform_requirements = {
75+
'8.0': true
76+
};
7477

7578
/**
7679
* @param {Requirements} requirements
@@ -116,8 +119,18 @@ class Config {
116119
this.additional_checks = configuration.additional_checks;
117120
}
118121

122+
if (configuration.ignore_php_platform_requirements !== undefined && typeof configuration.ignore_php_platform_requirements === 'object') {
123+
this.ignore_php_platform_requirements = Object.assign(
124+
this.ignore_php_platform_requirements,
125+
configuration.ignore_php_platform_requirements
126+
);
127+
}
128+
119129
if (configuration.ignore_platform_reqs_8 !== undefined && typeof configuration.ignore_platform_reqs_8 === 'boolean') {
120-
this.ignore_platform_reqs_8 = configuration.ignore_platform_reqs_8;
130+
core.warning('WARNING: You are using `ignore_platform_reqs_8` in your projects configuration.');
131+
core.warning('This is deprecated as of v1.9.0 of the matrix action and will be removed in future versions.');
132+
core.warning('Please use `ignore_php_platform_requirements` instead.');
133+
this.ignore_php_platform_requirements['8.0'] = configuration.ignore_platform_reqs_8;
121134
}
122135
}
123136
}

src/create-jobs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const createQaJobs = function (command, config) {
3434
config.extensions,
3535
config.php_ini,
3636
'locked',
37-
config.ignore_platform_reqs_8,
37+
config.ignore_php_platform_requirements[config.minimum_version] ?? false,
3838
))
3939
)];
4040
};
@@ -84,7 +84,7 @@ const createPHPUnitJob = function (version, deps, config) {
8484
config.extensions,
8585
config.php_ini,
8686
deps,
87-
config.ignore_platform_reqs_8,
87+
config.ignore_php_platform_requirements[version] ?? false,
8888
)),
8989
);
9090
};
@@ -102,7 +102,7 @@ const createNoOpJob = function (config) {
102102
[],
103103
[],
104104
'locked',
105-
config.ignore_platform_reqs_8,
105+
config.ignore_php_platform_requirements[config.stable_version] ?? false,
106106
)),
107107
)];
108108
};

0 commit comments

Comments
 (0)