Skip to content

Commit

Permalink
change regex for latest patch to match whole jsons parts of download …
Browse files Browse the repository at this point in the history
…page per version

get versions from download page
  • Loading branch information
venetrius authored and psavidis committed Oct 11, 2024
1 parent 2dc2f63 commit 1d49e47
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 52 deletions.
79 changes: 53 additions & 26 deletions common/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163772,13 +163772,15 @@ module.exports = SBOMParser;

const core = __nccwpck_require__(42186);
const github = __nccwpck_require__(95438);
const https = __nccwpck_require__(95687);

module.exports = async function () {

// Get Version Labels

const getVersionLabels = async function (potentialLabels, latestMinorVersion) {
const promises = potentialLabels.map(async potentialLabel => {

const minorVersion = getMinorFromPotentialLabel(potentialLabel);

if (minorVersion === latestMinorVersion) {
Expand All @@ -163795,10 +163797,10 @@ module.exports = async function () {
if (!latestPatchVersion) {
const calculatedVersionLabel = getVersionLabelFromPotential(potentialLabel); // fallback if GitHub is down, pom version is wrong, error at parsing
console.log(`No latest patch version found for potential label: ${potentialLabel}, returning calculated version ${calculatedVersionLabel}`);
return calculatedVersionLabel;
return getNextPatchVersion(calculatedVersionLabel);
}

return latestPatchVersion;
return getNextPatchVersion(calculatedVersionLabel);;
});

// Wait for all promises to settle and filter out null values
Expand Down Expand Up @@ -163858,6 +163860,12 @@ module.exports = async function () {
return match ? match[1] : null;
}

const getNextPatchVersion = function (currentVersion) {
const versionParts = currentVersion.split('.');
versionParts[2] = parseInt(versionParts[2]) + 1;
return versionParts.join('.');
}

const getLatestPatchVersion = async function (potentialLabel) {
console.log(`Get latest patch version for issue: #${issueNumber} for potential label:`, potentialLabel);
try {
Expand All @@ -163870,15 +163878,25 @@ module.exports = async function () {
console.log(`Minor version found: ${minorVersion}`);
}

const maintenanceRepoName = 'camunda-bpm-platform-maintenance';
const pomXML = await getFileContent(owner, maintenanceRepoName, 'pom.xml', minorVersion);
const patchVersionRegex = new RegExp(`(camDownloads\\.branches\\['${minorVersion}'\\]\\s*=\\s*)(\\[[\\s\\S]*?\\])(\\s*;)`);
const matchJson = downloadPage.match(patchVersionRegex);

// Return the version if found, otherwise return null
let versionsJsonString = matchJson ? matchJson[2] : null;

if (versionsJsonString == null) {
console.log(`No patch version could be extracted for potential label: ${potentialLabel}. Returning null.`);
return null;
}

console.log(`Patch Versions to fetch first element:`, versionsJsonString);

// Define regex to match <version>...</version>
const patchVersionRegex = /<artifactId>camunda-root<\/artifactId>\s*<version>(\d+\.\d+\.\d+)(?:-\w+)?<\/version>/;
const match = pomXML.match(patchVersionRegex); //FIXME something is not working here
const extractFirstPatchVersionFromJson = new RegExp(`(number\\: ')(.*)\\,`);
const matchFirstPatch = versionsJsonString.match(extractFirstPatchVersionFromJson);
let firstPatchVersion = matchFirstPatch ? matchFirstPatch[2] : null;

// Return the version if found, otherwise return null
return match ? match[1] : null;
console.log(`The latest version is: ${firstPatchVersion}`);
return firstPatchVersion;
} catch (error) {
console.error("Error fetching the XML document:", error);
return null;
Expand All @@ -163897,22 +163915,30 @@ module.exports = async function () {
return match ? match[1] : null;
}

async function getFileContent(owner, repo, path, ref) {
try {
const response = await octokit.rest.repos.getContent({
owner,
repo,
path,
ref, // branch name, commit SHA, or tag
});

// The content is base64 encoded, so we need to decode it
const fileContent = Buffer.from(response.data.content, 'base64').toString('utf-8');
console.log(fileContent);
return fileContent
} catch (error) {
console.error("Error fetching file:", error);
}
async function fetchDownloadPage() {
const url = `https://docs.camunda.org/enterprise/download/`;

return new Promise((resolve, reject) => {
https.get(url, (response) => {
let data = '';

if (response.statusCode !== 200) {
reject(new Error(`Failed to fetch data. Status code: ${response.statusCode}`));
response.resume(); // Consume response data to free up memory
return;
}

response.on('data', (chunk) => {
data += chunk;
});

response.on('end', () => {
resolve(data);
});
}).on('error', (error) => {
reject(error);
});
});
}

const setLabels = async function (owner, repo, issueNumber, labels) {
Expand Down Expand Up @@ -163948,11 +163974,12 @@ module.exports = async function () {
return;
}

const downloadPage = await fetchDownloadPage();

const latestVersion = await getLatestMinorVersion();
console.log(`Latest minor version: ${latestVersion}`);

const versionLabels = await getVersionLabels(potentialLabels, latestVersion);
console.log(versionLabels);

await setLabels(owner, repoName, issueNumber, versionLabels);
await removeLabels(owner, repoName, issueNumber, potentialLabels);
Expand Down
79 changes: 53 additions & 26 deletions common/src/set-version-labels.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const core = require('@actions/core');
const github = require('@actions/github');
const https = require('https');

module.exports = async function () {

// Get Version Labels

const getVersionLabels = async function (potentialLabels, latestMinorVersion) {
const promises = potentialLabels.map(async potentialLabel => {

const minorVersion = getMinorFromPotentialLabel(potentialLabel);

if (minorVersion === latestMinorVersion) {
Expand All @@ -23,10 +25,10 @@ module.exports = async function () {
if (!latestPatchVersion) {
const calculatedVersionLabel = getVersionLabelFromPotential(potentialLabel); // fallback if GitHub is down, pom version is wrong, error at parsing
console.log(`No latest patch version found for potential label: ${potentialLabel}, returning calculated version ${calculatedVersionLabel}`);
return calculatedVersionLabel;
return getNextPatchVersion(calculatedVersionLabel);
}

return latestPatchVersion;
return getNextPatchVersion(calculatedVersionLabel);;
});

// Wait for all promises to settle and filter out null values
Expand Down Expand Up @@ -86,6 +88,12 @@ module.exports = async function () {
return match ? match[1] : null;
}

const getNextPatchVersion = function (currentVersion) {
const versionParts = currentVersion.split('.');
versionParts[2] = parseInt(versionParts[2]) + 1;
return versionParts.join('.');
}

const getLatestPatchVersion = async function (potentialLabel) {
console.log(`Get latest patch version for issue: #${issueNumber} for potential label:`, potentialLabel);
try {
Expand All @@ -98,15 +106,25 @@ module.exports = async function () {
console.log(`Minor version found: ${minorVersion}`);
}

const maintenanceRepoName = 'camunda-bpm-platform-maintenance';
const pomXML = await getFileContent(owner, maintenanceRepoName, 'pom.xml', minorVersion);
const patchVersionRegex = new RegExp(`(camDownloads\\.branches\\['${minorVersion}'\\]\\s*=\\s*)(\\[[\\s\\S]*?\\])(\\s*;)`);
const matchJson = downloadPage.match(patchVersionRegex);

// Return the version if found, otherwise return null
let versionsJsonString = matchJson ? matchJson[2] : null;

// Define regex to match <version>...</version>
const patchVersionRegex = /<artifactId>camunda-root<\/artifactId>\s*<version>(\d+\.\d+\.\d+)(?:-\w+)?<\/version>/;
const match = pomXML.match(patchVersionRegex); //FIXME something is not working here
if (versionsJsonString == null) {
console.log(`No patch version could be extracted for potential label: ${potentialLabel}. Returning null.`);
return null;
}

// Return the version if found, otherwise return null
return match ? match[1] : null;
console.log(`Patch Versions to fetch first element:`, versionsJsonString);

const extractFirstPatchVersionFromJson = new RegExp(`(number\\: ')(.*)('\\,)`);
const matchFirstPatch = versionsJsonString.match(extractFirstPatchVersionFromJson);
let firstPatchVersion = matchFirstPatch ? matchFirstPatch[2] : null;

console.log(`The latest version is: ${firstPatchVersion}`);
return firstPatchVersion;
} catch (error) {
console.error("Error fetching the XML document:", error);
return null;
Expand All @@ -125,22 +143,30 @@ module.exports = async function () {
return match ? match[1] : null;
}

async function getFileContent(owner, repo, path, ref) {
try {
const response = await octokit.rest.repos.getContent({
owner,
repo,
path,
ref, // branch name, commit SHA, or tag
});

// The content is base64 encoded, so we need to decode it
const fileContent = Buffer.from(response.data.content, 'base64').toString('utf-8');
console.log(fileContent);
return fileContent
} catch (error) {
console.error("Error fetching file:", error);
}
async function fetchDownloadPage() {
const url = `https://docs.camunda.org/enterprise/download/`;

return new Promise((resolve, reject) => {
https.get(url, (response) => {
let data = '';

if (response.statusCode !== 200) {
reject(new Error(`Failed to fetch data. Status code: ${response.statusCode}`));
response.resume(); // Consume response data to free up memory
return;
}

response.on('data', (chunk) => {
data += chunk;
});

response.on('end', () => {
resolve(data);
});
}).on('error', (error) => {
reject(error);
});
});
}

const setLabels = async function (owner, repo, issueNumber, labels) {
Expand Down Expand Up @@ -176,11 +202,12 @@ module.exports = async function () {
return;
}

const downloadPage = await fetchDownloadPage();

const latestVersion = await getLatestMinorVersion();
console.log(`Latest minor version: ${latestVersion}`);

const versionLabels = await getVersionLabels(potentialLabels, latestVersion);
console.log(versionLabels);

await setLabels(owner, repoName, issueNumber, versionLabels);
await removeLabels(owner, repoName, issueNumber, potentialLabels);
Expand Down

0 comments on commit 1d49e47

Please sign in to comment.