diff --git a/.github/scripts/actionUtils.js b/.github/scripts/actionUtils.js index d7319fb165..285765cd79 100644 --- a/.github/scripts/actionUtils.js +++ b/.github/scripts/actionUtils.js @@ -4,18 +4,17 @@ const fs = require("fs"); // NodeJs module provides an API for interacting with /** * Appends a provided summary content to the GitHub step summary file. * This function is designed to be reused across different modules or scripts. - * + * * @param {string} summaryContent The content to append to the GitHub step summary. */ async function appendSummary(summaryContent) { - try { - fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, summaryContent); - console.log("Summary appended successfully."); - } catch (error) { - core.setFailed("Failed to append summary due to: " + error.message); - console.error(error); - } + try { + fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, summaryContent); + console.log("Summary appended successfully."); + } catch (error) { + core.setFailed("Failed to append summary due to: " + error.message); + console.error(error); + } } module.exports = appendSummary; // Exporting the function for external use - diff --git a/.github/scripts/createAndPostTag.js b/.github/scripts/createAndPostTag.js index 7ba1dd5f57..7be4f5351e 100644 --- a/.github/scripts/createAndPostTag.js +++ b/.github/scripts/createAndPostTag.js @@ -1,6 +1,6 @@ // createAndPostTag.js const { prData, getReleaseVersionValue } = require("./prData"); -const appendSummary = require('./actionUtils'); +const appendSummary = require("./actionUtils"); const fs = require("fs"); /** @@ -49,39 +49,43 @@ async function createTag(github, owner, repo, newVersion, sha) { * @async */ async function createAndPostTag(params) { - const { github, context, core } = params; - const owner = context.repo.owner; - const repo = context.repo.repo; + const { github, context, core } = params; + const owner = context.repo.owner; + const repo = context.repo.repo; - try { - // Retrieve PR data to decide the new version tag - const { releaseBranchSha, newVersion } = await prData({ - github, - context, - core, - }); + try { + // Retrieve PR data to decide the new version tag + const { releaseBranchSha, newVersion } = await prData({ + github, + context, + core, + }); - // Create and push the tag using the SHA from releaseBranchSha - await createTag(github, owner, repo, newVersion, releaseBranchSha); + // Create and push the tag using the SHA from releaseBranchSha + await createTag(github, owner, repo, newVersion, releaseBranchSha); - // Update the RELEASE_VERSION repo variable - await github.rest.actions.updateRepoVariable({ - owner, - repo, - name: "RELEASE_VERSION", - value: newVersion, - }); + // Update the RELEASE_VERSION repo variable + await github.rest.actions.updateRepoVariable({ + owner, + repo, + name: "RELEASE_VERSION", + value: newVersion, + }); - // Construct the summary content - const summaryContent = ` + // Construct the summary content + const summaryContent = ` ### Successful Tag Creation! - After merge to the release branch, a tag was created. - New version is ${newVersion} - Tag created for version ${newVersion} using the new release branch SHA: ${releaseBranchSha} `; - // Append the summary to the GitHub step summary file or log it - appendSummary(summaryContent); + // Append the summary to the GitHub step summary file or log it + appendSummary(summaryContent); + } catch (error) { + core.setFailed(`Failed to generate summary: ${error.message}`); + console.error(error); + } } module.exports = createAndPostTag; diff --git a/.github/scripts/prData.js b/.github/scripts/prData.js index 5e73a8bdc0..30ef1bb910 100644 --- a/.github/scripts/prData.js +++ b/.github/scripts/prData.js @@ -71,16 +71,16 @@ function processLabelsAndVersion(labels, currentVersion) { versionParts[2] = 0; appliedLabel = "breaking change"; } else if ( - // If hotfix, security, or bug label + // If hotfix, security, or bug label labels.some((label) => ["hotfix", "security", "bug"].includes(label.name)) ) { - // patch bump + // patch bump versionParts[2] += 1; appliedLabel = labels.find((label) => ["hotfix", "security", "bug"].includes(label.name), ).name; } else { - // all other labels are a minor bump + // all other labels are a minor bump versionParts[1] += 1; versionParts[2] = 0; appliedLabel = labels.find((label) => label).name; // Catch-all increment @@ -110,7 +110,7 @@ async function prData(params) { const currentVersion = await getReleaseVersionValue(github, owner, repo); const releaseBranchSha = await fetchReleaseBranchSha(github, owner, repo); - const labels = pullRequestData.data[0].labels + const labels = pullRequestData.data[0].labels; const prNumber = pullRequestData.data[0].number; const prUrl = pullRequestData.data[0].html_url; @@ -132,10 +132,9 @@ async function prData(params) { console.error("Error processing PR data:", error); return null; // Ensure to handle null in postQA.js if needed } -}; +} module.exports = { prData, getReleaseVersionValue, }; - diff --git a/.github/scripts/prLabelSemver.js b/.github/scripts/prLabelSemver.js index d1b36af0e1..76d9ebe5c6 100644 --- a/.github/scripts/prLabelSemver.js +++ b/.github/scripts/prLabelSemver.js @@ -1,12 +1,12 @@ // prLabelSemver.js const { prData } = require("./prData"); -const appendSummary = require('./actionUtils'); +const appendSummary = require("./actionUtils"); const fs = require("fs"); /** * Automatically labels pull requests based on semantic versioning (semver) guidelines * and appends a summary to the GitHub action step. - * + * * @param {object} github - The github object providing context and operations for the pull request. * @param {object} context - The context object containing metadata and states for the action run. * @param {object} core - The core library with utilities for logging and error handling. @@ -25,7 +25,7 @@ const prLabelSemver = async ({ github, context, core }) => { ? "PATCH" : "MINOR"; - // Construct the summary content + // Construct the summary content const summaryContent = ` ### PR Label Semver Summary - PR Number: [#${prNumber}](${prUrl}) @@ -33,8 +33,11 @@ const prLabelSemver = async ({ github, context, core }) => { - Semver Bump: ${semverValue} `; // Append the summary to the GitHub step summary file or log it - appendSummary(summaryContent); + appendSummary(summaryContent); + } catch (error) { + core.setFailed(`Failed to generate summary: ${error.message}`); + console.error(error); + } }; module.exports = prLabelSemver; - diff --git a/.github/scripts/preTagSummary.js b/.github/scripts/preTagSummary.js index 8224b42c1b..7a428c7228 100644 --- a/.github/scripts/preTagSummary.js +++ b/.github/scripts/preTagSummary.js @@ -1,7 +1,7 @@ // preTagSummary.js // This module defines a function to generate a pre-tag release summary for GitHub pull requests. const { prData, getReleaseVersionValue } = require("./prData"); -const appendSummary = require('./actionUtils'); +const appendSummary = require("./actionUtils"); const fs = require("fs"); /** @@ -9,7 +9,7 @@ const fs = require("fs"); * This function retrieves the current and proposed new release versions from a pull request data, * constructs a summary of the release, and appends it to the GitHub step summary for visibility * in the GitHub Actions workflow. - * + * * @param {object} github - The GitHub context object, providing context like repo and owner. * @param {object} context - The GitHub context object with additional pull request information. * @param {object} core - The GitHub core library, used for setting action failure messages. @@ -31,8 +31,11 @@ const preTagSummary = async ({ github, context, core }) => { `; // Append the summary to the GitHub step summary file or log it - appendSummary(summaryContent); + appendSummary(summaryContent); + } catch (error) { + core.setFailed(`Failed to generate summary: ${error.message}`); + console.error(error); + } }; module.exports = preTagSummary; -