feat(supported-version): add user-defined kind (#28)

`kind` is a new input property for the `supported-version` action which
allows one to define what specific versions of Magento they support.

Currently, `kind` supports `latest`, `currently-supported`, and `custom`. See the
README for `supported-version` if you want more specifics
This commit is contained in:
Damien Retzinger
2022-08-05 17:36:38 -04:00
committed by GitHub
parent 97b4223c0c
commit 664360ede2
22 changed files with 7289 additions and 115 deletions
@@ -0,0 +1,29 @@
name: Test Actions
on:
push:
branches:
- main
paths:
- ".github/workflows/_internal-supported-version.yaml"
- "supported-version/**"
- "!(**/*.md)"
pull_request:
branches:
- main
paths:
- ".github/workflows/_internal-supported-version.yaml"
- "supported-version/**"
- "!(**/*.md)"
jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci
shell: bash
- run: npm test
shell: bash
+1
View File
@@ -0,0 +1 @@
node_modules/
+6784
View File
File diff suppressed because it is too large Load Diff
+30
View File
@@ -0,0 +1,30 @@
{
"name": "@graycore/github-actions-magento",
"version": "1.0.0",
"description": "Github Actions for Magento 2",
"scripts": {
"test": "cd supported-version && npm run test && cd -"
},
"private": true,
"repository": {
"type": "git",
"url": "git+https://github.com/graycoreio/github-actions-magento2.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/graycoreio/github-actions-magento2/issues"
},
"homepage": "https://github.com/graycoreio/github-actions-magento2#readme",
"dependencies": {
"@actions/core": "^1.9.0"
},
"devDependencies": {
"@types/jest": "^28.1.6",
"@types/node": "^18.6.4",
"esbuild": "^0.14.53",
"jest": "^28.1.3",
"ts-jest": "^28.0.7",
"typescript": "^4.7.4"
}
}
+9 -10
View File
@@ -7,6 +7,15 @@ All data comes from:
- [v2.3](https://github.com/magento/devdocs/blob/master/src/_data/codebase/v2_3/system-requirements.yml) - [v2.3](https://github.com/magento/devdocs/blob/master/src/_data/codebase/v2_3/system-requirements.yml)
- [v2.4](https://github.com/magento/devdocs/blob/master/src/_data/codebase/v2_4/system-requirements.yml) - [v2.4](https://github.com/magento/devdocs/blob/master/src/_data/codebase/v2_4/system-requirements.yml)
## Inputs
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` and `custom` | 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 | '' |
## Usage ## Usage
```yml ```yml
@@ -30,14 +39,4 @@ jobs:
- uses: graycoreio/github-actions-magento2/supported-version@main - uses: graycoreio/github-actions-magento2/supported-version@main
id: supported-version id: supported-version
- run: echo ${{ steps.supported-version.outputs.matrix }} - run: echo ${{ steps.supported-version.outputs.matrix }}
install-test:
needs: compute_matrix
strategy:
matrix: ${{ fromJSON(needs.compute_matrix.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: echo ${{ matrix.magento }} ${{ matrix.os }} ${{ matrix.php }}
shell: bash
``` ```
+14 -9
View File
@@ -1,6 +1,16 @@
name: "Compute Supported Magento 2 Versions" name: "Compute Supported Magento 2 Versions"
author: "Graycore" author: "Graycore"
description: "A Github Action that computes the Github Actions matrix for the currently supported versions of Magento 2" description: "A Github Action that computes the Github Actions matrix for the chosen versions of Magento 2"
inputs:
kind:
required: false
description: "The kind of versions you want to return. Allowed values are `currently-supported, latest, custom`"
default: "currently-supported"
custom_versions:
required: false
description: "The specific custom versions of Magento that you want to use. Only applies when `kind` is `custom`"
default: ""
outputs: outputs:
matrix: matrix:
@@ -8,14 +18,9 @@ outputs:
value: ${{ steps.generate.outputs.matrix }} value: ${{ steps.generate.outputs.matrix }}
runs: runs:
using: 'composite' using: "node16"
steps: main: dist/index.js
- run: |
content=`cat ${{ github.action_path }}/supported.json | jq -c`
echo "::set-output name=matrix::$content"
shell: bash
id: generate
branding: branding:
icon: "code" icon: "code"
color: "green" color: "green"
File diff suppressed because one or more lines are too long
+9
View File
@@ -0,0 +1,9 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testMatch: ['**/*.spec.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}
+13
View File
@@ -0,0 +1,13 @@
{
"name": "@graycore/github-actions-magento2-supported-version",
"version": "1.0.0",
"description": "A Github Action that computes the currently supported Github Actions Matrix for Magento 2 Versions",
"main": "index.js",
"private": true,
"scripts": {
"build": "esbuild --outfile=dist/index.js --platform=node --bundle --minify src/index.ts",
"test": "jest"
},
"author": "",
"license": "MIT"
}
+20
View File
@@ -0,0 +1,20 @@
import * as core from '@actions/core';
import { validateOrError } from './kind/compute-kind';
import { getMatrixForKind } from './matrix/get-matrix-for-kind';
export async function run(): Promise<void> {
try {
const kind = core.getInput("kind");
validateOrError(kind);
const customVersions = core.getInput("custom_versions");
core.setOutput('matrix', getMatrixForKind(kind, customVersions));
}
catch (error) {
core.setFailed(error.message);
}
}
run()
@@ -0,0 +1,11 @@
import { isValidKind } from "./compute-kind";
describe('isValidKind', () => {
it('returns `true` if its a valid kind', () => {
expect(isValidKind("latest")).toBe(true);
});
it('returns `false` if it is not a valid kind', () => {
expect(isValidKind("taco")).toBe(false);
})
})
@@ -0,0 +1,21 @@
/**
* Acceptable arguments for version `kind`
*/
export const KNOWN_KINDS = {
'currently-supported': true,
'latest': true,
'custom': true,
}
export const isValidKind = (kind: string): boolean => {
return kind in KNOWN_KINDS;
};
export const validateOrError = (kind: string): true => {
if(isValidKind(kind)){
return true;
}
else {
throw new Error(`Invalid kind provided, supported kinds are: ${Object.keys(KNOWN_KINDS).join(', ')}`);
}
}
@@ -0,0 +1,9 @@
[
"magento/project-community-edition:>=2.3 <2.4",
"magento/project-community-edition:>=2.4.0 <2.4.1",
"magento/project-community-edition:>=2.4.1 <2.4.2",
"magento/project-community-edition:>=2.4.2 <2.4.3",
"magento/project-community-edition:>=2.4.3 <2.4.4",
"magento/project-community-edition:>=2.4.4 <2.4.5",
"magento/project-community-edition"
]
+3
View File
@@ -0,0 +1,3 @@
[
"magento/project-community-edition"
]
@@ -0,0 +1,35 @@
import { getMatrixForKind } from "./get-matrix-for-kind";
describe('getMatrixForKind', () => {
it('returns a matrix for `latest`', () => {
const result = getMatrixForKind("latest");
expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});
it('returns a matrix for `currently-supported`', () => {
const result = getMatrixForKind("currently-supported");
expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});
it('returns a matrix for valid `custom`', () => {
const result = getMatrixForKind("custom", "magento/project-community-edition:2.3.7-p3");
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");
expect(result.magento).toBeDefined();
expect(result.include).toBeDefined();
});
it('errors for invalid `custom``', () => {
expect(() => getMatrixForKind("custom")).toThrowError();
});
})
@@ -0,0 +1,17 @@
import { getMatrixForVersions } from "./get-matrix-for-versions";
import latestJson from '../kind/latest.json';
import currentlySupportedJson from '../kind/currently-supported.json';
export const getMatrixForKind = (kind: string, versions: string = "") => {
switch(kind){
case 'latest':
return getMatrixForVersions(latestJson);
case 'currently-supported':
return getMatrixForVersions(currentlySupportedJson);
case 'custom':
return getMatrixForVersions(versions.split(","))
default:
throw new Error(`Unreachable kind: ${kind} discovered, please report to the maintainers.`);
}
}
@@ -0,0 +1,21 @@
import { GithubActionsMatrix, MagentoMatrixVersion } from "./matrix-type";
import compositeVersionJson from '../versions/composite.json';
import individualVersionJson from '../versions/individual.json';
const knownVersions : Record<string, MagentoMatrixVersion> = {...individualVersionJson, ...compositeVersionJson };
/**
* Computes the Github Actions Matrix for given versions of Magento
*/
export const getMatrixForVersions = (versions: string[]): GithubActionsMatrix => {
return versions.reduce((acc, current): GithubActionsMatrix => {
if(knownVersions[current] === undefined){
throw new Error("Unknown version while computing matrix");
}
return {
magento: [...acc.magento, current],
include: [...acc.include, knownVersions[current]]
}
}, {magento: [], include: []});
}
@@ -0,0 +1,17 @@
export interface MagentoMatrixVersion {
magento: string,
php: string | number,
composer: string | number,
mysql: string,
elasticsearch: string,
rabbitmq: string,
redis: string,
varnish: string,
nginx: string,
os: string
}
export interface GithubActionsMatrix {
magento: string[],
include: MagentoMatrixVersion[]
}
@@ -0,0 +1,86 @@
{
"magento/project-community-edition:>=2.3 <2.4": {
"magento": "magento/project-community-edition:>=2.3 <2.4",
"php": 7.4,
"composer": 1,
"mysql": "mysql:5.7",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-18.04"
},
"magento/project-community-edition:>=2.4.0 <2.4.1": {
"magento": "magento/project-community-edition:>=2.4.0 <2.4.1",
"php": 7.4,
"composer": 1,
"mysql": "mysql:5.7",
"elasticsearch": "elasticsearch:7.6.2",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:5.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:>=2.4.1 <2.4.2": {
"magento": "magento/project-community-edition:>=2.4.1 <2.4.2",
"php": 7.4,
"composer": 1,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.7.1",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:5.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:>=2.4.2 <2.4.3": {
"magento": "magento/project-community-edition:>=2.4.2 <2.4.3",
"php": 7.4,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.9.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:>=2.4.3 <2.4.4": {
"magento": "magento/project-community-edition:>=2.4.3 <2.4.4",
"php": 7.4,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:>=2.4.4 <2.4.5": {
"magento": "magento/project-community-edition:>=2.4.4 <2.4.5",
"php": 8.1,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.9",
"redis": "redis:6.2",
"varnish": "varnish:7.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition": {
"magento": "magento/project-community-edition",
"php": 8.1,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.9",
"redis": "redis:6.2",
"varnish": "varnish:7.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
}
}
@@ -0,0 +1,146 @@
{
"magento/project-community-edition:2.3.7-p3": {
"magento": "magento/project-community-edition:2.3.7-p3",
"php": 7.4,
"composer": 1,
"mysql": "mysql:5.7",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-18.04"
},
"magento/project-community-edition:2.4.0": {
"magento": "magento/project-community-edition:2.4.0",
"php": 7.4,
"composer": 1,
"mysql": "mysql:5.7",
"elasticsearch": "elasticsearch:7.6.2",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:5.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:2.4.0-p1": {
"magento": "magento/project-community-edition:2.4.0-p1",
"php": 7.4,
"composer": 1,
"mysql": "mysql:5.7",
"elasticsearch": "elasticsearch:7.6.2",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:5.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:2.4.1": {
"magento": "magento/project-community-edition:2.4.1",
"php": 7.4,
"composer": 1,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.7.1",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:5.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:2.4.1-p1": {
"magento": "magento/project-community-edition:2.4.1-p1",
"php": 7.4,
"composer": 1,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.7.1",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:5.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:2.4.2": {
"magento": "magento/project-community-edition:2.4.2",
"php": 7.4,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.9.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:2.4.2-p1": {
"magento": "magento/project-community-edition:2.4.2-p1",
"php": 7.4,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.9.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:2.4.2-p2": {
"magento": "magento/project-community-edition:2.4.2-p2",
"php": 7.4,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.9.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:2.4.3": {
"magento": "magento/project-community-edition:2.4.3",
"php": 7.4,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:2.4.3-p1": {
"magento": "magento/project-community-edition:2.4.3-p1",
"php": 7.4,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:2.4.3-p2": {
"magento": "magento/project-community-edition:2.4.3-p2",
"php": 7.4,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
"magento/project-community-edition:2.4.4": {
"magento": "magento/project-community-edition:2.4.4",
"php": 8.1,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.9",
"redis": "redis:6.2",
"varnish": "varnish:7.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
}
}
-96
View File
@@ -1,96 +0,0 @@
{
"magento": [
"magento/project-community-edition:>=2.3 <2.4",
"magento/project-community-edition:>=2.4.0 <2.4.1",
"magento/project-community-edition:>=2.4.1 <2.4.2",
"magento/project-community-edition:>=2.4.2 <2.4.3",
"magento/project-community-edition:>=2.4.3 <2.4.4",
"magento/project-community-edition:>=2.4.4 <2.4.5",
"magento/project-community-edition"
],
"include": [
{
"magento": "magento/project-community-edition:>=2.3 <2.4",
"php": 7.4,
"composer": 1,
"mysql": "mysql:5.7",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-18.04"
},
{
"magento": "magento/project-community-edition:>=2.4.0 <2.4.1",
"php": 7.4,
"composer": 1,
"mysql": "mysql:5.7",
"elasticsearch": "elasticsearch:7.6.2",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:5.0",
"varnish": "varnish:6.0",
"os": "ubuntu-latest"
},
{
"magento": "magento/project-community-edition:>=2.4.1 <2.4.2",
"php": 7.4,
"composer": 1,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.7.1",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:5.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
{
"magento": "magento/project-community-edition:>=2.4.2 <2.4.3",
"php": 7.4,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.9.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
{
"magento": "magento/project-community-edition:>=2.4.3 <2.4.4",
"php": 7.4,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.8",
"redis": "redis:6.0",
"varnish": "varnish:6.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
{
"magento": "magento/project-community-edition:>=2.4.4 <2.4.5",
"php": 8.1,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.9",
"redis": "redis:6.2",
"varnish": "varnish:7.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
},
{
"magento": "magento/project-community-edition",
"php": 8.1,
"composer": 2,
"mysql": "mysql:8.0",
"elasticsearch": "elasticsearch:7.16.3",
"rabbitmq": "rabbitmq:3.9",
"redis": "redis:6.2",
"varnish": "varnish:7.0",
"nginx": "nginx:1.18",
"os": "ubuntu-latest"
}
]
}
+6
View File
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true,
}
}