pre_commit_suggestions.yaml 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. # Create PR suggestions based on problems found by pre-commit action.
  5. name: pre-commit-suggestions
  6. # This action is run whenever the `pre-commit` action finishes. Because the
  7. # `pre-commit` action is an unprivileged action running on (for example) the
  8. # `pull_request` event, it's run without write permissions to the repository, so
  9. # we use a separate privileged `workflow_run` action here to pick up its results
  10. # and convert them into suggestion comments.
  11. #
  12. # This action is only run from the workflow file on the trunk branch. Changes to
  13. # this file will not take effect until they are merged to trunk.
  14. on:
  15. workflow_run:
  16. workflows: [pre-commit]
  17. types:
  18. - completed
  19. permissions:
  20. pull-requests: write
  21. jobs:
  22. pull-request-suggestions:
  23. # Only generate suggestions if pre-commit for a PR failed.
  24. if: |
  25. github.event.workflow_run.conclusion == 'failure' &&
  26. github.event.workflow_run.event == 'pull_request'
  27. runs-on: ubuntu-latest
  28. steps:
  29. - uses: reviewdog/action-setup@v1
  30. with:
  31. reviewdog_version: latest
  32. - uses: actions/checkout@v4
  33. - name: Download pre-commit output
  34. uses: actions/download-artifact@v4
  35. with:
  36. name: pre-commit output
  37. github-token: ${{ secrets.GITHUB_TOKEN }}
  38. run-id: ${{ github.event.workflow_run.id }}
  39. # Use https://github.com/reviewdog/reviewdog to create PR suggestions
  40. # matching the diff that pre-commit created.
  41. - name: Create suggestions
  42. env:
  43. REVIEWDOG_GITHUB_API_TOKEN:
  44. ${{ secrets.CARBON_INFRA_BOT_FOR_REVIEWDOG }}
  45. run: |
  46. cat ./diff | \
  47. GITHUB_EVENT_PATH=./event \
  48. reviewdog -f=diff -f.diff.strip=1 -reporter=github-pr-review