Skip to content

Commit

Permalink
fixed catch and ran prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ldraney committed May 8, 2024
1 parent 1b3cf05 commit a7677f1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 48 deletions.
17 changes: 8 additions & 9 deletions .github/scripts/actionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

52 changes: 28 additions & 24 deletions .github/scripts/createAndPostTag.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// createAndPostTag.js
const { prData, getReleaseVersionValue } = require("./prData");
const appendSummary = require('./actionUtils');
const appendSummary = require("./actionUtils");
const fs = require("fs");

/**
Expand Down Expand Up @@ -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;
11 changes: 5 additions & 6 deletions .github/scripts/prData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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,
};

13 changes: 8 additions & 5 deletions .github/scripts/prLabelSemver.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,16 +25,19 @@ 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})
- Label: ${label}
- 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;

11 changes: 7 additions & 4 deletions .github/scripts/preTagSummary.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// 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");

/**
* Asynchronously generates and appends a pre-tag release summary to the GitHub step summary file.
* 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.
Expand All @@ -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;

0 comments on commit a7677f1

Please sign in to comment.