Skip to content

Commit b7e32f8

Browse files
committed
feat(supported-version): add recent kind
1 parent b281820 commit b7e32f8

8 files changed

Lines changed: 177 additions & 43 deletions

File tree

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`, `usable`, `nightly`, and `all`"
8+
description: "The kind of versions you want to return. Allowed values are `currently-supported`, `latest`, `custom`, `usable`, `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: 38 additions & 37 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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ import { validateProject } from "./project/validate-projects";
55

66

77
export async function run(): Promise<void> {
8-
try {
8+
try {
99
const kind = core.getInput("kind");
1010
const customVersions = core.getInput("custom_versions");
1111
const project = core.getInput("project");
12-
12+
const recent_time_frame = core.getInput("recent_time_frame");
13+
1314
validateProject(<any>project)
1415

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

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

supported-version/src/kind/kinds.ts

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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.4-p13",
52+
"magento/project-community-edition:2.4.5-p9",
53+
"magento/project-community-edition:2.4.5-p10",
54+
"magento/project-community-edition:2.4.5-p11",
55+
"magento/project-community-edition:2.4.5-p12",
56+
"magento/project-community-edition:2.4.5-p13",
57+
"magento/project-community-edition:2.4.6-p7",
58+
"magento/project-community-edition:2.4.6-p8",
59+
"magento/project-community-edition:2.4.6-p9",
60+
"magento/project-community-edition:2.4.6-p10",
61+
"magento/project-community-edition:2.4.6-p11",
62+
"magento/project-community-edition:2.4.7-p2",
63+
"magento/project-community-edition:2.4.7-p3",
64+
"magento/project-community-edition:2.4.7-p4",
65+
"magento/project-community-edition:2.4.7-p5",
66+
"magento/project-community-edition:2.4.7-p6",
67+
"magento/project-community-edition:2.4.8",
68+
"magento/project-community-edition:2.4.8-p1"
69+
]],
70+
])(
71+
'recent for %s',
72+
(date, description ,result) => {
73+
expect(
74+
getRecentVersions(project, new Date(date), '360d')
75+
).toEqual(result);
76+
}
77+
);
78+
})
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.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ describe('getMatrixForKind for mage-os', () => {
4747
expect(result.include).toBeDefined();
4848
});
4949

50+
it('returns a matrix for `recent`', () => {
51+
const result = getMatrixForKind("recent", project);
52+
53+
expect(result.magento).toBeDefined();
54+
expect(result.include).toBeDefined();
55+
});
56+
5057
it('errors for invalid `custom``', () => {
5158
expect(() => getMatrixForKind("custom", project)).toThrowError();
5259
});
@@ -104,6 +111,13 @@ describe('getMatrixForKind for magento-open-source', () => {
104111
expect(result.include).toBeDefined();
105112
});
106113

114+
it('returns a matrix for `recent`', () => {
115+
const result = getMatrixForKind("recent", project);
116+
117+
expect(result.magento).toBeDefined();
118+
expect(result.include).toBeDefined();
119+
});
120+
107121
it('errors for invalid `custom``', () => {
108122
expect(() => getMatrixForKind("custom", project)).toThrowError();
109123
});

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { getDayBefore } from '../nightly/get-day-before';
66
import { getCurrentlySupportedVersions } from "../kind/get-currently-supported";
77
import { getUsableVersions } from "../kind/get-usable";
88
import { amendMatrixForNext } from "../nightly/amend-matrix-for-next";
9+
import { getRecentVersions } from "../kind/recent";
910

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

1213
switch(kind){
1314
case 'latest':
@@ -22,6 +23,8 @@ export const getMatrixForKind = (kind: string, project: string, versions = "") =
2223
return getMatrixForVersions(project, Object.keys(getIndividualVersionsForProject(project)));
2324
case 'custom':
2425
return getMatrixForVersions(project, versions.split(","))
26+
case 'recent':
27+
return getMatrixForVersions(project, getRecentVersions(project, new Date(), recent_time_frame));
2528
default:
2629
throw new Error(`Unreachable kind: ${kind} discovered, please report to the maintainers.`);
2730
}

0 commit comments

Comments
 (0)