pre_commit_suggestions.yaml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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: 'Add 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. # Note reviewdog/reviewdog has its own token.
  20. permissions:
  21. contents: read # For actions/checkout.
  22. jobs:
  23. pull-request-suggestions:
  24. # Only generate suggestions if pre-commit for a PR failed.
  25. if: |
  26. github.event.workflow_run.conclusion == 'failure' &&
  27. github.event.workflow_run.event == 'pull_request' &&
  28. github.actor != 'jonmeow'
  29. runs-on: ubuntu-latest
  30. steps:
  31. - name: Harden Runner
  32. uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
  33. with:
  34. disable-sudo: true
  35. egress-policy: block
  36. # prettier-ignore
  37. allowed-endpoints: >
  38. api.github.com:443
  39. github.com:443
  40. objects.githubusercontent.com:443
  41. raw.githubusercontent.com:443
  42. - uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v1.3.0
  43. with:
  44. reviewdog_version: latest
  45. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  46. - name: Download pre-commit output
  47. uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
  48. with:
  49. name: pre-commit output
  50. github-token: ${{ secrets.GITHUB_TOKEN }}
  51. run-id: ${{ github.event.workflow_run.id }}
  52. # Use https://github.com/reviewdog/reviewdog to create PR suggestions
  53. # matching the diff that pre-commit created.
  54. - name: Create suggestions
  55. env:
  56. REVIEWDOG_GITHUB_API_TOKEN:
  57. ${{ secrets.CARBON_INFRA_BOT_FOR_REVIEWDOG }}
  58. run: |
  59. cat ./diff | \
  60. GITHUB_EVENT_PATH=./event \
  61. reviewdog -f=diff -f.diff.strip=1 -reporter=github-pr-review