Skip to content
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

PR release comment workflow #1165

Merged
merged 1 commit into from
Jul 24, 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
29 changes: 29 additions & 0 deletions .github/pr-release-comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = async ({github, context, core}) => {
const newTag = context.ref.replace('refs/tags/', '');
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});

const release = releases.data.find((rel) => rel.tag_name === newTag);

if (!release) {
core.setFailed(`Release not found for tag ${newTag}`);
}

const prNumbers = release.body.match(/#(\d+)/g).map((match) => match.replace(/\D/g, ''));

for (const prNumber of prNumbers) {
try {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `This PR has been included in release: ${newTag}, see the [release notes](https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/${newTag}).`,
});
} catch (error) {
console.error(error);
core.setFailed(`Failed to comment on PR #${prNumber}: `);
}
}
}
21 changes: 21 additions & 0 deletions .github/workflows/pr-release-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: PR Release Comment

on:
push:
tags:
- '*'

jobs:
comment:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Comment on PRs
uses: actions/github-script@v6
with:
script: |
const commentOnPRs = require('./.github/pr-release-comment');
commentOnPRs({github, context, core});