Skip to content

feat: allow using "next" version on supported version #58

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 12 commits into from
Oct 11, 2022
8 changes: 7 additions & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
on:
workflow_call:
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:
type: string
required: false
Expand Down Expand Up @@ -130,6 +135,7 @@ jobs:
name: Add Github Repo for Testing
working-directory: ${{ inputs.magento_directory }}
shell: bash
if: ${{ inputs.use_local_source == true }}

- run: composer require monolog/monolog:"<2.7.0" --no-update
name: Fixup Monolog (https://github.com/magento/magento2/pull/35596)
Expand Down
6 changes: 6 additions & 0 deletions installation-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ inputs:
default: "2"
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:
required: true
default: $GITHUB_WORKSPACE
Expand Down Expand Up @@ -86,6 +91,7 @@ runs:
name: Add Github Repo for Testing
working-directory: ${{ inputs.magento_directory }}
shell: bash
if: ${{ inputs.use_local_source == 'true' }}

- run: |
composer config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion supported-version/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ See the [action.yml](./action.yml)

| 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 | '' |

## 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

```yml
Expand Down
2 changes: 1 addition & 1 deletion supported-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: "A Github Action that computes the Github Actions matrix for the ch
inputs:
kind:
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"
custom_versions:
required: false
Expand Down
10 changes: 5 additions & 5 deletions supported-version/dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions supported-version/src/kind/compute-kind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const KNOWN_KINDS = {
'currently-supported': true,
'latest': true,
'custom': true,
'nightly': true,
'all': true,
}

Expand Down
3 changes: 3 additions & 0 deletions supported-version/src/kind/nightly.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"magento/project-community-edition:next"
]
7 changes: 7 additions & 0 deletions supported-version/src/matrix/get-matrix-for-kind.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
5 changes: 5 additions & 0 deletions supported-version/src/matrix/get-matrix-for-kind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ 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){
case 'latest':
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':
Expand Down
8 changes: 8 additions & 0 deletions supported-version/src/nightly/get-day-before.ts
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 12 additions & 0 deletions supported-version/src/nightly/get-next-version.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
})
44 changes: 44 additions & 0 deletions supported-version/src/nightly/get-next-version.ts
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 12 additions & 0 deletions supported-version/src/versions/composite.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}