Submit linter suggestions #1599
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Submit linter suggestions' | |
on: | |
workflow_run: | |
workflows: ["C# linting", "Add Markdown Feedback"] | |
types: | |
- completed | |
permissions: {} | |
jobs: | |
submit-linter-suggestions: | |
if: > | |
${{ github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' }} | |
name: 'Submit linter suggestions' | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- name: 'Verify user is a collaborator' | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea | |
with: | |
script: | | |
await github.rest.repos.checkCollaborator({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
username: context.payload.workflow_run.triggering_actor.login | |
}); | |
- name: Checkout | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
persist-credentials: false | |
- name: Set C# Linting Env Vars | |
if: ${{ github.event.workflow_run.name == 'C# Linting' }} | |
run: | | |
echo 'reporter_name=dotnet format' >> $GITHUB_ENV | |
echo 'workflow_name=lint-csharp.yml' >> $GITHUB_ENV | |
- name: Set Append Markdown Feedback Env Vars | |
if: ${{ github.event.workflow_run.name == 'Add Markdown Feedback' }} | |
run: | | |
echo 'reporter_name=Add Markdown Feedback' >> $GITHUB_ENV | |
echo 'workflow_name=add-markdown-feedback.yml' >> $GITHUB_ENV | |
# Download the artifact from the workflow that kicked off this one. | |
# The default artifact download action doesn't support cross-workflow | |
# artifacts, so use a 3rd party one. | |
- name: 'Download linting results' | |
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 | |
with: | |
workflow: ${{env.workflow_name}} | |
run_id: ${{github.event.workflow_run.id }} | |
name: pr-linter | |
path: ./pr-linter | |
- name: 'Setup reviewdog' | |
uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 | |
# Manually supply the triggering PR event information since when a PR is from a fork, | |
# this workflow running in the base repo will not be given information about it. | |
# | |
# Also patch the fork's owner id in the event file, since reviewdog has as fail-fast path that | |
# checks the head vs base repo owner id to determine if the PR is from a fork. | |
# If so, it assumes that it doesn't have permissions to write comments on the PR. | |
# | |
# This isn't the case in our setup since we are using two workflows (lint-csharp and this one) | |
# to enable write permissions on fork PRs. | |
- name: Submit formatting suggestions | |
run: | | |
new_event_file=${{github.workspace}}/reviewdog_event.json | |
jq -j ".pull_request.head.repo.owner.id = .pull_request.base.repo.owner.id" ./pr-linter/pr-event.json > ${new_event_file} | |
GITHUB_EVENT_NAME="pull_request" GITHUB_EVENT_PATH="${new_event_file}" reviewdog \ | |
-name="$reporter_name" \ | |
-f=diff \ | |
-f.diff.strip=1 \ | |
-reporter="github-pr-review" \ | |
-filter-mode="diff_context" \ | |
-fail-on-error="false" \ | |
-level="warning" \ | |
< "./pr-linter/linter.diff" | |
env: | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} |