Skip to content

Commit

Permalink
added post PR reviews (#34)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JHalbauer authored Nov 27, 2024
1 parent 6c37f42 commit 095de6e
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 3 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ jobs:
- name: Check code style with Black
run: |
black --check --diff --line-length 79 .
- name: Create and upload code suggestions to apply for black
id: diff-black
uses: OSGeo/grass/.github/actions/create-upload-suggestions@main
with:
tool-name: black
# extra-upload-changes: .clang-format
ruff:
name: ruff
if: ${{ inputs.ruff-version != '' }}
Expand All @@ -164,9 +170,20 @@ jobs:
run: |
echo "ruff.toml does not exists. Will be downloaded."
wget https://raw.githubusercontent.com/mundialis/github-workflows/main/linting-config-examples/ruff.toml
- name: Lint with ruff
run: |
ruff check --config ruff.toml .
- name: Run ruff (output annotations on fixable errors)
run: |
ruff check --config ruff.toml --output-format=github . --preview --unsafe-fixes
continue-on-error: true
- name: Run ruff (apply fixes for suggestions)
run: |
ruff check --config ruff.toml . --preview --fix --unsafe-fixes
- name: Create and upload code suggestions to apply for ruff
id: diff-ruff
if: ${{ !cancelled() }}
uses: OSGeo/grass/.github/actions/create-upload-suggestions@main
with:
tool-name: ruff
# extra-upload-changes: ruff.toml
super-linter:
name: super-linter
runs-on: ubuntu-latest
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/post-pr-reviews.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# from https://github.com/OSGeo/grass/blob/main/.github/workflows/post-pr-reviews.yml and slightly modified
---
name: Post PR code suggestions

on:
workflow_call:

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
ruff
- 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 ruff suggestions
if: ${{ steps.tools.outputs.ruff == '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: ruff
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

0 comments on commit 095de6e

Please sign in to comment.