Skip to content

Commit 479b40f

Browse files
committed
feat(supported-version): add recent kind
1 parent fb29b3d commit 479b40f

File tree

7 files changed

+120
-69
lines changed

7 files changed

+120
-69
lines changed

supported-version/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "A Github Action that computes the Github Actions matrix for the ch
55
inputs:
66
kind:
77
required: false
8-
description: "The kind of versions you want to return. Allowed values are `currently-supported`, `latest`, `custom`, `nightly` and `all`"
8+
description: "The kind of versions you want to return. Allowed values are `currently-supported`, `latest`, `custom`, `nightly`, `recent` and `all`"
99
default: "currently-supported"
1010
project:
1111
required: false
@@ -17,6 +17,11 @@ inputs:
1717
description: "The specific custom versions of Magento that you want to use. Only applies when `kind` is `custom`"
1818
default: ""
1919

20+
recent_time_frame:
21+
required: false
22+
default: "2y"
23+
description: "The time frame (from today). Only used in `recent` kind. String that defines a time duration using a combination of years (y), months (m), and days (d). Each unit is optional and can appear in any order, separated by spaces. For example `2y 2m 2d`. "
24+
2025
outputs:
2126
matrix:
2227
description: "The Github Actions matrix of software technologies required to run Magento."

supported-version/dist/index.js

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

supported-version/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ export async function run(): Promise<void> {
99
const kind = core.getInput("kind");
1010
const customVersions = core.getInput("custom_versions");
1111
const project = core.getInput("project");
12+
const recent_time_frame = core.getInput("recent_time_frame");
1213

1314
validateProject(<any>project)
1415

1516
validateKind(<any>kind, customVersions ? customVersions.split(',') : undefined);
1617

17-
core.setOutput('matrix', getMatrixForKind(kind, project, customVersions));
18+
core.setOutput('matrix', getMatrixForKind(kind, project, customVersions, recent_time_frame));
1819
}
1920
catch (error) {
2021
core.setFailed(error.message);

supported-version/src/kind/kinds.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const KNOWN_KINDS = {
66
'latest': true,
77
'custom': true,
88
'nightly': true,
9+
'recent': true,
910
'all': true,
1011
}
1112

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Project } from "../project/projects";
2+
import { getRecentVersions } from "./recent";
3+
4+
describe('recent for magento-open-source', () => {
5+
const project: Project = "magento-open-source";
6+
7+
test.each([
8+
['2024-12-31T00:00:00Z', 'End of 2024', [
9+
"magento/project-community-edition:2.4.4-p7",
10+
"magento/project-community-edition:2.4.4-p8",
11+
"magento/project-community-edition:2.4.4-p9",
12+
"magento/project-community-edition:2.4.4-p10",
13+
"magento/project-community-edition:2.4.4-p11",
14+
"magento/project-community-edition:2.4.5-p6",
15+
"magento/project-community-edition:2.4.5-p7",
16+
"magento/project-community-edition:2.4.5-p8",
17+
"magento/project-community-edition:2.4.5-p9",
18+
"magento/project-community-edition:2.4.5-p10",
19+
"magento/project-community-edition:2.4.6-p4",
20+
"magento/project-community-edition:2.4.6-p5",
21+
"magento/project-community-edition:2.4.6-p6",
22+
"magento/project-community-edition:2.4.6-p7",
23+
"magento/project-community-edition:2.4.6-p8",
24+
"magento/project-community-edition:2.4.7",
25+
"magento/project-community-edition:2.4.7-p1",
26+
"magento/project-community-edition:2.4.7-p2",
27+
"magento/project-community-edition:2.4.7-p3",
28+
]],
29+
['2025-04-08T00:00:00Z', 'The day Damien wrote a test.', [
30+
"magento/project-community-edition:2.4.4-p9",
31+
"magento/project-community-edition:2.4.4-p10",
32+
"magento/project-community-edition:2.4.4-p11",
33+
"magento/project-community-edition:2.4.4-p12",
34+
"magento/project-community-edition:2.4.5-p8",
35+
"magento/project-community-edition:2.4.5-p9",
36+
"magento/project-community-edition:2.4.5-p10",
37+
"magento/project-community-edition:2.4.5-p11",
38+
"magento/project-community-edition:2.4.6-p6",
39+
"magento/project-community-edition:2.4.6-p7",
40+
"magento/project-community-edition:2.4.6-p8",
41+
"magento/project-community-edition:2.4.6-p9",
42+
"magento/project-community-edition:2.4.7-p1",
43+
"magento/project-community-edition:2.4.7-p2",
44+
"magento/project-community-edition:2.4.7-p3",
45+
"magento/project-community-edition:2.4.7-p4",
46+
]],
47+
['2025-08-08T00:00:00Z', 'Day Before v2.4.5 EoL', [
48+
"magento/project-community-edition:2.4.4-p10",
49+
"magento/project-community-edition:2.4.4-p11",
50+
"magento/project-community-edition:2.4.4-p12",
51+
"magento/project-community-edition:2.4.5-p9",
52+
"magento/project-community-edition:2.4.5-p10",
53+
"magento/project-community-edition:2.4.5-p11",
54+
"magento/project-community-edition:2.4.6-p7",
55+
"magento/project-community-edition:2.4.6-p8",
56+
"magento/project-community-edition:2.4.6-p9",
57+
"magento/project-community-edition:2.4.7-p2",
58+
"magento/project-community-edition:2.4.7-p3",
59+
"magento/project-community-edition:2.4.7-p4",
60+
]],
61+
])(
62+
'recent for %s',
63+
(date, description ,result) => {
64+
expect(
65+
getRecentVersions(project, new Date(date), '360d')
66+
).toEqual(result);
67+
}
68+
);
69+
})
70+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { PackageMatrixVersion } from '../matrix/matrix-type';
2+
import { getIndividualVersionsForProject } from "../versions/get-versions-for-project";
3+
4+
export const getRecentVersions = (project: string, date: Date, durationStr: string): string[] => {
5+
const regex = /(?:(\d+)\s*y)?\s*(?:(\d+)\s*m)?\s*(?:(\d+)\s*d)?/i;
6+
const match = durationStr.match(regex);
7+
8+
if (!match) {
9+
throw new Error(`Invalid duration string: ${durationStr}`);
10+
}
11+
12+
const years = parseInt(match[1] || "0", 10);
13+
const months = parseInt(match[2] || "0", 10);
14+
const days = parseInt(match[3] || "0", 10);
15+
16+
const allVersions = getIndividualVersionsForProject(project)
17+
return Object.entries(<Record<string,PackageMatrixVersion>>allVersions)
18+
.filter(([key, value]) => {
19+
const dayOfRelease = new Date(value.release);
20+
dayOfRelease.setSeconds(dayOfRelease.getSeconds() + 1);
21+
const dateAfterRelease = new Date(value.release);
22+
23+
dateAfterRelease.setFullYear(dateAfterRelease.getFullYear() + years);
24+
dateAfterRelease.setMonth(dateAfterRelease.getMonth() + months);
25+
dateAfterRelease.setDate(dateAfterRelease.getDate() + days);
26+
27+
28+
return date >= dayOfRelease && date <= dateAfterRelease;
29+
})
30+
.map(([key, value]) => key);
31+
}

supported-version/src/matrix/get-matrix-for-kind.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import nightlyJson from '../kind/special-versions/nightly.json';
55
import { getDayBefore } from '../nightly/get-day-before';
66
import { getCurrentlySupportedVersions } from "../kind/get-currently-supported";
77
import { amendMatrixForNext } from "../nightly/amend-matrix-for-next";
8+
import { getRecentVersions } from "../kind/recent";
89

9-
export const getMatrixForKind = (kind: string, project: string, versions = "") => {
10+
export const getMatrixForKind = (kind: string, project: string, versions = "", recent_time_frame = '2y') => {
1011

1112
switch(kind){
1213
case 'latest':
@@ -19,6 +20,8 @@ export const getMatrixForKind = (kind: string, project: string, versions = "") =
1920
return getMatrixForVersions(project, Object.keys(getIndividualVersionsForProject(project)));
2021
case 'custom':
2122
return getMatrixForVersions(project, versions.split(","))
23+
case 'recent':
24+
return getMatrixForVersions(project, getRecentVersions(project, new Date(), recent_time_frame));
2225
default:
2326
throw new Error(`Unreachable kind: ${kind} discovered, please report to the maintainers.`);
2427
}

0 commit comments

Comments
 (0)