-
Notifications
You must be signed in to change notification settings - Fork 157
85 lines (84 loc) · 3.4 KB
/
post-pr-reviews.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: Post PR code suggestions
on:
workflow_run:
workflows: ["ClangFormat Check", "Python Black Formatting"]
types:
- completed
permissions: {}
jobs:
post-suggestions:
runs-on: ubuntu-latest
# Only run on failures, since no changes are needed on success
if: >
(github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure')
permissions:
pull-requests: write
steps:
- name: Create a .git directory needed by reviewdog
run: git init
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
id: diff
continue-on-error: true
with:
name: diff
github-token: ${{ github.token }}
run-id: ${{github.event.workflow_run.id }}
- uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v1.3.0
- name: Check what tools have suggestions to post
# Using this pattern to have expected file names explicitly named
id: tools
run: |
for tool_name in $INPUT_TOOL_NAMES
do
INPUT_TOOL_NAME_FILE="diff-${tool_name}.patch"
echo "Checking if tool ${tool_name} left suggestions in ${INPUT_TOOL_NAME_FILE}"
if [[ -f "${INPUT_TOOL_NAME_FILE}" ]]; then
echo "${INPUT_TOOL_NAME_FILE} was found for tool ${tool_name}"
echo "$tool_name=true" >> "${GITHUB_OUTPUT}"
else
echo "${INPUT_TOOL_NAME_FILE} was not found for tool ${tool_name}"
echo "$tool_name=false" >> "${GITHUB_OUTPUT}"
fi
done
env:
INPUT_TOOL_NAMES: >-
black
clang-format
- name: Post Black suggestions
if: ${{ steps.tools.outputs.black == 'true' }}
run: |
TMPFILE="diff-${INPUT_TOOL_NAME}.patch"
GITHUB_ACTIONS="" reviewdog \
-name="${INPUT_TOOL_NAME:-reviewdog-suggester}" \
-f=diff \
-f.diff.strip=1 \
-filter-mode=nofilter \
-guess \
-reporter="github-pr-review" < "${TMPFILE}"
env:
INPUT_TOOL_NAME: black
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CI_COMMIT: ${{ github.event.workflow_run.head_sha }}
CI_REPO_OWNER: ${{ github.event.workflow_run.repository.owner.login }}
CI_REPO_NAME: ${{ github.event.workflow_run.repository.name }}
# CI_PULL_REQUEST: "" # Populated from reviewdog's "-guess" flag since hard to get
- name: Post Clang-format suggestions
if: ${{ steps.tools.outputs.clang-format == 'true' }}
run: |
TMPFILE="diff-${INPUT_TOOL_NAME}.patch"
GITHUB_ACTIONS="" reviewdog \
-name="${INPUT_TOOL_NAME:-reviewdog-suggester}" \
-f=diff \
-f.diff.strip=1 \
-filter-mode=nofilter \
-guess \
-reporter="github-pr-review" < "${TMPFILE}"
env:
INPUT_TOOL_NAME: clang-format
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CI_COMMIT: ${{ github.event.workflow_run.head_sha }}
CI_REPO_OWNER: ${{ github.event.workflow_run.repository.owner.login }}
CI_REPO_NAME: ${{ github.event.workflow_run.repository.name }}
# CI_PULL_REQUEST: "" # Populated from reviewdog's "-guess" flag since hard to get