pre_commit_suggestions.yaml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. - name: Download pre-commit output
  30. uses: actions/download-artifact@v4
  31. with:
  32. name: pre-commit output
  33. github-token: ${{ secrets.GITHUB_TOKEN }}
  34. run-id: ${{ github.event.workflow_run.id }}
  35. # Use https://github.com/tido64/suggestion-bot to create PR suggestions
  36. # matching the diff that pre-commit created.
  37. - name: Create suggestions
  38. env:
  39. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  40. run: |
  41. GITHUB_EVENT_PATH=./event cat ./diff | \
  42. npx suggestion-bot -f -m "pre-commit checks made changes to the following files:"