From d8acb0be8b117008de9034161f54eee675541ed8 Mon Sep 17 00:00:00 2001 From: Ajay Jaganathan <36824134+AjayJagan@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:11:57 +0530 Subject: [PATCH] chore: Improve automation logic for reading release branches (#1066) --- .../scripts/get-component-release-notes.js | 10 ++++--- .github/scripts/get-release-branches.js | 26 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.github/scripts/get-component-release-notes.js b/.github/scripts/get-component-release-notes.js index d79805fd79c..e7eb4d4d18a 100644 --- a/.github/scripts/get-component-release-notes.js +++ b/.github/scripts/get-component-release-notes.js @@ -20,10 +20,14 @@ module.exports = ({ github, core }) => { issueCommentBody = issue.body_text if (issueCommentBody.includes("#Release#")) { let components = issueCommentBody.split("\n") - components = components.splice(2, components.length - 1) + const releaseIdx = components.indexOf("#Release#") + components = components.splice(releaseIdx + 1, components.length - 1) + const regex = /[A-Za-z-_0-9]+\|(https:\/\/github\.com\/.*tree.*){1}\|(https:\/\/github\.com\/.*releases.*){1}/gm; components.forEach(component => { - [componentName, branchUrl, tagUrl] = component.split("|") - outputStr += `- **${componentName.charAt(0).toUpperCase() + componentName.slice(1)}**: ${tagUrl}\n` + if (regex.test(component)) { + [componentName, branchUrl, tagUrl] = component.split("|") + outputStr += `- **${componentName.trim().charAt(0).toUpperCase() + componentName.trim().slice(1)}**: ${tagUrl.trim()}\n` + } }) } }) diff --git a/.github/scripts/get-release-branches.js b/.github/scripts/get-release-branches.js index a8c757510d3..cc11d8385f6 100644 --- a/.github/scripts/get-release-branches.js +++ b/.github/scripts/get-release-branches.js @@ -20,17 +20,23 @@ module.exports = ({ github, core }) => { issueCommentBody = issue.body_text if (issueCommentBody.includes("#Release#")) { let components = issueCommentBody.split("\n") - components = components.splice(2, components.length - 1) + const releaseIdx = components.indexOf("#Release#") + components = components.splice(releaseIdx + 1, components.length - 1) + const regex = /[A-Za-z-_0-9]+\|(https:\/\/github\.com\/.*tree.*){1}\|(https:\/\/github\.com\/.*releases.*){1}/gm; components.forEach(component => { - [componentName, branchUrl] = component.split("|") - const splitArr = branchUrl.split("/") - const idx = splitArr.indexOf("tree") - const branchName = splitArr.slice(idx + 1).join("/") - if(componentName === "notebook-controller"){ - core.exportVariable("component_spec_odh-notebook-controller".toLowerCase(), branchName); - core.exportVariable("component_spec_kf-notebook-controller".toLowerCase(), branchName); - }else{ - core.exportVariable("component_spec_"+componentName.toLowerCase(), branchName); + if (regex.test(component)) { + [componentName, branchUrl] = component.split("|") + componentName = componentName.trim() + branchUrl = branchUrl.trim() + const splitArr = branchUrl.split("/") + const idx = splitArr.indexOf("tree") + const branchName = splitArr.slice(idx + 1).join("/") + if (componentName === "notebook-controller") { + core.exportVariable("component_spec_odh-notebook-controller".toLowerCase(), branchName); + core.exportVariable("component_spec_kf-notebook-controller".toLowerCase(), branchName); + } else { + core.exportVariable("component_spec_" + componentName.toLowerCase(), branchName); + } } }) }