-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
55 lines (51 loc) · 2.52 KB
/
action.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
name: PR Comment with Changes Breakdown
description: 'Comment on PR with a short summary of changes. They are classified according to your config.'
author: 'Boris Lykah'
inputs:
diff-stat:
description: 'The JSON object describing changes. This is the "stat" output of lykahb/paths-filter.'
required: true
minimum-files:
description: 'There minimum number of files that must change before a comment is posted. If both minimum-files and minimum-lines are set, the conditions for both must be met before a comment is posted.'
default: 0
minimum-lines:
description: 'The minimum number of lines of code that must change before a comment is posted. If both minimum-files and minimum-lines are set, the conditions for both must be met before a comment is posted.'
default: 0
runs:
using: 'composite'
steps:
- id: condition
shell: bash
run: |
echo "passed=$(jq 'to_entries | map(.value) | (map(.additionCount + .deletionCount) | ${{ inputs.minimum-lines }} <= add) and (map (.fileCount) | ${{ inputs.minimum-files }} <= add)' <<< '${{ inputs.diff-stat }}')" >> "${GITHUB_OUTPUT}"
- if: steps.condition.outputs.passed == 'true'
uses: peter-evans/find-comment@v2
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- Paths Filter with Diff Stat -->'
- if: steps.condition.outputs.passed == 'true'
id: make-comment-body
shell: bash
run: |
JQ_FILTER='to_entries | group_by(.key=="other") | flatten | .[] | select (.value.fileCount > 0) | "| \(.key) | \(.value.fileCount) | \(.value.additionCount) | \(.value.deletionCount) |"'
COMMENT_BODY=$(echo '${{ inputs.diff-stat }}' | jq --raw-output "$JQ_FILTER")
echo "comment_body<<PR_COMMENT_EOF" >> $GITHUB_OUTPUT
echo "$COMMENT_BODY" >> $GITHUB_OUTPUT
echo "PR_COMMENT_EOF" >> $GITHUB_OUTPUT
- if: steps.condition.outputs.passed == 'true'
uses: peter-evans/create-or-update-comment@v2
id: create-or-update-comment
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- Paths Filter with Diff Stat -->
| Group | Files changed | Additions | Deletions |
| ------ | ------------- | --------- | --------- |
${{ steps.make-comment-body.outputs.comment_body }}
edit-mode: replace
branding:
color: blue
icon: message-square