-
Notifications
You must be signed in to change notification settings - Fork 41
74 lines (66 loc) · 2.39 KB
/
knip-reporter.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
name: Knip-reporter
on:
workflow_run:
workflows: ["Knip"]
types:
- completed
jobs:
knip-reporter:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion != 'success' }}
steps:
- name: Verify Runner's Identity
id: verify-runner
run: |
echo "Runner name: $RUNNER_NAME"
if [[ "$RUNNER_NAME" != *"GitHub Actions"* ]]; then
echo "This workflow must run on a GitHub Actions runner. (github-actions[bot])"
exit 1
fi
- uses: actions/download-artifact@v4
with:
name: knip-results
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Read pr number
id: pr-number
uses: juliangruber/read-file-action@v1
with:
path: ./pr-number.txt
trim: true
- name: Get or create comment ID for Knip Report
id: get-comment
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issue_number = ${{ steps.pr-number.outputs.content }};
// Fetch all comments on the PR
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
// Look for an existing Knip report comment
let knipComment = comments.data.find(comment =>
comment.body.startsWith("| Knip Report |")
);
if (knipComment) {
console.log('Found existing Knip report comment:', knipComment.id);
core.setOutput('comment_id', knipComment.id); // Set the comment ID output
} else {
console.log('No existing Knip report comment found.');
core.setOutput('comment_id', ''); // No existing comment
}
- name: Report Knip results to pull request
uses: gitcoindev/knip-reporter@main
with:
verbose: true
comment_id: ${{ steps.get-comment.outputs.comment_id || github.workflow }}-knip-report
command_script_name: knip-ci
annotations: true
ignore_results: false
json_input: true
json_input_file_name: knip-results.json
pull_request_number: ${{ steps.pr-number.outputs.content }}
token: ${{ secrets.GITHUB_TOKEN }}