PR Reviewdog #664
This file contains hidden or 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: PR Reviewdog | |
| on: | |
| workflow_run: | |
| workflows: | |
| - "Lint content" | |
| types: | |
| - completed | |
| permissions: | |
| # Download artifact from lint workflow. | |
| actions: read | |
| # Post inline review comments via reviewdog. | |
| pull-requests: write | |
| # Report commit status. | |
| statuses: write | |
| jobs: | |
| reviewdog: | |
| runs-on: ubuntu-latest | |
| env: | |
| STATUS_PATH: repos/${{ github.repository }}/statuses/${{ github.event.workflow_run.head_sha }} | |
| STATUS_CONTEXT: ${{ github.workflow }} | |
| STATUS_TARGET: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| steps: | |
| - name: Mark status as pending | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api "$STATUS_PATH" \ | |
| -f state=pending \ | |
| -f context="$STATUS_CONTEXT" \ | |
| -f description='Running' \ | |
| -f target_url="$STATUS_TARGET" | |
| - name: Identify PR | |
| id: identify-pr | |
| env: | |
| BASE_REPO: ${{ github.repository }} | |
| GITHUB_TOKEN: ${{ github.token }} | |
| HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }} | |
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | |
| run: | | |
| PR_NUMBER=$(gh api "repos/$HEAD_REPO/commits/$HEAD_SHA/pulls" \ | |
| --jq ".[] | select(.base.repo.full_name == \"$BASE_REPO\") | .number") | |
| echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT | |
| - name: Download artifact | |
| if: steps.identify-pr.outputs.number | |
| continue-on-error: true | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: lint-results | |
| path: lint-results | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Check for artifact | |
| id: check | |
| if: steps.identify-pr.outputs.number && hashFiles('lint-results/') != '' | |
| run: echo "HAS_ARTIFACT=true" >> "$GITHUB_OUTPUT" | |
| - name: Checkout | |
| if: steps.identify-pr.outputs.number | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| path: mdn-translated-content | |
| ref: main | |
| persist-credentials: false | |
| - name: Setup reviewdog | |
| if: steps.check.outputs.HAS_ARTIFACT == 'true' | |
| uses: reviewdog/action-setup@d8a7baabd7f3e8544ee4dbde3ee41d0011c3a93f # v1.5.0 | |
| with: | |
| reviewdog_version: latest | |
| - name: Add PR review with suggested changes using `git diff` output | |
| if: steps.check.outputs.HAS_ARTIFACT == 'true' && hashFiles('lint-results/lint.diff') != '' | |
| working-directory: mdn-translated-content | |
| env: | |
| CI_PULL_REQUEST: ${{ steps.identify-pr.outputs.number }} | |
| CI_COMMIT: ${{ github.event.workflow_run.head_sha }} | |
| CI_REPO_OWNER: ${{ github.repository_owner }} | |
| CI_REPO_NAME: ${{ github.event.repository.name }} | |
| CI_BRANCH: ${{ github.event.workflow_run.head_branch }} | |
| REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| env -u GITHUB_ACTIONS reviewdog \ | |
| -guess \ | |
| -name="mdn-linter" \ | |
| -f=diff \ | |
| -f.diff.strip=1 \ | |
| -filter-mode=diff_context \ | |
| -reporter=github-pr-review < ../lint-results/lint.diff | |
| - name: Add PR review with comments for errors in markdownlint output | |
| if: steps.check.outputs.HAS_ARTIFACT == 'true' && hashFiles('lint-results/markdownlint.log') != '' | |
| working-directory: mdn-translated-content | |
| env: | |
| CI_PULL_REQUEST: ${{ steps.identify-pr.outputs.number }} | |
| CI_COMMIT: ${{ github.event.workflow_run.head_sha }} | |
| CI_REPO_OWNER: ${{ github.repository_owner }} | |
| CI_REPO_NAME: ${{ github.event.repository.name }} | |
| CI_BRANCH: ${{ github.event.workflow_run.head_branch }} | |
| REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| env -u GITHUB_ACTIONS reviewdog \ | |
| -efm="%f:%l:%c %m" \ | |
| -efm="%f:%l %m" \ | |
| -name="markdownlint" \ | |
| -diff="git diff" \ | |
| -reporter="github-pr-review" < ../lint-results/markdownlint.log | |
| - name: Mark status as success | |
| if: success() | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api "$STATUS_PATH" \ | |
| -f state=success \ | |
| -f context="$STATUS_CONTEXT" \ | |
| -f description='Successful' \ | |
| -f target_url="$STATUS_TARGET" | |
| - name: Mark status as failure | |
| if: failure() | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api "$STATUS_PATH" \ | |
| -f state=failure \ | |
| -f context="$STATUS_CONTEXT" \ | |
| -f description='Failing' \ | |
| -f target_url="$STATUS_TARGET" |