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:
Damien Retzinger
2022-10-11 16:19:49 -04:00
committed by GitHub
parent 3e4d3c1645
commit 7431dcb7af
14 changed files with 119 additions and 10 deletions
+7 -1
View File
@@ -1,7 +1,12 @@
on: on:
workflow_call: workflow_call:
inputs: inputs:
use_local_source:
type: boolean
required: false
default: true
description: "Whether or not you want to test your local package or not."
source_folder: source_folder:
type: string type: string
required: false required: false
@@ -130,6 +135,7 @@ jobs:
name: Add Github Repo for Testing name: Add Github Repo for Testing
working-directory: ${{ inputs.magento_directory }} working-directory: ${{ inputs.magento_directory }}
shell: bash shell: bash
if: ${{ inputs.use_local_source == true }}
- run: composer require monolog/monolog:"<2.7.0" --no-update - run: composer require monolog/monolog:"<2.7.0" --no-update
name: Fixup Monolog (https://github.com/magento/magento2/pull/35596) name: Fixup Monolog (https://github.com/magento/magento2/pull/35596)
+6
View File
@@ -18,6 +18,11 @@ inputs:
default: "2" default: "2"
description: "The version of composer to use" description: "The version of composer to use"
use_local_source:
required: false
default: "true"
description: "Whether or not you want to test your local package or not."
source_folder: source_folder:
required: true required: true
default: $GITHUB_WORKSPACE default: $GITHUB_WORKSPACE
@@ -86,6 +91,7 @@ runs:
name: Add Github Repo for Testing name: Add Github Repo for Testing
working-directory: ${{ inputs.magento_directory }} working-directory: ${{ inputs.magento_directory }}
shell: bash shell: bash
if: ${{ inputs.use_local_source == 'true' }}
- run: | - run: |
composer config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true composer config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
+1 -2
View File
@@ -8062,8 +8062,7 @@
"version": "1.2.2", "version": "1.2.2",
"resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.2.tgz", "resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.2.tgz",
"integrity": "sha512-olV41bKSMm8BdnuMsewT4jqlZ8+3TCARAXjZGT9jcoSnrfUnRCqnMoF9XEeoWjbzObpqF9dRhHQj0Xb9QdF6/w==", "integrity": "sha512-olV41bKSMm8BdnuMsewT4jqlZ8+3TCARAXjZGT9jcoSnrfUnRCqnMoF9XEeoWjbzObpqF9dRhHQj0Xb9QdF6/w==",
"dev": true, "dev": true
"requires": {}
}, },
"jest-regex-util": { "jest-regex-util": {
"version": "28.0.2", "version": "28.0.2",
+7 -1
View File
@@ -13,9 +13,15 @@ See the [action.yml](./action.yml)
| Input | Description | Required | Default | | Input | Description | Required | Default |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ----------- | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ----------- |
| kind | The "kind" of support you're targeting for your package. Allowed values are `currently-supported`, `latest`, `custom`, and `all` | false | 'currently-supported' | | kind | The "kind" of support you're targeting for your package. Allowed values are `currently-supported`, `latest`, `custom`, `nightly` and `all` | false | 'currently-supported' |
| custom_versions | The versions you want to support, as a comma-separated string, i.e. 'magento/project-community-edition:2.3.7-p3, magento/project-community-edition:2.4.2-p2' | false | '' | | custom_versions | The versions you want to support, as a comma-separated string, i.e. 'magento/project-community-edition:2.3.7-p3, magento/project-community-edition:2.4.2-p2' | false | '' |
## Kinds
- `currently-supported` - The currently supported Magento Open Source versions by Adobe.
- `latest` - The latest version of Magento only.
- `custom` - A custom subset of the versions, as specified by you. Requires `custom_versions` sibling key.
- `nightly` - The nightly version of Magento (only available via `https://upstream-nightly.mage-os.org`)
- `all` - All versions of Magento (including patched/unpatched versions).
## Usage ## Usage
```yml ```yml
+1 -1
View File
@@ -5,7 +5,7 @@ description: "A Github Action that computes the Github Actions matrix for the ch
inputs: inputs:
kind: kind:
required: false required: false
description: "The kind of versions you want to return. Allowed values are `currently-supported, latest, custom, all`" description: "The kind of versions you want to return. Allowed values are `currently-supported`, `latest`, `custom`, `nightly` and `all`"
default: "currently-supported" default: "currently-supported"
custom_versions: custom_versions:
required: false required: false
+5 -5
View File
File diff suppressed because one or more lines are too long
@@ -5,6 +5,7 @@ export const KNOWN_KINDS = {
'currently-supported': true, 'currently-supported': true,
'latest': true, 'latest': true,
'custom': true, 'custom': true,
'nightly': true,
'all': true, 'all': true,
} }
+3
View File
@@ -0,0 +1,3 @@
[
"magento/project-community-edition:next"
]
@@ -29,6 +29,13 @@ describe('getMatrixForKind', () => {
expect(result.include).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");
expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});
it('returns a matrix for valid multiple `custom`', () => { 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", "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 latestJson from '../kind/latest.json';
import currentlySupportedJson from '../kind/currently-supported.json'; import currentlySupportedJson from '../kind/currently-supported.json';
import allVersions from '../versions/individual.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 = "") => { export const getMatrixForKind = (kind: string, versions: string = "") => {
switch(kind){ switch(kind){
@@ -10,6 +13,8 @@ export const getMatrixForKind = (kind: string, versions: string = "") => {
return getMatrixForVersions(latestJson); return getMatrixForVersions(latestJson);
case 'currently-supported': case 'currently-supported':
return getMatrixForVersions(currentlySupportedJson); return getMatrixForVersions(currentlySupportedJson);
case 'nightly':
return amendMatrixForNext(getMatrixForVersions(nightly), 'https://upstream-mirror.mage-os.org', getDayBefore());
case 'all': case 'all':
return getMatrixForVersions(Object.keys(allVersions)); return getMatrixForVersions(Object.keys(allVersions));
case 'custom': 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", "varnish": "varnish:7.0",
"nginx": "nginx:1.18", "nginx": "nginx:1.18",
"os": "ubuntu-latest" "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"
} }
} }