Skip to content

Commit f7f0504

Browse files
authored
feat: add project versions (#110)
* refactor: allow version matrixes by projects * feat: add initial version-matrix for mage-os * feat: add project as optional input to action * docs: document new input * refactor: tighten types a bit * chore: apply change requests from code review
1 parent 28643a7 commit f7f0504

27 files changed

+331
-67
lines changed

supported-version/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Magento 2 Supported Versions
22

3-
A Github Action that computes the currently supported Github Actions Matrix for Magento 2 Versions
3+
A GitHub Action that computes the currently supported GitHub Actions Matrix for Magento 2 Versions
44

55
All data comes from:
66

@@ -11,17 +11,23 @@ All data comes from:
1111

1212
See the [action.yml](./action.yml)
1313

14-
| Input | Description | Required | Default |
15-
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ----------- |
14+
| Input | Description | Required | Default |
15+
|-----------------| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- |-----------------------|
1616
| kind | The "kind" of support you're targeting for your package. Allowed values are `currently-supported`, `latest`, `custom`, `nightly` and `all` | false | 'currently-supported' |
17-
| custom_versions | The versions you want to support, as a comma-separated string, i.e. 'magento/project-community-edition:2.3.7-p3, magento/project-community-edition:2.4.2-p2' | false | '' |
17+
| project | The project to return the supported versions for. Allowed values are `mage-os` and `magento-open-source` | false | 'magento-open-source' |
18+
| custom_versions | The versions you want to support, as a comma-separated string, i.e. 'magento/project-community-edition:2.3.7-p3, magento/project-community-edition:2.4.2-p2' | false | '' |
1819

1920
## Kinds
2021
- `currently-supported` - The currently supported Magento Open Source versions by Adobe.
2122
- `latest` - The latest version of Magento only.
2223
- `custom` - A custom subset of the versions, as specified by you. Requires `custom_versions` sibling key.
2324
- `nightly` - The nightly version of Magento (only available via `https://upstream-nightly.mage-os.org`)
2425
- `all` - All versions of Magento (including patched/unpatched versions).
26+
27+
## Projects
28+
- `mage-os`
29+
- `magento-open-source` (default)
30+
2531
## Usage
2632

2733
```yml

supported-version/action.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
name: "Compute Supported Magento 2 Versions"
2-
author: "Graycore"
1+
name: "Compute Supported Mage-OS and Magento 2 Versions"
2+
author: "Mage-OS"
33
description: "A Github Action that computes the Github Actions matrix for the chosen versions of Magento 2"
44

55
inputs:
66
kind:
77
required: false
88
description: "The kind of versions you want to return. Allowed values are `currently-supported`, `latest`, `custom`, `nightly` and `all`"
99
default: "currently-supported"
10+
project:
11+
required: false
12+
description: "The project to return the supported versions for. Allowed values are `mage-os` and `magento-open-source`"
13+
# The default value is what it is to keep backward compatibility
14+
default: "magento-open-source"
1015
custom_versions:
1116
required: false
1217
description: "The specific custom versions of Magento that you want to use. Only applies when `kind` is `custom`"

supported-version/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import * as core from '@actions/core';
22
import { validateKind } from './kind/validate-kinds';
33
import { getMatrixForKind } from './matrix/get-matrix-for-kind';
4+
import { validateProject } from "./project/validate-projects";
45

56

67
export async function run(): Promise<void> {
78
try {
89
const kind = core.getInput("kind");
910
const customVersions = core.getInput("custom_versions");
11+
const project = core.getInput("project");
12+
13+
validateProject(<any>project)
1014

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

13-
core.setOutput('matrix', getMatrixForKind(kind, customVersions));
17+
core.setOutput('matrix', getMatrixForKind(kind, project, customVersions));
1418
}
1519
catch (error) {
1620
core.setFailed(error.message);

supported-version/src/kind/get-currently-supported.spec.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { getCurrentlySupportedVersions } from "./get-currently-supported";
2+
import { Project } from "../project/projects";
23

3-
describe('getCurrentlySupportedVersions', () => {
4+
describe('getCurrentlySupportedVersions for magento-open-source', () => {
5+
const project: Project = "magento-open-source";
6+
47
it('should say that v2.4.0 is not supported in 2025', () => {
58
const date: Date = new Date('2025-01-01T00:00:00Z');
6-
expect(getCurrentlySupportedVersions(date)).not.toContain('magento/project-community-edition:2.4.0');
9+
expect(getCurrentlySupportedVersions(project, date)).not.toContain('magento/project-community-edition:2.4.0');
710
});
811

912
test.each([
10-
//TODO: add a release-date so that past dates do not incur non-contemporaneous
11-
// versions.
1213
['2023-01-01T00:00:00Z', 'First day of 2023', [
1314
'magento/project-community-edition:2.4.4-p2',
1415
'magento/project-community-edition:2.4.5-p1',
@@ -49,7 +50,31 @@ describe('getCurrentlySupportedVersions', () => {
4950
'supportedVersions for %s',
5051
(date, description ,result) => {
5152
expect(
52-
getCurrentlySupportedVersions(new Date(date))
53+
getCurrentlySupportedVersions(project, new Date(date))
54+
).toEqual(result);
55+
}
56+
);
57+
})
58+
59+
describe('getCurrentlySupportedVersions for mage-os', () => {
60+
const project: Project = "mage-os";
61+
62+
it('should say that v1.0.0 is not supported in 2027', () => {
63+
const date: Date = new Date('2027-01-01T00:00:00Z');
64+
expect(getCurrentlySupportedVersions(project, date)).not.toContain('mage-os/project-community-edition:1.0.0');
65+
});
66+
67+
test.each([
68+
['2023-01-01T00:00:00Z', 'First day of 2023', [
69+
]],
70+
['2024-01-01T00:00:00Z', 'First day of 2024', [
71+
'mage-os/project-community-edition:1.0.0',
72+
]],
73+
])(
74+
'supportedVersions for %s',
75+
(date, description ,result) => {
76+
expect(
77+
getCurrentlySupportedVersions(project, new Date(date))
5378
).toEqual(result);
5479
}
5580
);
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { MagentoMatrixVersion } from '../matrix/matrix-type';
2-
import allVersions from '../versions/individual.json';
1+
import { PackageMatrixVersion } from '../matrix/matrix-type';
2+
import { getIndividualVersionsForProject } from "../versions/get-versions-for-project";
33

4-
export const getCurrentlySupportedVersions = (date: Date): string[] =>
5-
Object.entries(<Record<string,MagentoMatrixVersion>>allVersions)
6-
.filter(([key, value]) => {
7-
const dayAfterRelease = new Date(value.release);
8-
dayAfterRelease.setDate(dayAfterRelease.getDate() + 1);
9-
return date >= dayAfterRelease && new Date(value.eol) >= date;
10-
})
11-
.map(([key, value]) => key);
4+
export const getCurrentlySupportedVersions = (project: string, date: Date): string[] => {
5+
const allVersions = getIndividualVersionsForProject(project)
6+
return Object.entries(<Record<string,PackageMatrixVersion>>allVersions)
7+
.filter(([key, value]) => {
8+
const dayAfterRelease = new Date(value.release);
9+
dayAfterRelease.setDate(dayAfterRelease.getDate() + 1);
10+
return date >= dayAfterRelease && new Date(value.eol) >= date;
11+
})
12+
.map(([key, value]) => key);
13+
}

supported-version/src/kind/latest.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

supported-version/src/kind/nightly.json

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"mage-os": ["mage-os/project-community-edition"],
3+
"magento-open-source": ["magento/project-community-edition"]
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"mage-os": ["mage-os/project-community-edition:next"],
3+
"magento-open-source": ["magento/project-community-edition:next"]
4+
}
Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,96 @@
11
import { getMatrixForKind } from "./get-matrix-for-kind";
22

3-
describe('getMatrixForKind', () => {
3+
4+
describe('getMatrixForKind for mage-os', () => {
5+
const project = "mage-os";
6+
7+
it('returns a matrix for `latest`', () => {
8+
const result = getMatrixForKind("latest", project);
9+
10+
expect(result.magento).toBeDefined();
11+
expect(result.include).toBeDefined();
12+
});
13+
14+
it('returns a matrix for `currently-supported`', () => {
15+
const result = getMatrixForKind("currently-supported", project);
16+
17+
expect(result.magento).toBeDefined();
18+
expect(result.include).toBeDefined();
19+
});
20+
21+
it('returns a matrix for `all`', () => {
22+
const result = getMatrixForKind("all", project);
23+
24+
expect(result.magento).toBeDefined();
25+
expect(result.include).toBeDefined();
26+
});
27+
28+
it('returns a matrix for valid `custom`', () => {
29+
const result = getMatrixForKind("custom", project, "mage-os/project-community-edition:1.0.0");
30+
31+
expect(result.magento).toBeDefined();
32+
expect(result.include).toBeDefined();
33+
});
34+
35+
it('returns a matrix for the next release when using `nightly`', () => {
36+
const result = getMatrixForKind("nightly", project, "mage-os/project-community-edition:next");
37+
38+
expect(result.magento).toBeDefined();
39+
expect(result.include).toBeDefined();
40+
});
41+
42+
it('errors for invalid `custom``', () => {
43+
expect(() => getMatrixForKind("custom", project)).toThrowError();
44+
});
45+
})
46+
47+
48+
describe('getMatrixForKind for magento-open-source', () => {
49+
const project = "magento-open-source";
50+
451
it('returns a matrix for `latest`', () => {
5-
const result = getMatrixForKind("latest");
52+
const result = getMatrixForKind("latest", project);
653

754
expect(result.magento).toBeDefined();
855
expect(result.include).toBeDefined();
956
});
1057

1158
it('returns a matrix for `currently-supported`', () => {
12-
const result = getMatrixForKind("currently-supported");
59+
const result = getMatrixForKind("currently-supported", project);
1360

1461
expect(result.magento).toBeDefined();
1562
expect(result.include).toBeDefined();
1663
});
1764

1865
it('returns a matrix for `all`', () => {
19-
const result = getMatrixForKind("all");
66+
const result = getMatrixForKind("all", project);
2067

2168
expect(result.magento).toBeDefined();
2269
expect(result.include).toBeDefined();
2370
});
2471

2572
it('returns a matrix for valid `custom`', () => {
26-
const result = getMatrixForKind("custom", "magento/project-community-edition:2.3.7-p3");
73+
const result = getMatrixForKind("custom", project, "magento/project-community-edition:2.3.7-p3");
2774

2875
expect(result.magento).toBeDefined();
2976
expect(result.include).toBeDefined();
3077
});
3178

3279
it('returns a matrix for the next release when using `nightly`', () => {
33-
const result = getMatrixForKind("nightly", "magento/project-community-edition:next");
80+
const result = getMatrixForKind("nightly", project, "magento/project-community-edition:next");
3481

3582
expect(result.magento).toBeDefined();
3683
expect(result.include).toBeDefined();
3784
});
3885

3986
it('returns a matrix for valid multiple `custom`', () => {
40-
const result = getMatrixForKind("custom", "magento/project-community-edition:2.3.7-p3,magento/project-community-edition:2.4.0");
87+
const result = getMatrixForKind("custom", project, "magento/project-community-edition:2.3.7-p3,magento/project-community-edition:2.4.0");
4188

4289
expect(result.magento).toBeDefined();
4390
expect(result.include).toBeDefined();
4491
});
4592

4693
it('errors for invalid `custom``', () => {
47-
expect(() => getMatrixForKind("custom")).toThrowError();
94+
expect(() => getMatrixForKind("custom", project)).toThrowError();
4895
});
4996
})

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { getMatrixForVersions } from "./get-matrix-for-versions";
2-
3-
import latestJson from '../kind/latest.json';
4-
import allVersions from '../versions/individual.json';
5-
import nightly from '../kind/nightly.json';
2+
import { getIndividualVersionsForProject } from "../versions/get-versions-for-project";
3+
import latestJson from '../kind/special-versions/latest.json';
4+
import nightlyJson from '../kind/special-versions/nightly.json';
65
import { amendMatrixForNext } from "../nightly/get-next-version";
76
import { getDayBefore } from '../nightly/get-day-before';
87
import { getCurrentlySupportedVersions } from "../kind/get-currently-supported";
98

10-
export const getMatrixForKind = (kind: string, versions = "") => {
9+
export const getMatrixForKind = (kind: string, project: string, versions = "") => {
10+
1111
switch(kind){
1212
case 'latest':
13-
return getMatrixForVersions(latestJson);
13+
return getMatrixForVersions(project, latestJson[project]);
1414
case 'currently-supported':
15-
return getMatrixForVersions(getCurrentlySupportedVersions(new Date()));
15+
return getMatrixForVersions(project, getCurrentlySupportedVersions(project, new Date()));
1616
case 'nightly':
17-
return amendMatrixForNext(getMatrixForVersions(nightly), 'https://upstream-mirror.mage-os.org', getDayBefore());
17+
return amendMatrixForNext(getMatrixForVersions(project, nightlyJson[project]), 'https://upstream-mirror.mage-os.org', getDayBefore());
1818
case 'all':
19-
return getMatrixForVersions(Object.keys(allVersions));
19+
return getMatrixForVersions(project, Object.keys(getIndividualVersionsForProject(project)));
2020
case 'custom':
21-
return getMatrixForVersions(versions.split(","))
21+
return getMatrixForVersions(project, versions.split(","))
2222
default:
2323
throw new Error(`Unreachable kind: ${kind} discovered, please report to the maintainers.`);
2424
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { GithubActionsMatrix, MagentoMatrixVersion } from "./matrix-type";
2-
import compositeVersionJson from '../versions/composite.json';
3-
import individualVersionJson from '../versions/individual.json';
4-
5-
const knownVersions : Record<string, MagentoMatrixVersion> = {...individualVersionJson, ...compositeVersionJson };
1+
import { GithubActionsMatrix, PackageMatrixVersion } from "./matrix-type";
2+
import { getIndividualVersionsForProject, getCompositeVersionsForProject } from "../versions/get-versions-for-project";
63

74
/**
8-
* Computes the Github Actions Matrix for given versions of Magento
5+
* Computes the GitHub Actions Matrix for given versions of Magento
96
*/
10-
export const getMatrixForVersions = (versions: string[]): GithubActionsMatrix => {
7+
export const getMatrixForVersions = (project: string, versions: string[]): GithubActionsMatrix => {
8+
const knownVersions : Record<string, PackageMatrixVersion> = {
9+
...getIndividualVersionsForProject(project), ...getCompositeVersionsForProject(project)
10+
}
11+
1112
return versions.reduce((acc, current): GithubActionsMatrix => {
12-
if(knownVersions[current] === undefined){
13-
throw new Error("Unknown version while computing matrix");
13+
if (knownVersions[current] === undefined){
14+
throw new Error(`Unknown "${current}" version while computing matrix`);
1415
}
1516

1617
return {

supported-version/src/matrix/matrix-type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface MagentoMatrixVersion {
1+
export interface PackageMatrixVersion {
22
magento: string,
33
php: string | number,
44
composer: string | number,
@@ -15,5 +15,5 @@ export interface MagentoMatrixVersion {
1515

1616
export interface GithubActionsMatrix {
1717
magento: string[],
18-
include: MagentoMatrixVersion[]
18+
include: PackageMatrixVersion[]
1919
}

supported-version/src/nightly/get-next-version.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import { getNextVersion } from "./get-next-version"
22

33
describe('getNextVersion', () => {
44

5-
it('should get the next nightly version for MageOS', () => {
6-
expect(getNextVersion('https://upstream-mirror.mage-os.org', new Date('2022-09-29T17:47:00')), ).toEqual('@alpha');
5+
it('should get the next nightly version for Magento Open Source', () => {
6+
expect(getNextVersion('https://upstream-nightly.mage-os.org', new Date('2022-09-29T17:47:00')), ).toEqual('@alpha');
7+
});
8+
9+
it('should get the next nightly version for Mage-OS', () => {
10+
expect(getNextVersion('https://nightly.mage-os.org', new Date('2024-09-29T17:47:00')), ).toEqual('@alpha');
711
});
812

913
it('should handle the first of the month correctly', () => {
10-
expect(getNextVersion('https://upstream-mirror.mage-os.org', new Date('2022-01-01T17:47:00')), ).toEqual('@alpha');
14+
expect(getNextVersion('https://upstream-nightly.mage-os.org', new Date('2022-01-01T17:47:00')), ).toEqual('@alpha');
1115
});
1216
})

0 commit comments

Comments
 (0)