Skip to content

Commit 095de6e

Browse files
authored
added post PR reviews (#34)
* added post PR reviews * fixed value error causing typo * added action to create/upload suggestions and added workflow call * removed worklflow call in post-pr-reviews * added referenced action * changes action path * change to ation dir only * added workflow_call * removed trigger in post PR review * added remote action and workflow trigger * commented condition for workflow run
1 parent 6c37f42 commit 095de6e

2 files changed

Lines changed: 104 additions & 3 deletions

File tree

.github/workflows/linting.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ jobs:
145145
- name: Check code style with Black
146146
run: |
147147
black --check --diff --line-length 79 .
148+
- name: Create and upload code suggestions to apply for black
149+
id: diff-black
150+
uses: OSGeo/grass/.github/actions/create-upload-suggestions@main
151+
with:
152+
tool-name: black
153+
# extra-upload-changes: .clang-format
148154
ruff:
149155
name: ruff
150156
if: ${{ inputs.ruff-version != '' }}
@@ -164,9 +170,20 @@ jobs:
164170
run: |
165171
echo "ruff.toml does not exists. Will be downloaded."
166172
wget https://raw.githubusercontent.com/mundialis/github-workflows/main/linting-config-examples/ruff.toml
167-
- name: Lint with ruff
168-
run: |
169-
ruff check --config ruff.toml .
173+
- name: Run ruff (output annotations on fixable errors)
174+
run: |
175+
ruff check --config ruff.toml --output-format=github . --preview --unsafe-fixes
176+
continue-on-error: true
177+
- name: Run ruff (apply fixes for suggestions)
178+
run: |
179+
ruff check --config ruff.toml . --preview --fix --unsafe-fixes
180+
- name: Create and upload code suggestions to apply for ruff
181+
id: diff-ruff
182+
if: ${{ !cancelled() }}
183+
uses: OSGeo/grass/.github/actions/create-upload-suggestions@main
184+
with:
185+
tool-name: ruff
186+
# extra-upload-changes: ruff.toml
170187
super-linter:
171188
name: super-linter
172189
runs-on: ubuntu-latest
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# from https://github.com/OSGeo/grass/blob/main/.github/workflows/post-pr-reviews.yml and slightly modified
2+
---
3+
name: Post PR code suggestions
4+
5+
on:
6+
workflow_call:
7+
8+
permissions: {}
9+
jobs:
10+
post-suggestions:
11+
runs-on: ubuntu-latest
12+
# Only run on failures, since no changes are needed on success
13+
# if: >
14+
# (github.event.workflow_run.event == 'pull_request' &&
15+
# github.event.workflow_run.conclusion == 'failure')
16+
permissions:
17+
pull-requests: write
18+
steps:
19+
- name: Create a .git directory needed by reviewdog
20+
run: git init
21+
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
22+
id: diff
23+
continue-on-error: true
24+
with:
25+
name: diff
26+
github-token: ${{ github.token }}
27+
run-id: ${{github.event.workflow_run.id }}
28+
- uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v1.3.0
29+
- name: Check what tools have suggestions to post
30+
# Using this pattern to have expected file names explicitly named
31+
id: tools
32+
run: |
33+
for tool_name in $INPUT_TOOL_NAMES
34+
do
35+
INPUT_TOOL_NAME_FILE="diff-${tool_name}.patch"
36+
echo "Checking if tool ${tool_name} left suggestions in ${INPUT_TOOL_NAME_FILE}..."
37+
if [[ -f "${INPUT_TOOL_NAME_FILE}" ]]; then
38+
echo " ${INPUT_TOOL_NAME_FILE} was found for tool ${tool_name}"
39+
echo "$tool_name=true" >> "${GITHUB_OUTPUT}"
40+
else
41+
echo " ${INPUT_TOOL_NAME_FILE} was not found for tool ${tool_name}"
42+
echo "$tool_name=false" >> "${GITHUB_OUTPUT}"
43+
fi
44+
done
45+
env:
46+
INPUT_TOOL_NAMES: >-
47+
black
48+
ruff
49+
- name: Post black suggestions
50+
if: ${{ steps.tools.outputs.black == 'true' }}
51+
run: |
52+
TMPFILE="diff-${INPUT_TOOL_NAME}.patch"
53+
GITHUB_ACTIONS="" reviewdog \
54+
-name="${INPUT_TOOL_NAME:-reviewdog-suggester}" \
55+
-f=diff \
56+
-f.diff.strip=1 \
57+
-filter-mode=nofilter \
58+
-guess \
59+
-reporter="github-pr-review" < "${TMPFILE}"
60+
env:
61+
INPUT_TOOL_NAME: black
62+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
CI_COMMIT: ${{ github.event.workflow_run.head_sha }}
64+
CI_REPO_OWNER: ${{ github.event.workflow_run.repository.owner.login }}
65+
CI_REPO_NAME: ${{ github.event.workflow_run.repository.name }}
66+
# CI_PULL_REQUEST: "" # Populated from reviewdog's "-guess" flag since hard to get
67+
- name: Post ruff suggestions
68+
if: ${{ steps.tools.outputs.ruff == 'true' }}
69+
run: |
70+
TMPFILE="diff-${INPUT_TOOL_NAME}.patch"
71+
GITHUB_ACTIONS="" reviewdog \
72+
-name="${INPUT_TOOL_NAME:-reviewdog-suggester}" \
73+
-f=diff \
74+
-f.diff.strip=1 \
75+
-filter-mode=nofilter \
76+
-guess \
77+
-reporter="github-pr-review" < "${TMPFILE}"
78+
env:
79+
INPUT_TOOL_NAME: ruff
80+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
CI_COMMIT: ${{ github.event.workflow_run.head_sha }}
82+
CI_REPO_OWNER: ${{ github.event.workflow_run.repository.owner.login }}
83+
CI_REPO_NAME: ${{ github.event.workflow_run.repository.name }}
84+
# CI_PULL_REQUEST: "" # Populated from reviewdog's "-guess" flag since hard to get

0 commit comments

Comments
 (0)