Skip to content

feat: add project versions #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 6, 2023
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
14 changes: 10 additions & 4 deletions supported-version/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Magento 2 Supported Versions

A Github Action that computes the currently supported Github Actions Matrix for Magento 2 Versions
A GitHub Action that computes the currently supported GitHub Actions Matrix for Magento 2 Versions

All data comes from:

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

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

| Input | Description | Required | Default |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ----------- |
| Input | Description | Required | Default |
|-----------------| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- |-----------------------|
| kind | The "kind" of support you're targeting for your package. Allowed values are `currently-supported`, `latest`, `custom`, `nightly` and `all` | false | 'currently-supported' |
| 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 | '' |
| project | The project to return the supported versions for. Allowed values are `mage-os` and `magento-open-source` | false | 'magento-open-source' |
| 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 | '' |

## Kinds
- `currently-supported` - The currently supported Magento Open Source versions by Adobe.
- `latest` - The latest version of Magento only.
- `custom` - A custom subset of the versions, as specified by you. Requires `custom_versions` sibling key.
- `nightly` - The nightly version of Magento (only available via `https://upstream-nightly.mage-os.org`)
- `all` - All versions of Magento (including patched/unpatched versions).

## Projects
- `mage-os`
- `magento-open-source` (default)

## Usage

```yml
Expand Down
9 changes: 7 additions & 2 deletions supported-version/action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
name: "Compute Supported Magento 2 Versions"
author: "Graycore"
name: "Compute Supported Mage-OS and Magento 2 Versions"
author: "Mage-OS"
description: "A Github Action that computes the Github Actions matrix for the chosen versions of Magento 2"

inputs:
kind:
required: false
description: "The kind of versions you want to return. Allowed values are `currently-supported`, `latest`, `custom`, `nightly` and `all`"
default: "currently-supported"
project:
required: false
description: "The project to return the supported versions for. Allowed values are `mage-os` and `magento-open-source`"
# The default value is what it is to keep backward compatibility
default: "magento-open-source"
custom_versions:
required: false
description: "The specific custom versions of Magento that you want to use. Only applies when `kind` is `custom`"
Expand Down
6 changes: 5 additions & 1 deletion supported-version/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import * as core from '@actions/core';
import { validateKind } from './kind/validate-kinds';
import { getMatrixForKind } from './matrix/get-matrix-for-kind';
import { validateProject } from "./project/validate-projects";


export async function run(): Promise<void> {
try {
const kind = core.getInput("kind");
const customVersions = core.getInput("custom_versions");
const project = core.getInput("project");

validateProject(<any>project)

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

core.setOutput('matrix', getMatrixForKind(kind, customVersions));
core.setOutput('matrix', getMatrixForKind(kind, project, customVersions));
}
catch (error) {
core.setFailed(error.message);
Expand Down
35 changes: 30 additions & 5 deletions supported-version/src/kind/get-currently-supported.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { getCurrentlySupportedVersions } from "./get-currently-supported";
import { Project } from "../project/projects";

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

it('should say that v2.4.0 is not supported in 2025', () => {
const date: Date = new Date('2025-01-01T00:00:00Z');
expect(getCurrentlySupportedVersions(date)).not.toContain('magento/project-community-edition:2.4.0');
expect(getCurrentlySupportedVersions(project, date)).not.toContain('magento/project-community-edition:2.4.0');
});

test.each([
//TODO: add a release-date so that past dates do not incur non-contemporaneous
// versions.
['2023-01-01T00:00:00Z', 'First day of 2023', [
'magento/project-community-edition:2.4.4-p2',
'magento/project-community-edition:2.4.5-p1',
Expand Down Expand Up @@ -49,7 +50,31 @@ describe('getCurrentlySupportedVersions', () => {
'supportedVersions for %s',
(date, description ,result) => {
expect(
getCurrentlySupportedVersions(new Date(date))
getCurrentlySupportedVersions(project, new Date(date))
).toEqual(result);
}
);
})

describe('getCurrentlySupportedVersions for mage-os', () => {
const project: Project = "mage-os";

it('should say that v1.0.0 is not supported in 2027', () => {
const date: Date = new Date('2027-01-01T00:00:00Z');
expect(getCurrentlySupportedVersions(project, date)).not.toContain('mage-os/project-community-edition:1.0.0');
});

test.each([
['2023-01-01T00:00:00Z', 'First day of 2023', [
]],
['2024-01-01T00:00:00Z', 'First day of 2024', [
'mage-os/project-community-edition:1.0.0',
]],
])(
'supportedVersions for %s',
(date, description ,result) => {
expect(
getCurrentlySupportedVersions(project, new Date(date))
).toEqual(result);
}
);
Expand Down
22 changes: 12 additions & 10 deletions supported-version/src/kind/get-currently-supported.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { MagentoMatrixVersion } from '../matrix/matrix-type';
import allVersions from '../versions/individual.json';
import { PackageMatrixVersion } from '../matrix/matrix-type';
import { getIndividualVersionsForProject } from "../versions/get-versions-for-project";

export const getCurrentlySupportedVersions = (date: Date): string[] =>
Object.entries(<Record<string,MagentoMatrixVersion>>allVersions)
.filter(([key, value]) => {
const dayAfterRelease = new Date(value.release);
dayAfterRelease.setDate(dayAfterRelease.getDate() + 1);
return date >= dayAfterRelease && new Date(value.eol) >= date;
})
.map(([key, value]) => key);
export const getCurrentlySupportedVersions = (project: string, date: Date): string[] => {
const allVersions = getIndividualVersionsForProject(project)
return Object.entries(<Record<string,PackageMatrixVersion>>allVersions)
.filter(([key, value]) => {
const dayAfterRelease = new Date(value.release);
dayAfterRelease.setDate(dayAfterRelease.getDate() + 1);
return date >= dayAfterRelease && new Date(value.eol) >= date;
})
.map(([key, value]) => key);
}
3 changes: 0 additions & 3 deletions supported-version/src/kind/latest.json

This file was deleted.

3 changes: 0 additions & 3 deletions supported-version/src/kind/nightly.json

This file was deleted.

4 changes: 4 additions & 0 deletions supported-version/src/kind/special-versions/latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"mage-os": ["mage-os/project-community-edition"],
"magento-open-source": ["magento/project-community-edition"]
}
4 changes: 4 additions & 0 deletions supported-version/src/kind/special-versions/nightly.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"mage-os": ["mage-os/project-community-edition:next"],
"magento-open-source": ["magento/project-community-edition:next"]
}
63 changes: 55 additions & 8 deletions supported-version/src/matrix/get-matrix-for-kind.spec.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,96 @@
import { getMatrixForKind } from "./get-matrix-for-kind";

describe('getMatrixForKind', () => {

describe('getMatrixForKind for mage-os', () => {
const project = "mage-os";

it('returns a matrix for `latest`', () => {
const result = getMatrixForKind("latest", project);

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

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

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

it('returns a matrix for `all`', () => {
const result = getMatrixForKind("all", project);

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

it('returns a matrix for valid `custom`', () => {
const result = getMatrixForKind("custom", project, "mage-os/project-community-edition:1.0.0");

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

it('returns a matrix for the next release when using `nightly`', () => {
const result = getMatrixForKind("nightly", project, "mage-os/project-community-edition:next");

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

it('errors for invalid `custom``', () => {
expect(() => getMatrixForKind("custom", project)).toThrowError();
});
})


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

it('returns a matrix for `latest`', () => {
const result = getMatrixForKind("latest");
const result = getMatrixForKind("latest", project);

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

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

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

it('returns a matrix for `all`', () => {
const result = getMatrixForKind("all");
const result = getMatrixForKind("all", project);

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

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

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

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

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

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

expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});

it('errors for invalid `custom``', () => {
expect(() => getMatrixForKind("custom")).toThrowError();
expect(() => getMatrixForKind("custom", project)).toThrowError();
});
})
20 changes: 10 additions & 10 deletions supported-version/src/matrix/get-matrix-for-kind.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { getMatrixForVersions } from "./get-matrix-for-versions";

import latestJson from '../kind/latest.json';
import allVersions from '../versions/individual.json';
import nightly from '../kind/nightly.json';
import { getIndividualVersionsForProject } from "../versions/get-versions-for-project";
import latestJson from '../kind/special-versions/latest.json';
import nightlyJson from '../kind/special-versions/nightly.json';
import { amendMatrixForNext } from "../nightly/get-next-version";
import { getDayBefore } from '../nightly/get-day-before';
import { getCurrentlySupportedVersions } from "../kind/get-currently-supported";

export const getMatrixForKind = (kind: string, versions = "") => {
export const getMatrixForKind = (kind: string, project: string, versions = "") => {

switch(kind){
case 'latest':
return getMatrixForVersions(latestJson);
return getMatrixForVersions(project, latestJson[project]);
case 'currently-supported':
return getMatrixForVersions(getCurrentlySupportedVersions(new Date()));
return getMatrixForVersions(project, getCurrentlySupportedVersions(project, new Date()));
case 'nightly':
return amendMatrixForNext(getMatrixForVersions(nightly), 'https://upstream-mirror.mage-os.org', getDayBefore());
return amendMatrixForNext(getMatrixForVersions(project, nightlyJson[project]), 'https://upstream-mirror.mage-os.org', getDayBefore());
case 'all':
return getMatrixForVersions(Object.keys(allVersions));
return getMatrixForVersions(project, Object.keys(getIndividualVersionsForProject(project)));
case 'custom':
return getMatrixForVersions(versions.split(","))
return getMatrixForVersions(project, versions.split(","))
default:
throw new Error(`Unreachable kind: ${kind} discovered, please report to the maintainers.`);
}
Expand Down
19 changes: 10 additions & 9 deletions supported-version/src/matrix/get-matrix-for-versions.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { GithubActionsMatrix, MagentoMatrixVersion } from "./matrix-type";
import compositeVersionJson from '../versions/composite.json';
import individualVersionJson from '../versions/individual.json';

const knownVersions : Record<string, MagentoMatrixVersion> = {...individualVersionJson, ...compositeVersionJson };
import { GithubActionsMatrix, PackageMatrixVersion } from "./matrix-type";
import { getIndividualVersionsForProject, getCompositeVersionsForProject } from "../versions/get-versions-for-project";

/**
* Computes the Github Actions Matrix for given versions of Magento
* Computes the GitHub Actions Matrix for given versions of Magento
*/
export const getMatrixForVersions = (versions: string[]): GithubActionsMatrix => {
export const getMatrixForVersions = (project: string, versions: string[]): GithubActionsMatrix => {
const knownVersions : Record<string, PackageMatrixVersion> = {
...getIndividualVersionsForProject(project), ...getCompositeVersionsForProject(project)
}

return versions.reduce((acc, current): GithubActionsMatrix => {
if(knownVersions[current] === undefined){
throw new Error("Unknown version while computing matrix");
if (knownVersions[current] === undefined){
throw new Error(`Unknown "${current}" version while computing matrix`);
}

return {
Expand Down
4 changes: 2 additions & 2 deletions supported-version/src/matrix/matrix-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface MagentoMatrixVersion {
export interface PackageMatrixVersion {
magento: string,
php: string | number,
composer: string | number,
Expand All @@ -15,5 +15,5 @@ export interface MagentoMatrixVersion {

export interface GithubActionsMatrix {
magento: string[],
include: MagentoMatrixVersion[]
include: PackageMatrixVersion[]
}
10 changes: 7 additions & 3 deletions supported-version/src/nightly/get-next-version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { getNextVersion } from "./get-next-version"

describe('getNextVersion', () => {

it('should get the next nightly version for MageOS', () => {
expect(getNextVersion('https://upstream-mirror.mage-os.org', new Date('2022-09-29T17:47:00')), ).toEqual('@alpha');
it('should get the next nightly version for Magento Open Source', () => {
expect(getNextVersion('https://upstream-nightly.mage-os.org', new Date('2022-09-29T17:47:00')), ).toEqual('@alpha');
});

it('should get the next nightly version for Mage-OS', () => {
expect(getNextVersion('https://nightly.mage-os.org', new Date('2024-09-29T17:47:00')), ).toEqual('@alpha');
});

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