pre_commit_suggestions.yaml 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. runs-on: ubuntu-latest
  29. steps:
  30. - name: Harden Runner
  31. uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc # v2.15.1
  32. with:
  33. disable-sudo: true
  34. egress-policy: block
  35. # prettier-ignore
  36. allowed-endpoints: >
  37. api.github.com:443
  38. github.com:443
  39. objects.githubusercontent.com:443
  40. raw.githubusercontent.com:443
  41. - uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v1.3.0
  42. with:
  43. reviewdog_version: latest
  44. - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  45. - name: Download pre-commit output
  46. uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
  47. with:
  48. name: pre-commit output
  49. github-token: ${{ secrets.GITHUB_TOKEN }}
  50. run-id: ${{ github.event.workflow_run.id }}
  51. # Use https://github.com/reviewdog/reviewdog to create PR suggestions
  52. # matching the diff that pre-commit created.
  53. - name: Create suggestions
  54. env:
  55. REVIEWDOG_GITHUB_API_TOKEN:
  56. ${{ secrets.CARBON_INFRA_BOT_FOR_REVIEWDOG }}
  57. run: |
  58. cat ./diff | \
  59. GITHUB_EVENT_PATH=./event \
  60. reviewdog -f=diff -f.diff.strip=1 -reporter=github-pr-review