Skip to content

Commit

Permalink
get versions from download page
Browse files Browse the repository at this point in the history
  • Loading branch information
venetrius committed Oct 11, 2024
1 parent 2dc2f63 commit c4d6a61
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 46 deletions.
53 changes: 30 additions & 23 deletions common/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163772,6 +163772,7 @@ module.exports = SBOMParser;

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

module.exports = async function () {

Expand Down Expand Up @@ -163870,13 +163871,9 @@ 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);

// 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 patchVersionRegex = new RegExp(`camDownloads\\.branches\\['${minorVersion}'\\]\\s*=\\s*\\[\\s*\\{\\s*number:\\s*'(\\d+\\.\\d+\\.\\d+)'`);
const match = downloadPage.match(patchVersionRegex);

// Return the version if found, otherwise return null
return match ? match[1] : null;
} catch (error) {
Expand All @@ -163897,22 +163894,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,6 +163953,8 @@ module.exports = async function () {
return;
}

const downloadPage = await fetchDownloadPage();

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

Expand Down
53 changes: 30 additions & 23 deletions common/src/set-version-labels.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');
const https = require('https');

module.exports = async function () {

Expand Down Expand Up @@ -98,13 +99,9 @@ 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);

// 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 patchVersionRegex = new RegExp(`camDownloads\\.branches\\['${minorVersion}'\\]\\s*=\\s*\\[\\s*\\{\\s*number:\\s*'(\\d+\\.\\d+\\.\\d+)'`);
const match = downloadPage.match(patchVersionRegex);

// Return the version if found, otherwise return null
return match ? match[1] : null;
} catch (error) {
Expand All @@ -125,22 +122,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,6 +181,8 @@ module.exports = async function () {
return;
}

const downloadPage = await fetchDownloadPage();

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

Expand Down

0 comments on commit c4d6a61

Please sign in to comment.