mirror of
https://github.com/icewind1991/nextcloud-version-matrix.git
synced 2026-06-03 09:34:12 +02:00
allow setting extra matrix fields
This commit is contained in:
parent
d2d332d004
commit
8238a96541
4 changed files with 105 additions and 8 deletions
|
|
@ -7,6 +7,10 @@ Get a version matrix of server versions to test the app against
|
|||
### `filename`
|
||||
**Optional** The path to the `info.xml` for the app, defaults to `appinfo/info.xml`.
|
||||
|
||||
### `matrix`
|
||||
|
||||
**Optional** Other fields to include in the output matrix, json encoded
|
||||
|
||||
## Outputs
|
||||
|
||||
### `matrix`
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@ inputs:
|
|||
filename:
|
||||
description: 'The path to the appinfo.xml'
|
||||
required: false
|
||||
default: 'appinfo/info.xml'
|
||||
matrix:
|
||||
description: 'Other fields to include in the output matrix, json encoded'
|
||||
required: false
|
||||
default: '{}'
|
||||
outputs:
|
||||
matrix:
|
||||
description: 'Test matrix with server branch and php version'
|
||||
|
|
|
|||
52
dist/index.js
vendored
52
dist/index.js
vendored
|
|
@ -38838,9 +38838,49 @@ function onlyUnique(value, index, array) {
|
|||
return array.indexOf(value) === index;
|
||||
}
|
||||
|
||||
function cartesianProduct(input) {
|
||||
const inputArray = [];
|
||||
for (let key of Object.keys(input)) {
|
||||
const item = {};
|
||||
item[key] = input[key];
|
||||
inputArray.push(item);
|
||||
}
|
||||
return cartesianProductInner(inputArray);
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/18959668
|
||||
function cartesianProductInner(input, current) {
|
||||
if (!input || !input.length) { return []; }
|
||||
|
||||
let head = input[0];
|
||||
let tail = input.slice(1);
|
||||
let output = [];
|
||||
|
||||
for (let key in head) {
|
||||
for (let i = 0; i < head[key].length; i++) {
|
||||
let newCurrent = copy(current);
|
||||
newCurrent[key] = head[key][i];
|
||||
if (tail.length) {
|
||||
let productOfTail =
|
||||
cartesianProductInner(tail, newCurrent);
|
||||
output = output.concat(productOfTail);
|
||||
} else output.push(newCurrent);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
function copy(obj) {
|
||||
let res = {};
|
||||
for (let p in obj) res[p] = obj[p];
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const filename = core.getInput('filename') || 'appinfo/info.xml';
|
||||
const matrixInput = JSON.parse(core.getInput('matrix') || '{}');
|
||||
|
||||
const content = fs.readFileSync(filename, 'utf8');
|
||||
const document = new DOMParser().parseFromString(content);
|
||||
|
|
@ -38863,10 +38903,14 @@ function onlyUnique(value, index, array) {
|
|||
// parseFloat will ignore patch versions, leaving us with all major and minor releases
|
||||
const possiblePhpVersions = (await getAllPhpVersions()).map(parseFloat).filter(onlyUnique);
|
||||
|
||||
const matrix = versionData.map(data => ({
|
||||
"php-versions": data.phpMin.toFixed(1),
|
||||
"server-versions": data.branch,
|
||||
}));
|
||||
const matrix = cartesianProduct({
|
||||
"server-versions": versionData.map(data => data.branch),
|
||||
...matrixInput
|
||||
});
|
||||
matrix.forEach(row => {
|
||||
const phpMax = versionData.find(data => data.branch === row["server-versions"]).phpMax;
|
||||
row["php-versions"] = phpMax.toFixed(1);
|
||||
});
|
||||
|
||||
core.setOutput("versions", JSON.stringify(versions));
|
||||
|
||||
|
|
|
|||
|
|
@ -50,9 +50,49 @@ function onlyUnique(value, index, array) {
|
|||
return array.indexOf(value) === index;
|
||||
}
|
||||
|
||||
function cartesianProduct(input) {
|
||||
const inputArray = [];
|
||||
for (let key of Object.keys(input)) {
|
||||
const item = {};
|
||||
item[key] = input[key];
|
||||
inputArray.push(item);
|
||||
}
|
||||
return cartesianProductInner(inputArray);
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/18959668
|
||||
function cartesianProductInner(input, current) {
|
||||
if (!input || !input.length) { return []; }
|
||||
|
||||
let head = input[0];
|
||||
let tail = input.slice(1);
|
||||
let output = [];
|
||||
|
||||
for (let key in head) {
|
||||
for (let i = 0; i < head[key].length; i++) {
|
||||
let newCurrent = copy(current);
|
||||
newCurrent[key] = head[key][i];
|
||||
if (tail.length) {
|
||||
let productOfTail =
|
||||
cartesianProductInner(tail, newCurrent);
|
||||
output = output.concat(productOfTail);
|
||||
} else output.push(newCurrent);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
function copy(obj) {
|
||||
let res = {};
|
||||
for (let p in obj) res[p] = obj[p];
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const filename = core.getInput('filename') || 'appinfo/info.xml';
|
||||
const matrixInput = JSON.parse(core.getInput('matrix') || '{}');
|
||||
|
||||
const content = fs.readFileSync(filename, 'utf8');
|
||||
const document = new DOMParser().parseFromString(content);
|
||||
|
|
@ -75,10 +115,14 @@ function onlyUnique(value, index, array) {
|
|||
// parseFloat will ignore patch versions, leaving us with all major and minor releases
|
||||
const possiblePhpVersions = (await getAllPhpVersions()).map(parseFloat).filter(onlyUnique);
|
||||
|
||||
const matrix = versionData.map(data => ({
|
||||
"php-versions": data.phpMin.toFixed(1),
|
||||
"server-versions": data.branch,
|
||||
}));
|
||||
const matrix = cartesianProduct({
|
||||
"server-versions": versionData.map(data => data.branch),
|
||||
...matrixInput
|
||||
});
|
||||
matrix.forEach(row => {
|
||||
const phpMax = versionData.find(data => data.branch === row["server-versions"]).phpMax;
|
||||
row["php-versions"] = phpMax.toFixed(1);
|
||||
});
|
||||
|
||||
core.setOutput("versions", JSON.stringify(versions));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue