pre_commit_suggestions.yaml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. # 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@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
  33. with:
  34. egress-policy: audit
  35. - uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v1.3.0
  36. with:
  37. reviewdog_version: latest
  38. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  39. - name: Download pre-commit output
  40. uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
  41. with:
  42. name: pre-commit output
  43. github-token: ${{ secrets.GITHUB_TOKEN }}
  44. run-id: ${{ github.event.workflow_run.id }}
  45. # Use https://github.com/reviewdog/reviewdog to create PR suggestions
  46. # matching the diff that pre-commit created.
  47. - name: Create suggestions
  48. env:
  49. REVIEWDOG_GITHUB_API_TOKEN:
  50. ${{ secrets.CARBON_INFRA_BOT_FOR_REVIEWDOG }}
  51. run: |
  52. cat ./diff | \
  53. GITHUB_EVENT_PATH=./event \
  54. reviewdog -f=diff -f.diff.strip=1 -reporter=github-pr-review
  55. delete-stale-suggestions:
  56. if: github.event.workflow_run.event == 'pull_request'
  57. runs-on: ubuntu-latest
  58. steps:
  59. - name: Harden Runner
  60. uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0
  61. with:
  62. egress-policy: audit
  63. - name: Delete stale suggestions
  64. uses: Ardiannn08/resolve-outdated-comment@3b3cf4b2651a84fac2d6a94c2aeca9ac7c05ac5f # v1.3
  65. with:
  66. token: ${{ secrets.CARBON_INFRA_BOT_FOR_REVIEWDOG }}
  67. filter-user: 'CarbonInfraBot'
  68. mode: 'delete'