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
@@ -0,0 +1,9 @@
/**
* Acceptable arguments for version `project`
*/
export const KNOWN_PROJECTS = {
"mage-os": true,
"magento-open-source": true,
}
export type Project = keyof typeof KNOWN_PROJECTS;
@@ -0,0 +1,12 @@
import { validateProject } from "./validate-projects";
describe('validateProject', () => {
it('returns `true` if its a valid project', () => {
expect(validateProject("magento-open-source")).toBe(true);
expect(validateProject("mage-os")).toBe(true);
});
it('throws a helpful exception if it is an invalid project', () => {
expect(() => validateProject(<any>"quark")).toThrowError();
})
})
@@ -0,0 +1,6 @@
import { isKnownProject } from './validations/is-known-project';
import { ProjectValidator } from "./validator";
export const validateProject: ProjectValidator = (project): boolean => {
return isKnownProject(project)
}
@@ -0,0 +1,13 @@
import {isKnownProject} from "./is-known-project";
import {Project} from "../projects";
describe('isKnownProject', () => {
it('returns `true` for known projects', () => {
expect(isKnownProject("mage-os")).toBe(true)
expect(isKnownProject("magento-open-source")).toBe(true)
});
it('throws a message if for unknown projects', () => {
expect(() => isKnownProject(<Project>"bingo")).toThrowError()
});
})
@@ -0,0 +1,11 @@
import { KNOWN_PROJECTS, Project } from '../projects';
export const isKnownProject = (project: Project): boolean => {
if (!(project in KNOWN_PROJECTS)) {
throw new Error(
`Invalid project provided, supported projects are: ${Object.keys(KNOWN_PROJECTS).join(', ')}`
)
}
return true;
}
@@ -0,0 +1,3 @@
import { Project } from "./projects";
export type ProjectValidator = (project: Project) => boolean;