Skip to content

Auto-update pre-commit hooks #543

Auto-update pre-commit hooks

Auto-update pre-commit hooks #543

Workflow file for this run

# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
name: pre-commit
on:
workflow_dispatch:
pull_request:
push:
permissions:
contents: read
jobs:
pre-commit-push:
name: Pre-Commit check on Push
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
permissions:
contents: read
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Python
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: 3.13
# We wish to run pre-commit on all files instead of the changes
# only made in the push commit.
#
# So linting error persists when there's formatting problem.
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
pre-commit-pr:
name: Pre-Commit check on PR
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request_target' }}
permissions:
contents: read
checks: write
issues: write
pull-requests: write
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
# pull_request_target checkout the base of the repo
# We need to checkout the actual pr to lint the changes.
- name: Checkout pr
run: gh pr checkout ${{ github.event.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: 3.13
# we only lint on the changed file in PR.
- name: Get Changed Files
id: changed-files
uses: step-security/changed-files@2e07db73e5ccdb319b9a6c7766bd46d39d304bad # v47.0.5
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
id: run-pre-commit
with:
extra_args: --files ${{ steps.changed-files.outputs.all_changed_files }}
# Review dog posts the suggested change from pre-commit to the pr.
- name: suggester / pre-commit
uses: reviewdog/action-suggester@2558ba17e65a9039e73764a73009fc05fef28a46 #v1.24.3
if: ${{ failure() && steps.run-pre-commit.conclusion == 'failure' }}
with:
tool_name: pre-commit
level: warning
reviewdog_flags: "-fail-level=error"