Skip to content

Commit 15c66c4

Browse files
committed
feature: introduce semver via composer/semver to better detect PHP version ranges
Signed-off-by: Maximilian Bösing <[email protected]>
1 parent 3570ac9 commit 15c66c4

File tree

6 files changed

+62
-24
lines changed

6 files changed

+62
-24
lines changed

Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ RUN npm ci
99
COPY ./src ./src
1010
RUN npm run build
1111

12-
12+
FROM ghcr.io/boesing/composer-semver:1.0 as composer-semver
13+
FROM php:8.1.9-cli-alpine as php
1314
FROM node:18-alpine
15+
1416
LABEL "repository"="http://github.com/laminas/laminas-ci-matrix-action"
1517
LABEL "homepage"="http://github.com/laminas/laminas-ci-matrix-action"
1618
LABEL "maintainer"="https://github.com/laminas/technical-steering-committee/"
@@ -25,6 +27,16 @@ ADD laminas-ci.schema.json /action/
2527
COPY --from=compiler /usr/local/source/dist/main.js /action/
2628
RUN chmod u+x /action/main.js
2729

30+
# Setup PHP
31+
RUN mkdir -p /usr/local/bin /usr/local/etc /usr/local/lib
32+
COPY --from=php /usr/local/bin/php /usr/local/bin
33+
COPY --from=php /usr/local/etc/* /usr/local/etc
34+
COPY --from=php /usr/local/lib/php/* /usr/local/lib/php
35+
COPY --from=php /usr/lib/* /usr/lib
36+
COPY --from=php /lib/* /lib
37+
38+
COPY --from=composer-semver /usr/local/bin/main.phar /usr/local/bin/composer-semver.phar
39+
2840
ADD entrypoint.sh /usr/local/bin/entrypoint.sh
2941

3042
ENTRYPOINT ["entrypoint.sh"]

package-lock.json

Lines changed: 19 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
},
66
"type": "commonjs",
77
"devDependencies": {
8+
"@types/node": "^18.6.4",
89
"@typescript-eslint/eslint-plugin": "^5.16.0",
910
"@typescript-eslint/parser": "^5.16.0",
10-
"@types/node": "^18.6.4",
1111
"eslint": "^8.11.0",
1212
"eslint-config-incredible": "^2.4.2",
1313
"eslint-import-resolver-typescript": "^2.7.0",
@@ -25,7 +25,6 @@
2525
"dependencies": {
2626
"@actions/core": "^1.6.0",
2727
"@cfworker/json-schema": "^1.12.2",
28-
"@types/semver": "^7.3.9",
29-
"semver": "^7.3.5"
28+
"child_process": "^1.0.2"
3029
}
3130
}

src/app.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export class App {
8181
this.checkRequirements(filesFromDiff),
8282
this.composerJsonFileName,
8383
this.composerLockJsonFileName,
84-
this.continousIntegrationConfigurationJsonFileName
84+
this.continousIntegrationConfigurationJsonFileName,
85+
this.logger
8586
);
8687
}
8788

src/config/app.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import fs, {PathLike} from 'fs';
2-
import semver from 'semver';
32
import parseJsonFile from '../json';
43
import {Tool, ToolExecutionType} from '../tools';
54
import {Logger} from '../logging';
65
import {CURRENT_STABLE, INSTALLABLE_VERSIONS, InstallablePhpVersionType, isInstallableVersion} from './php';
76
import {ComposerJson} from './composer';
87
import {ConfigurationFromFile, isAdditionalChecksConfiguration, isAnyComposerDependencySet, isAnyPhpVersionType, isConfigurationContainingJobExclusions, isExplicitChecksConfiguration, isLatestPhpVersionType, isLowestPhpVersionType, JobDefinitionFromFile, JobFromFile, JobToExcludeFromFile} from './input';
8+
import {satisfies} from "../semver";
99

1010
export const OPERATING_SYSTEM = 'ubuntu-latest';
1111
export const ACTION = 'laminas/laminas-continuous-integration-action@v1';
@@ -16,19 +16,29 @@ export enum ComposerDependencySet {
1616
LATEST = 'latest',
1717
}
1818

19-
function gatherVersions(composerJson: ComposerJson): InstallablePhpVersionType[] {
19+
function gatherVersions(composerJson: ComposerJson, logger: Logger): InstallablePhpVersionType[] {
2020
if (JSON.stringify(composerJson) === '{}') {
21+
logger.debug('The composer.json file is either empty or does not exist.');
2122
return [];
2223
}
2324

2425
const composerPhpVersion: string = (composerJson.require?.php ?? '').replace(/,\s/, ' ');
2526

2627
if (composerPhpVersion === '') {
28+
logger.debug('`composer.json` does not contain any PHP requirement.');
2729
return [];
2830
}
2931

3032
return INSTALLABLE_VERSIONS
31-
.filter((version) => semver.satisfies(`${version}.0`, composerPhpVersion));
33+
.filter((version) => {
34+
if (satisfies(`${version}.0`, composerPhpVersion)) {
35+
logger.debug(`PHP ${version} is supported by projects \`composer.json\`!`)
36+
return true;
37+
}
38+
39+
logger.debug(`PHP ${version} is NOT supported by projects \`composer.json\`!`)
40+
return false;
41+
});
3242
}
3343

3444
function gatherExtensions(composerJson: ComposerJson): Set<string> {
@@ -418,12 +428,13 @@ export default function createConfig(
418428
requirements: Requirements,
419429
composerJsonFileName: PathLike,
420430
composerLockJsonFileName: PathLike,
421-
continousIntegrationConfigurationJsonFileName: PathLike
431+
continousIntegrationConfigurationJsonFileName: PathLike,
432+
logger: Logger
422433
): Config {
423434
const composerJson: ComposerJson = parseJsonFile(composerJsonFileName) as ComposerJson;
424435
const configurationFromFile: ConfigurationFromFile =
425436
parseJsonFile(continousIntegrationConfigurationJsonFileName) as ConfigurationFromFile;
426-
const phpVersionsSupportedByProject: InstallablePhpVersionType[] = gatherVersions(composerJson);
437+
const phpVersionsSupportedByProject: InstallablePhpVersionType[] = gatherVersions(composerJson, logger);
427438
let phpExtensions: Set<string> = gatherExtensions(composerJson);
428439
let stablePHPVersion: InstallablePhpVersionType = CURRENT_STABLE;
429440

src/semver.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {execSync} from "child_process";
2+
3+
export function satisfies(version: string, constraint: string): boolean {
4+
try {
5+
execSync(`/usr/local/bin/composer-semver.phar semver:match "${version}" "${constraint}" > /dev/null`)
6+
return true;
7+
} catch (error) {
8+
return false;
9+
}
10+
}

0 commit comments

Comments
 (0)