mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-13 13:14:53 +00:00
feat(supported-version): add recent kind (#188)
This commit is contained in:
@@ -5,7 +5,7 @@ description: "A Github Action that computes the Github Actions matrix for the ch
|
|||||||
inputs:
|
inputs:
|
||||||
kind:
|
kind:
|
||||||
required: false
|
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"
|
default: "currently-supported"
|
||||||
project:
|
project:
|
||||||
required: false
|
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`"
|
description: "The specific custom versions of Magento that you want to use. Only applies when `kind` is `custom`"
|
||||||
default: ""
|
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:
|
outputs:
|
||||||
matrix:
|
matrix:
|
||||||
description: "The Github Actions matrix of software technologies required to run Magento."
|
description: "The Github Actions matrix of software technologies required to run Magento."
|
||||||
|
|||||||
Vendored
+6
-66
File diff suppressed because one or more lines are too long
@@ -9,12 +9,13 @@ export async function run(): Promise<void> {
|
|||||||
const kind = core.getInput("kind");
|
const kind = core.getInput("kind");
|
||||||
const customVersions = core.getInput("custom_versions");
|
const customVersions = core.getInput("custom_versions");
|
||||||
const project = core.getInput("project");
|
const project = core.getInput("project");
|
||||||
|
const recent_time_frame = core.getInput("recent_time_frame");
|
||||||
|
|
||||||
validateProject(<any>project)
|
validateProject(<any>project)
|
||||||
|
|
||||||
validateKind(<any>kind, customVersions ? customVersions.split(',') : undefined);
|
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) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export const KNOWN_KINDS = {
|
|||||||
'latest': true,
|
'latest': true,
|
||||||
'custom': true,
|
'custom': true,
|
||||||
'nightly': true,
|
'nightly': true,
|
||||||
|
'recent': true,
|
||||||
'all': true,
|
'all': true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
})
|
||||||
|
|
||||||
@@ -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 { getDayBefore } from '../nightly/get-day-before';
|
||||||
import { getCurrentlySupportedVersions } from "../kind/get-currently-supported";
|
import { getCurrentlySupportedVersions } from "../kind/get-currently-supported";
|
||||||
import { amendMatrixForNext } from "../nightly/amend-matrix-for-next";
|
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){
|
switch(kind){
|
||||||
case 'latest':
|
case 'latest':
|
||||||
@@ -19,6 +20,8 @@ export const getMatrixForKind = (kind: string, project: string, versions = "") =
|
|||||||
return getMatrixForVersions(project, Object.keys(getIndividualVersionsForProject(project)));
|
return getMatrixForVersions(project, Object.keys(getIndividualVersionsForProject(project)));
|
||||||
case 'custom':
|
case 'custom':
|
||||||
return getMatrixForVersions(project, versions.split(","))
|
return getMatrixForVersions(project, versions.split(","))
|
||||||
|
case 'recent':
|
||||||
|
return getMatrixForVersions(project, getRecentVersions(project, new Date(), recent_time_frame));
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unreachable kind: ${kind} discovered, please report to the maintainers.`);
|
throw new Error(`Unreachable kind: ${kind} discovered, please report to the maintainers.`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user