-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
127 lines (115 loc) · 3.88 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: 'dstlled-diff'
description: 'Github action to make reviewing large structural code changes easier'
author: 'dhth'
branding:
color: 'blue'
icon: 'git-pull-request'
inputs:
starting-commit:
description: 'Starting commit for the diff'
required: true
ending-commit:
description: 'Ending commit for the diff'
required: true
pattern:
description: 'File pattern to get diff for'
required: false
default: '*'
directory:
description: 'Directory to operate in'
required: false
default: '.'
post-comment-on-pr:
description: 'Whether to post a comment containing the diff on the corresponding PR'
required: false
default: 'false'
save-diff-to-file:
description: 'Whether to save diff to a file'
required: false
default: 'false'
outputs:
diff:
description: "diff"
value: ${{ steps.gen-diff.outputs.diff }}
runs:
using: "composite"
steps:
- name: Install dstll
uses: jaxxstorm/action-install-gh-release@25d5e2dd555cd74f1fab9ac1e6ea117acde2c0c4 # v1.12.0
with:
repo: dhth/dstll
tag: v0.2.1
- name: Set GitHub Path
run: echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
shell: bash
env:
GITHUB_ACTION_PATH: ${{ github.action_path }}
- name: Shorten commit hashes
id: shorten-hashes
shell: bash
env:
STARTING_COMMIT: ${{ inputs.starting-commit }}
ENDING_COMMIT: ${{ inputs.ending-commit }}
run: |
START=$(echo "${STARTING_COMMIT:0:8}")
END=$(echo "${ENDING_COMMIT:0:8}")
echo "start=$START" >> $GITHUB_OUTPUT
echo "end=$END" >> $GITHUB_OUTPUT
- name: run dstll
id: gen-diff
shell: bash
env:
PATTERN: ${{ inputs.pattern }}
STARTING_COMMIT: ${{ steps.shorten-hashes.outputs.start }}
ENDING_COMMIT: ${{ steps.shorten-hashes.outputs.end }}
DIRECTORY: ${{ inputs.directory }}
run: |
echo "diffing ${STARTING_COMMIT}..${ENDING_COMMIT} -- $PATTERN"
dstlled-diff "$DIRECTORY" diff.patch "$PATTERN" "$STARTING_COMMIT" "$ENDING_COMMIT"
{
echo 'diff<<EOF'
cat diff.patch
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Delete diff file
if: ${{ inputs.save-diff-to-file == 'false' }}
shell: bash
run: rm diff.patch
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: ${{ github.event_name == 'pull_request' && inputs.post-comment-on-pr == 'true' }}
with:
github-token: ${{ github.token }}
script: |
// 1. Retrieve existing bot comments for the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('### dstlled-diff')
})
// 2. Prepare format of the comment
const output = `### dstlled-diff
> ${{ steps.shorten-hashes.outputs.start }}..${{ steps.shorten-hashes.outputs.end }} -- ${{ inputs.pattern }}
<details><summary> expand </summary>
\`\`\`diff\n
${{ steps.gen-diff.outputs.diff }}
\`\`\`
</details>`;
// 3. If we have a comment, update it, otherwise create a new one
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}