Skip to content

Changesets CI Comment #2480

Changesets CI Comment

Changesets CI Comment #2480

name: Changesets CI Comment
# NOTE: This workflow run indirection is used to securely comment on PRs when
# changeset CI runs are completed.
on:
workflow_run:
workflows: ["Changesets CI"]
types:
- completed
jobs:
upload:
runs-on: self-hosted
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Get workflow run information
uses: potiuk/get-workflow-origin@c657bb36aef4a7402bbe9b2e09a820320f8ff447 # v1.0.0
id: source-run-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
- name: "Download artifact"
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: get-artifact
if: steps.source-run-info.outputs.pullRequestNumber
with:
result-encoding: string
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "missing-changeset"
})[0];
if (!matchArtifact) {
return 'false';
}
return 'true';
- name: Comment PR
uses: thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # v2.5.0
if: steps.get-artifact.outputs.result == 'true' && steps.source-run-info.outputs.pullRequestNumber
with:
pr_number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
comment_tag: "changesets-warning"
message: |
⚠️ 🦋 **Changesets Warning:** This PR has changes to public npm packages, but does not contain a changeset. You can create a changeset easily by running `pnpm changeset` in the root of the IOTA repo, and following the prompts. If your change does not need a changeset (e.g. a documentation-only change), you can ignore this message. This warning will be removed when a changeset is added to this pull request.
[Learn more about Changesets](https://github.com/changesets/changesets).
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Remove outdated comments
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: steps.get-artifact.outputs.result == 'false' && steps.source-run-info.outputs.pullRequestNumber
env:
ISSUE_NUMBER: ${{ steps.source-run-info.outputs.pullRequestNumber }}
with:
script: |
const resp = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: process.env.ISSUE_NUMBER
});
const comments = resp.data.filter(it => it.body.startsWith('⚠️ 🦋 **Changesets Warning:**'));
for (const comment of comments) {
console.log(
`Removing issue ${comment.issue_url}`
);
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id
});
}