Skip to content

Changesets CI Comment #53497

Changesets CI Comment

Changesets CI Comment #53497

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: ubuntu-latest
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@e3ba776faee1134e17551924b852bfb374e1703d # pin@v1_1
id: source-run-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
- name: "Download artifact"
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # [email protected]
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@dadb7667129e23f12ca3925c90dc5cd7121ab57e # pin@v2
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 Sui 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 # [email protected]
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
});
}