Create new release issue #216
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create new release issue | |
on: | |
schedule: | |
- cron: "0 */6 * * *" # every 6 hours - this is a workaround for missing repository_dispatch events | |
workflow_dispatch: | |
repository_dispatch: | |
types: [new-release-created] | |
jobs: | |
create-issue: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Verify webhook secret | |
if: github.event_name == 'repository_dispatch' && github.event.action == 'new-release-created' | |
id: verify_secret | |
run: | | |
if [ "${{ github.event.client_payload.secret }}" != "${{ secrets.WEBHOOK_SECRET }}" ]; then | |
echo "Invalid secret" | |
exit 1 | |
fi | |
- name: Get latest release | |
id: get_latest_release | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const releases = await github.rest.repos.listReleases({ | |
owner: 'primer', | |
repo: 'brand' | |
}); | |
const latestRelease = releases.data.find(release => release.name.includes('@primer/react-brand')); | |
if (!latestRelease) { | |
core.setFailed('No @primer/react-brand release found.'); | |
} else { | |
console.log('Latest release:', latestRelease); | |
core.setOutput('release_name', latestRelease.name); | |
core.setOutput('release_url', latestRelease.html_url); | |
core.setOutput('release_body', latestRelease.body); | |
} | |
- name: Create new release issue | |
if: success() | |
id: created-issue | |
uses: JasonEtco/create-an-issue@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
release_name: ${{ steps.get_latest_release.outputs.release_name }} | |
release_url: ${{ steps.get_latest_release.outputs.release_url }} | |
release_body: ${{ steps.get_latest_release.outputs.release_body }} | |
with: | |
update_existing: true | |
search_existing: true | |
- name: Get comments from last release | |
if: success() | |
id: get_pr_comments | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const crypto = require('crypto'); | |
const prs = await github.rest.pulls.list({ | |
owner: "primer", | |
repo: "brand", | |
state: "closed", | |
sort: "updated", | |
direction: "desc", | |
}); | |
const targetPr = prs.data.find( | |
(pr) => pr.head.ref === "changeset-release/main" | |
); | |
if (!targetPr) { | |
console.error("No closed PR found with branch changeset-release/main."); | |
process.exit(1); | |
} else { | |
const comments = await github.rest.issues.listComments({ | |
owner: "primer", | |
repo: "brand", | |
issue_number: targetPr.number, | |
}); | |
const filteredComments = comments.data.filter( | |
(comment) => | |
comment.user.login !== "github-actions[bot]" && | |
comment.user.login !== "changeset-bot[bot]" | |
); | |
// Existing comments | |
const issue_number = ${{ steps.created-issue.outputs.number }}; | |
const issueComments = await github.rest.issues.listComments({ | |
owner: 'primer', | |
repo: 'brand-releases', | |
issue_number: issue_number, | |
}); | |
// Hash existing comments | |
const existingCommentHashes = new Set(issueComments.data.map(issueComment => | |
crypto.createHash('sha256').update(issueComment.body).digest('hex') | |
)); | |
// Post deduped comments | |
for (const comment of filteredComments) { | |
const commentHash = crypto.createHash('sha256').update(comment.body).digest('hex'); | |
if (!existingCommentHashes.has(commentHash)) { | |
await github.rest.issues.createComment({ | |
owner: 'primer', | |
repo: 'brand-releases', | |
issue_number: issue_number, | |
body: comment.body | |
}); | |
} | |
} | |
} |