forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (72 loc) · 3.04 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
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@v1_1
id: source-run-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
- name: "Download artifact"
uses: actions/github-script@v6
id: get-artifact
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@v1
if: steps.get-artifact.outputs.result == 'true'
with:
pr_number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
comment_includes: "⚠️ 🦋 **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`, 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@v6
if: steps.get-artifact.outputs.result == 'false'
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
});
}