pre_commit.yaml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. name: pre-commit
  5. on:
  6. pull_request:
  7. merge_group:
  8. push:
  9. branches: [trunk]
  10. permissions:
  11. contents: read # For actions/checkout.
  12. jobs:
  13. pre-commit:
  14. runs-on: ubuntu-22.04
  15. steps:
  16. - name: Harden Runner
  17. uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc # v2.15.1
  18. with:
  19. egress-policy: block
  20. # When adding endpoints, see README.md.
  21. # prettier-ignore
  22. allowed-endpoints: >
  23. *.blob.storage.azure.net:443
  24. *.githubapp.com:443
  25. *.sourceforge.net:443
  26. api.github.com:443
  27. api.ipify.org:443
  28. bcr.bazel.build:443
  29. downloads.sourceforge.net:443
  30. files.pythonhosted.org:443
  31. github.com:443
  32. go.dev:443
  33. mirror.bazel.build:443
  34. mirrors.kernel.org:443
  35. nodejs.org:443
  36. oauth2.googleapis.com:443
  37. objects.githubusercontent.com:443
  38. pypi.org:443
  39. registry.npmjs.org:443
  40. release-assets.githubusercontent.com:443
  41. releases.bazel.build:443
  42. storage.googleapis.com:443
  43. uploads.github.com:443
  44. www.googleapis.com:443
  45. - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  46. - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
  47. # Ensure LLVM is set up consistently.
  48. - uses: ./.github/actions/build-setup-common
  49. with:
  50. matrix_runner: ubuntu-22.04
  51. remote_cache_upload: '--remote_upload_local_results=false'
  52. - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
  53. # We want to automatically create github suggestions for pre-commit file
  54. # changes for a pull request. But `pull_request` actions never have write
  55. # permissions to the repository, so we create the suggestions in a separate
  56. # privileged `workflow_run` action in pre_commit_suggestions.yaml. Here,
  57. # we upload the diffs and event configuration to an artifact for use by
  58. # that action.
  59. - name: Collect pre-commit output
  60. if: failure()
  61. run: |
  62. mkdir -p pre-commit-output
  63. git diff > pre-commit-output/diff
  64. cp $GITHUB_EVENT_PATH pre-commit-output/event
  65. - uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
  66. if: failure()
  67. with:
  68. name: pre-commit output
  69. path: pre-commit-output/*