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
This commit is contained in:
Vinai Kopp
2023-09-06 22:08:57 +02:00
committed by GitHub
parent 28643a7156
commit f7f0504691
27 changed files with 331 additions and 67 deletions
@@ -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");
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, "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", "magento/project-community-edition:next");
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", 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, "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", 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();
});
})
@@ -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.`);
}
@@ -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 {
+2 -2
View File
@@ -1,4 +1,4 @@
export interface MagentoMatrixVersion {
export interface PackageMatrixVersion {
magento: string,
php: string | number,
composer: string | number,
@@ -15,5 +15,5 @@ export interface MagentoMatrixVersion {
export interface GithubActionsMatrix {
magento: string[],
include: MagentoMatrixVersion[]
include: PackageMatrixVersion[]
}