Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion supported-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: "A Github Action that computes the Github Actions matrix for the ch
inputs:
kind:
required: false
description: "The kind of versions you want to return. Allowed values are `currently-supported`, `latest`, `custom`, `nightly` and `all`"
description: "The kind of versions you want to return. Allowed values are `currently-supported`, `latest`, `custom`, `nightly`, `recent` and `all`"
default: "currently-supported"
project:
required: false
Expand All @@ -17,6 +17,11 @@ inputs:
description: "The specific custom versions of Magento that you want to use. Only applies when `kind` is `custom`"
default: ""

recent_time_frame:
required: false
default: "2y"
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`. "

outputs:
matrix:
description: "The Github Actions matrix of software technologies required to run Magento."
Expand Down
72 changes: 6 additions & 66 deletions supported-version/dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion supported-version/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export async function run(): Promise<void> {
const kind = core.getInput("kind");
const customVersions = core.getInput("custom_versions");
const project = core.getInput("project");
const recent_time_frame = core.getInput("recent_time_frame");

validateProject(<any>project)

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

core.setOutput('matrix', getMatrixForKind(kind, project, customVersions));
core.setOutput('matrix', getMatrixForKind(kind, project, customVersions, recent_time_frame));
}
catch (error) {
core.setFailed(error.message);
Expand Down
1 change: 1 addition & 0 deletions supported-version/src/kind/kinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const KNOWN_KINDS = {
'latest': true,
'custom': true,
'nightly': true,
'recent': true,
'all': true,
}

Expand Down
70 changes: 70 additions & 0 deletions supported-version/src/kind/recent.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Project } from "../project/projects";
import { getRecentVersions } from "./recent";

describe('recent for magento-open-source', () => {
const project: Project = "magento-open-source";

test.each([
['2024-12-31T00:00:00Z', 'End of 2024', [
"magento/project-community-edition:2.4.4-p7",
"magento/project-community-edition:2.4.4-p8",
"magento/project-community-edition:2.4.4-p9",
"magento/project-community-edition:2.4.4-p10",
"magento/project-community-edition:2.4.4-p11",
"magento/project-community-edition:2.4.5-p6",
"magento/project-community-edition:2.4.5-p7",
"magento/project-community-edition:2.4.5-p8",
"magento/project-community-edition:2.4.5-p9",
"magento/project-community-edition:2.4.5-p10",
"magento/project-community-edition:2.4.6-p4",
"magento/project-community-edition:2.4.6-p5",
"magento/project-community-edition:2.4.6-p6",
"magento/project-community-edition:2.4.6-p7",
"magento/project-community-edition:2.4.6-p8",
"magento/project-community-edition:2.4.7",
"magento/project-community-edition:2.4.7-p1",
"magento/project-community-edition:2.4.7-p2",
"magento/project-community-edition:2.4.7-p3",
]],
['2025-04-08T00:00:00Z', 'The day Damien wrote a test.', [
"magento/project-community-edition:2.4.4-p9",
"magento/project-community-edition:2.4.4-p10",
"magento/project-community-edition:2.4.4-p11",
"magento/project-community-edition:2.4.4-p12",
"magento/project-community-edition:2.4.5-p8",
"magento/project-community-edition:2.4.5-p9",
"magento/project-community-edition:2.4.5-p10",
"magento/project-community-edition:2.4.5-p11",
"magento/project-community-edition:2.4.6-p6",
"magento/project-community-edition:2.4.6-p7",
"magento/project-community-edition:2.4.6-p8",
"magento/project-community-edition:2.4.6-p9",
"magento/project-community-edition:2.4.7-p1",
"magento/project-community-edition:2.4.7-p2",
"magento/project-community-edition:2.4.7-p3",
"magento/project-community-edition:2.4.7-p4",
]],
['2025-08-08T00:00:00Z', 'Day Before v2.4.5 EoL', [
"magento/project-community-edition:2.4.4-p10",
"magento/project-community-edition:2.4.4-p11",
"magento/project-community-edition:2.4.4-p12",
"magento/project-community-edition:2.4.5-p9",
"magento/project-community-edition:2.4.5-p10",
"magento/project-community-edition:2.4.5-p11",
"magento/project-community-edition:2.4.6-p7",
"magento/project-community-edition:2.4.6-p8",
"magento/project-community-edition:2.4.6-p9",
"magento/project-community-edition:2.4.7-p2",
"magento/project-community-edition:2.4.7-p3",
"magento/project-community-edition:2.4.7-p4",
]],
])(
'recent for %s',
(date, description ,result) => {
expect(
getRecentVersions(project, new Date(date), '360d')
).toEqual(result);
}
);
})

31 changes: 31 additions & 0 deletions supported-version/src/kind/recent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { PackageMatrixVersion } from '../matrix/matrix-type';
import { getIndividualVersionsForProject } from "../versions/get-versions-for-project";

export const getRecentVersions = (project: string, date: Date, durationStr: string): string[] => {
const regex = /(?:(\d+)\s*y)?\s*(?:(\d+)\s*m)?\s*(?:(\d+)\s*d)?/i;
const match = durationStr.match(regex);

if (!match) {
throw new Error(`Invalid duration string: ${durationStr}`);
}

const years = parseInt(match[1] || "0", 10);
const months = parseInt(match[2] || "0", 10);
const days = parseInt(match[3] || "0", 10);

const allVersions = getIndividualVersionsForProject(project)
return Object.entries(<Record<string,PackageMatrixVersion>>allVersions)
.filter(([key, value]) => {
const dayOfRelease = new Date(value.release);
dayOfRelease.setSeconds(dayOfRelease.getSeconds() + 1);
const dateAfterRelease = new Date(value.release);

dateAfterRelease.setFullYear(dateAfterRelease.getFullYear() + years);
dateAfterRelease.setMonth(dateAfterRelease.getMonth() + months);
dateAfterRelease.setDate(dateAfterRelease.getDate() + days);


return date >= dayOfRelease && date <= dateAfterRelease;
})
.map(([key, value]) => key);
}
5 changes: 4 additions & 1 deletion supported-version/src/matrix/get-matrix-for-kind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import nightlyJson from '../kind/special-versions/nightly.json';
import { getDayBefore } from '../nightly/get-day-before';
import { getCurrentlySupportedVersions } from "../kind/get-currently-supported";
import { amendMatrixForNext } from "../nightly/amend-matrix-for-next";
import { getRecentVersions } from "../kind/recent";

export const getMatrixForKind = (kind: string, project: string, versions = "") => {
export const getMatrixForKind = (kind: string, project: string, versions = "", recent_time_frame = '2y') => {

switch(kind){
case 'latest':
Expand All @@ -19,6 +20,8 @@ export const getMatrixForKind = (kind: string, project: string, versions = "") =
return getMatrixForVersions(project, Object.keys(getIndividualVersionsForProject(project)));
case 'custom':
return getMatrixForVersions(project, versions.split(","))
case 'recent':
return getMatrixForVersions(project, getRecentVersions(project, new Date(), recent_time_frame));
default:
throw new Error(`Unreachable kind: ${kind} discovered, please report to the maintainers.`);
}
Expand Down
Loading