also get supported php versions

This commit is contained in:
Robin Appelman 2023-11-02 18:06:11 +01:00
commit a82a7d40fd
7 changed files with 82 additions and 15 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<info>
<dependencies>
<nextcloud min-version="25" max-version="29" />
<nextcloud min-version="25" max-version="28" />
</dependencies>
</info>

View file

@ -23,3 +23,4 @@ jobs:
run: |
echo -e "Versions :\n${{ steps.run.outputs.versions }}"
echo -e "Branches :\n${{ steps.run.outputs.branches }}"
echo -e "Matrix :\n${{ steps.run.outputs.matrix }}"

View file

@ -9,6 +9,8 @@ outputs:
description: 'List of supported nextcloud versions'
branches:
description: 'List of branches for the supported nextcloud versions'
matrix:
description: 'Test matrix with server branch and php version'
runs:
using: 'node20'
main: 'dist/index.js'

47
dist/index.js vendored
View file

@ -38791,15 +38791,39 @@ const xpath = __nccwpck_require__(5319);
const DOMParser = (__nccwpck_require__(7286)/* .DOMParser */ .a);
const fs = __nccwpck_require__(7147);
const urlExist = __nccwpck_require__(5565);
const {HttpClient} = __nccwpck_require__(6255);
function isVersionReleased(version) {
return urlExist(`https://download.nextcloud.com/server/releases/latest-${version}.zip`);
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;
}
@ -38816,17 +38840,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 isVersionReleased(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);

1
package-lock.json generated
View file

@ -15,6 +15,7 @@
"xpath": "0.0.27"
},
"devDependencies": {
"@actions/http-client": "^2.2.0",
"@vercel/ncc": "^0.38.1"
}
},

View file

@ -12,6 +12,7 @@
"license": "ISC",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/http-client": "^2.2.0",
"url-exist": "^2.0.2",
"xmldom": "^0.6.0",
"xpath": "0.0.27"

View file

@ -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);