pre_commit_suggestions.yaml 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. github.actor != 'jonmeow'
  28. runs-on: ubuntu-latest
  29. steps:
  30. - uses: reviewdog/action-setup@v1
  31. with:
  32. reviewdog_version: latest
  33. - uses: actions/checkout@v4
  34. - name: Download pre-commit output
  35. uses: actions/download-artifact@v4
  36. with:
  37. name: pre-commit output
  38. github-token: ${{ secrets.GITHUB_TOKEN }}
  39. run-id: ${{ github.event.workflow_run.id }}
  40. # Use https://github.com/reviewdog/reviewdog to create PR suggestions
  41. # matching the diff that pre-commit created.
  42. - name: Create suggestions
  43. env:
  44. REVIEWDOG_GITHUB_API_TOKEN:
  45. ${{ secrets.CARBON_INFRA_BOT_FOR_REVIEWDOG }}
  46. run: |
  47. cat ./diff | \
  48. GITHUB_EVENT_PATH=./event \
  49. reviewdog -f=diff -f.diff.strip=1 -reporter=github-pr-review