feat(supported-version): add recent kind (#188)

This commit is contained in:
Damien Retzinger
2025-04-09 09:51:01 -04:00
committed by GitHub
parent 157b6877e2
commit 2f1b2eaa5d
7 changed files with 120 additions and 69 deletions
+6 -1
View File
@@ -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
@@ -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."
+6 -66
View File
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -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);
+1
View File
@@ -6,6 +6,7 @@ export const KNOWN_KINDS = {
'latest': true,
'custom': true,
'nightly': true,
'recent': true,
'all': true,
}
+70
View File
@@ -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
View File
@@ -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,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':
@@ -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.`);
}