Skip to content

chore(ci): update post release workflow #1506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions .github/scripts/label_related_issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ const {
HANDLE_MAINTAINERS_TEAM,
PR_IS_MERGED,
RELATED_ISSUE_REGEX,
} = require("./constants");
LABEL_RELEASED,
} = require('./constants');

module.exports = async ({ github, context, core }) => {
if (IGNORE_AUTHORS.includes(PR_AUTHOR)) {
return core.notice("Author in IGNORE_AUTHORS list; skipping...");
return core.notice('Author in IGNORE_AUTHORS list; skipping...');
}

if (PR_IS_MERGED == "false") {
return core.notice("Only merged PRs to avoid spam; skipping");
if (PR_IS_MERGED == 'false') {
return core.notice('Only merged PRs to avoid spam; skipping');
}

const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY);
Expand Down Expand Up @@ -60,22 +61,28 @@ module.exports = async ({ github, context, core }) => {
/**
* Keep all labels except those that start with 'status/' or 'need-' or equal to 'help-wanted'
* as those are contextual to issues still in progress.
*
* If the issue was already marked with the 'status/completed' label, then we'll keep that, otherwise
* we'll add the 'status/pending-release' label.
*/
let hasCompletedLabel = false;
const newLabels = currentLabels.data
.filter(
(label) =>
!label.name.startsWith("status/") &&
!label.name.startsWith("need-") &&
label.name !== "help-wanted"
)
.filter((label) => {
if (label.name === LABEL_RELEASED) {
hasCompletedLabel = true;
}
return (
!label.name.startsWith('status/') &&
!label.name.startsWith('need-') &&
label.name !== 'help-wanted'
);
})
.map((label) => label.name);
// Add the status/pending-release label
newLabels.push(LABEL_PENDING_RELEASE);
// Add the status/pending-release or status/completed label
newLabels.push(hasCompletedLabel ? LABEL_RELEASED : LABEL_PENDING_RELEASE);

try {
core.info(
`Auto-labeling related issue ${issue} for release while removing 'status/*' and 'need-*' labels`
);
core.info(`Auto-labeling related issue ${issue} completed`);
return await github.rest.issues.setLabels({
issue_number: issue,
owner: context.repo.owner,
Expand Down
154 changes: 81 additions & 73 deletions .github/scripts/post_release.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { LABEL_PENDING_RELEASE, LABEL_RELEASED } = require("./constants");
const { LABEL_PENDING_RELEASE, LABEL_RELEASED } = require('./constants');

/**
* Fetch issues using GitHub REST API
Expand All @@ -12,26 +12,28 @@ const { LABEL_PENDING_RELEASE, LABEL_RELEASED } = require("./constants");
* @see {@link https://octokit.github.io/rest.js/v18#usage|Octokit client}
*/
const fetchIssues = async ({
gh_client,
org,
repository,
state = "all",
label = LABEL_PENDING_RELEASE,
gh_client,
core,
org,
repository,
state = 'all',
label = LABEL_PENDING_RELEASE,
}) => {
try {
const { data: issues } = await gh_client.rest.issues.listForRepo({
owner: org,
repo: repository,
state: state,
labels: label,
});

return issues;
} catch (error) {
console.error(error);
throw new Error("Failed to fetch issues");
}
try {
const { data: issues } = await gh_client.rest.issues.listForRepo({
owner: org,
repo: repository,
state: state,
labels: label,
});

return issues.filter(
(issue) => Object(issue).hasOwnProperty('pull_request') === false
);
} catch (error) {
core.setFailed(error);
throw new Error('Failed to fetch issues');
}
};

/**
Expand All @@ -44,68 +46,74 @@ const fetchIssues = async ({
* @see {@link https://octokit.github.io/rest.js/v18#usage|Octokit client}
*/
const notifyRelease = async ({
gh_client,
owner,
repository,
release_version,
gh_client,
core,
owner,
repository,
release_version,
}) => {
const release_url = `https://github.com/${owner}/${repository}/releases/tag/v${release_version.replace(/v/g, '')}`;

const issues = await fetchIssues({
gh_client: gh_client,
org: owner,
repository: repository,
state: "closed"
});
const release_url = `https://github.com/${owner}/${repository}/releases/tag/v${release_version.replace(
/v/g,
''
)}`;

issues.forEach(async (issue) => {
console.info(`Updating issue number ${issue.number}`);
const issues = await fetchIssues({
gh_client: gh_client,
org: owner,
repository: repository,
state: 'closed',
});

const comment = `This is now released under [${release_version}](${release_url}) version!`;
try {
await gh_client.rest.issues.createComment({
owner: owner,
repo: repository,
body: comment,
issue_number: issue.number,
});
} catch (error) {
console.error(error);
throw new Error(`Failed to update issue ${issue.number} about ${release_version} release`)
}
issues.forEach(async (issue) => {
core.info(`Updating issue number ${issue.number}`);

const comment = `This is now released under [${release_version}](${release_url}) version!`;
try {
await gh_client.rest.issues.createComment({
owner: owner,
repo: repository,
body: comment,
issue_number: issue.number,
});
} catch (error) {
core.setFailed(error);
throw new Error(
`Failed to update issue ${issue.number} about ${release_version} release`
);
}

// Close issue and remove staged label; keep existing ones
const labels = issue.labels
.filter((label) => label.name != LABEL_PENDING_RELEASE)
.map((label) => label.name)
.push(LABEL_RELEASED);
// Remove staged label; keep existing ones
const labels = issue.labels
.filter((label) => label.name != LABEL_PENDING_RELEASE)
.map((label) => label.name);

try {
await gh_client.rest.issues.setLabels({
repo: repository,
owner,
issue_number: issue.number,
labels,
});
} catch (error) {
console.error(error);
throw new Error("Failed to close issue")
}
// Update labels including the released one
try {
await gh_client.rest.issues.setLabels({
repo: repository,
owner,
issue_number: issue.number,
labels: [...labels, LABEL_RELEASED],
});
} catch (error) {
core.setFailed(error);
throw new Error('Failed to label issue');
}

console.info(`Issue number ${issue.number} closed and updated`);
});
core.info(`Issue number ${issue.number} labeled`);
});
};

// context: https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts
module.exports = async ({ github, context }) => {
const { RELEASE_VERSION } = process.env;
console.log(`Running post-release script for ${RELEASE_VERSION} version`);
module.exports = async ({ github, context, core }) => {
const { RELEASE_VERSION } = process.env;
core.info(`Running post-release script for ${RELEASE_VERSION} version`);

await notifyRelease({
gh_client: github,
owner: context.repo.owner,
repository: context.repo.repo,
release_version: RELEASE_VERSION,
});
};
await notifyRelease({
gh_client: github,
core,
owner: context.repo.owner,
repository: context.repo.repo,
release_version: RELEASE_VERSION,
});
};