mirror of
https://github.com/icewind1991/nextcloud-version-matrix.git
synced 2026-06-04 01:54:09 +02:00
also get supported php versions
This commit is contained in:
parent
d43cc64aae
commit
a82a7d40fd
7 changed files with 82 additions and 15 deletions
|
|
@ -3,15 +3,39 @@ const xpath = require('xpath');
|
|||
const DOMParser = require('xmldom').DOMParser;
|
||||
const fs = require('fs');
|
||||
const urlExist = require('url-exist');
|
||||
const {HttpClient} = require('@actions/http-client');
|
||||
|
||||
const client = new HttpClient('nextcloud-version-matrix')
|
||||
|
||||
function versionHashBranch(version) {
|
||||
return urlExist(`https://github.com/nextcloud/server/tree/stable${version}`);
|
||||
}
|
||||
|
||||
async function getBranch(version) {
|
||||
if (await versionHashBranch(version)) {
|
||||
return `stable${version}`;
|
||||
} else {
|
||||
return "master";
|
||||
}
|
||||
}
|
||||
|
||||
function range(from, to) {
|
||||
return [...Array(to - from + 1).keys()].map(i => i + from);
|
||||
}
|
||||
|
||||
async function getSupportedVersions(branch) {
|
||||
let res = await client.get(`https://raw.githubusercontent.com/nextcloud/server/${branch}/lib/versioncheck.php`);
|
||||
let versionCheckCode = await res.readBody();
|
||||
let min = parseVersionId(versionCheckCode.match(/PHP_VERSION_ID < (\d+)/)[1]);
|
||||
let max = parseVersionId(versionCheckCode.match(/PHP_VERSION_ID >= (\d+)/)[1]);
|
||||
return {min: min, max: max};
|
||||
}
|
||||
|
||||
function parseVersionId(raw) {
|
||||
let matches = raw.match(/^(\d\d)(\d)/)
|
||||
return parseInt(matches[1], 10) / 10 + parseInt(matches[2], 10) / 10
|
||||
}
|
||||
|
||||
function onlyUnique(value, index, array) {
|
||||
return array.indexOf(value) === index;
|
||||
}
|
||||
|
|
@ -28,17 +52,24 @@ function onlyUnique(value, index, array) {
|
|||
console.log(`App supports from ${minVersion} till ${maxVersion}`);
|
||||
|
||||
const versions = range(minVersion, maxVersion);
|
||||
core.setOutput("versions", JSON.stringify(versions));
|
||||
|
||||
const branches = await Promise.all(versions.map(async (version) => {
|
||||
if (await versionHashBranch(version)) {
|
||||
return `stable${version}`;
|
||||
} else {
|
||||
return "master";
|
||||
const matrix = await Promise.all(versions.map(async (version) => {
|
||||
const branch = await getBranch(version);
|
||||
const php = await getSupportedVersions(branch);
|
||||
return {
|
||||
"php-versions": php.min.toFixed(1),
|
||||
"server-versions": branch,
|
||||
}
|
||||
}));
|
||||
|
||||
core.setOutput("versions", JSON.stringify(versions));
|
||||
|
||||
const branches = matrix.map(matrix => matrix["server-versions"]);
|
||||
|
||||
core.setOutput("branches", JSON.stringify(branches.filter(onlyUnique)));
|
||||
core.setOutput("matrix", JSON.stringify({
|
||||
include: matrix
|
||||
}));
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue