|
| 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