mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-13 13:14:53 +00:00
feat: allow using "next" version on supported version (#58)
This also allows using the action in https://github.com/mage-os/generate-mirror-repo-js where the test module is an external package installed with composer. In this case, no local path repo configuration is needed. Co-authored-by: Vinai Kopp <Vinai@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,7 @@ export const KNOWN_KINDS = {
|
||||
'currently-supported': true,
|
||||
'latest': true,
|
||||
'custom': true,
|
||||
'nightly': true,
|
||||
'all': true,
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"magento/project-community-edition:next"
|
||||
]
|
||||
@@ -29,6 +29,13 @@ describe('getMatrixForKind', () => {
|
||||
expect(result.include).toBeDefined();
|
||||
});
|
||||
|
||||
it('returns a matrix for the next release when using `nightly`', () => {
|
||||
const result = getMatrixForKind("nightly", "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");
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ import { getMatrixForVersions } from "./get-matrix-for-versions";
|
||||
import latestJson from '../kind/latest.json';
|
||||
import currentlySupportedJson from '../kind/currently-supported.json';
|
||||
import allVersions from '../versions/individual.json';
|
||||
import nightly from '../kind/nightly.json';
|
||||
import { amendMatrixForNext } from "../nightly/get-next-version";
|
||||
import { getDayBefore } from '../nightly/get-day-before';
|
||||
|
||||
export const getMatrixForKind = (kind: string, versions: string = "") => {
|
||||
switch(kind){
|
||||
@@ -10,6 +13,8 @@ export const getMatrixForKind = (kind: string, versions: string = "") => {
|
||||
return getMatrixForVersions(latestJson);
|
||||
case 'currently-supported':
|
||||
return getMatrixForVersions(currentlySupportedJson);
|
||||
case 'nightly':
|
||||
return amendMatrixForNext(getMatrixForVersions(nightly), 'https://upstream-mirror.mage-os.org', getDayBefore());
|
||||
case 'all':
|
||||
return getMatrixForVersions(Object.keys(allVersions));
|
||||
case 'custom':
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Gets the date one day before the date.
|
||||
*/
|
||||
export const getDayBefore = (date: Date = new Date()) => {
|
||||
const yesterday = new Date(date);
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
return yesterday;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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 handle the first of the month correctly', () => {
|
||||
expect(getNextVersion('https://upstream-mirror.mage-os.org', new Date('2022-01-01T17:47:00')), ).toEqual('@alpha');
|
||||
});
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
import { GithubActionsMatrix } from "../matrix/matrix-type";
|
||||
|
||||
export type Repository = "https://upstream-mirror.mage-os.org" | "https://repo.magento.com";
|
||||
|
||||
/**
|
||||
* 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";
|
||||
|
||||
/**
|
||||
* 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":
|
||||
// See: https://github.com/mage-os/generate-mirror-repo-js/blob/bbbdf1708ea0bf8fc845aad8240d00f37632b4a7/src/release-branch-build-tools.js#L71
|
||||
return "@alpha";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const replaceNextPlaceHolderWithVersion = (packageName: string, nextVersion: string) => {
|
||||
return packageName.replace(/(?!:)next$/, nextVersion);
|
||||
}
|
||||
|
||||
export const computeNextPackage = (packageName: string, repository: Repository, date: Date): string => {
|
||||
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);
|
||||
matrix.include = matrix.include.map((item) => {
|
||||
return item.magento === nextVersionPlaceHolder
|
||||
? {
|
||||
...item,
|
||||
magento: computeNextPackage(nextVersionPlaceHolder, repository, date),
|
||||
}
|
||||
: item;
|
||||
});
|
||||
return matrix;
|
||||
}
|
||||
@@ -94,5 +94,17 @@
|
||||
"varnish": "varnish:7.0",
|
||||
"nginx": "nginx:1.18",
|
||||
"os": "ubuntu-latest"
|
||||
},
|
||||
"magento/project-community-edition:next": {
|
||||
"magento": "magento/project-community-edition:next",
|
||||
"php": 8.1,
|
||||
"composer": 2,
|
||||
"mysql": "mysql:8.0",
|
||||
"elasticsearch": "elasticsearch:7.17.5",
|
||||
"rabbitmq": "rabbitmq:3.9",
|
||||
"redis": "redis:6.2",
|
||||
"varnish": "varnish:7.0",
|
||||
"nginx": "nginx:1.18",
|
||||
"os": "ubuntu-latest"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user