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,19 +1,28 @@
import { GithubActionsMatrix } from "../matrix/matrix-type";
export type Repository = "https://upstream-mirror.mage-os.org" | "https://repo.magento.com";
const KNOWN_REPOSITORIES = {
"https://repo.mage-os.org": true,
"https://nightly.mage-os.org": true,
"https://upstream-mirror.mage-os.org": true,
"https://upstream-nightly.mage-os.org": true,
"https://repo.magento.com": true,
}
export type Repository = keyof typeof KNOWN_REPOSITORIES;
/**
* A placeholder value use to refer to the next version of Magento.
* This value is just a placeholder, there is no "next" version (as of authoring).
*/
export const nextVersionPlaceHolder = "magento/project-community-edition:next";
export const nextVersionPlaceHolder = "project-community-edition:next";
/**
* Get the next version of Magento, as determined by the repository.
*/
export const getNextVersion = (repository: Repository, date: Date) => {
switch(repository){
case "https://upstream-mirror.mage-os.org":
case "https://nightly.mage-os.org":
case "https://upstream-nightly.mage-os.org":
// See: https://github.com/mage-os/generate-mirror-repo-js/blob/bbbdf1708ea0bf8fc845aad8240d00f37632b4a7/src/release-branch-build-tools.js#L71
return "@alpha";
default:
@@ -30,13 +39,14 @@ export const computeNextPackage = (packageName: string, repository: Repository,
return replaceNextPlaceHolderWithVersion(packageName, getNextVersion(repository, date));
}
export const amendMatrixForNext = (matrix: GithubActionsMatrix, repository: Repository = "https://upstream-mirror.mage-os.org", date: Date = new Date()): GithubActionsMatrix => {
matrix.magento = matrix.magento.map((item) => item === nextVersionPlaceHolder ? computeNextPackage(nextVersionPlaceHolder, repository, date) : item);
export const amendMatrixForNext = (matrix: GithubActionsMatrix, repository: Repository, date: Date = new Date()): GithubActionsMatrix => {
const nextVersionRegExp = new RegExp(nextVersionPlaceHolder + '$');
matrix.magento = matrix.magento.map((item) => item.match(nextVersionRegExp) ? computeNextPackage(item, repository, date) : item);
matrix.include = matrix.include.map((item) => {
return item.magento === nextVersionPlaceHolder
return item.magento.match(nextVersionRegExp)
? {
...item,
magento: computeNextPackage(nextVersionPlaceHolder, repository, date),
magento: computeNextPackage(item.magento, repository, date),
}
: item;
});