-
Notifications
You must be signed in to change notification settings - Fork 13
85 lines (73 loc) · 3.38 KB
/
changesets_ci_comment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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 # pin@v1
id: source-run-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
- name: "Download artifact"
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # pin@v7
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 # 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 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 # pin@v7
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
});
}