mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-19 06:41:20 +00:00
feat(supported-version): add user-defined kind (#28)
`kind` is a new input property for the `supported-version` action which allows one to define what specific versions of Magento they support. Currently, `kind` supports `latest`, `currently-supported`, and `custom`. See the README for `supported-version` if you want more specifics
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { getMatrixForKind } from "./get-matrix-for-kind";
|
||||
|
||||
describe('getMatrixForKind', () => {
|
||||
it('returns a matrix for `latest`', () => {
|
||||
const result = getMatrixForKind("latest");
|
||||
|
||||
expect(result.magento).toBeDefined();
|
||||
expect(result.include).toBeDefined();
|
||||
});
|
||||
|
||||
it('returns a matrix for `currently-supported`', () => {
|
||||
const result = getMatrixForKind("currently-supported");
|
||||
|
||||
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");
|
||||
|
||||
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");
|
||||
|
||||
expect(result.magento).toBeDefined();
|
||||
expect(result.include).toBeDefined();
|
||||
});
|
||||
|
||||
it('errors for invalid `custom``', () => {
|
||||
expect(() => getMatrixForKind("custom")).toThrowError();
|
||||
});
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
import { getMatrixForVersions } from "./get-matrix-for-versions";
|
||||
|
||||
import latestJson from '../kind/latest.json';
|
||||
import currentlySupportedJson from '../kind/currently-supported.json';
|
||||
|
||||
export const getMatrixForKind = (kind: string, versions: string = "") => {
|
||||
switch(kind){
|
||||
case 'latest':
|
||||
return getMatrixForVersions(latestJson);
|
||||
case 'currently-supported':
|
||||
return getMatrixForVersions(currentlySupportedJson);
|
||||
case 'custom':
|
||||
return getMatrixForVersions(versions.split(","))
|
||||
default:
|
||||
throw new Error(`Unreachable kind: ${kind} discovered, please report to the maintainers.`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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 };
|
||||
|
||||
/**
|
||||
* Computes the Github Actions Matrix for given versions of Magento
|
||||
*/
|
||||
export const getMatrixForVersions = (versions: string[]): GithubActionsMatrix => {
|
||||
return versions.reduce((acc, current): GithubActionsMatrix => {
|
||||
if(knownVersions[current] === undefined){
|
||||
throw new Error("Unknown version while computing matrix");
|
||||
}
|
||||
|
||||
return {
|
||||
magento: [...acc.magento, current],
|
||||
include: [...acc.include, knownVersions[current]]
|
||||
}
|
||||
}, {magento: [], include: []});
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
export interface MagentoMatrixVersion {
|
||||
magento: string,
|
||||
php: string | number,
|
||||
composer: string | number,
|
||||
mysql: string,
|
||||
elasticsearch: string,
|
||||
rabbitmq: string,
|
||||
redis: string,
|
||||
varnish: string,
|
||||
nginx: string,
|
||||
os: string
|
||||
}
|
||||
|
||||
export interface GithubActionsMatrix {
|
||||
magento: string[],
|
||||
include: MagentoMatrixVersion[]
|
||||
}
|
||||
Reference in New Issue
Block a user