This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
50 lines (41 loc) · 1.77 KB
/
precommit_checks.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This action is triggered when a pull request review is submitted.
# It will run precommit checks only when the pull request is approved.
# Reference: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-a-workflow-when-a-pull-request-is-approved
name: Run Precommit Checks on PR Approval
on:
workflow_dispatch:
push:
branches:
- main
pull_request_review:
types: [submitted]
jobs:
# This job runs the precommit checks on the changed files.
run_precommit_checks:
# Ensures the job only runs when the PR review state is "approved".
if: github.event.review.state == 'approved'
runs-on: ubuntu-22.04
steps:
# Checkout the repository to the GitHub Actions runner.
- name: Checkout Repository
uses: actions/checkout@v4
# Set up the desired Python environment.
- name: Setup Python Environment
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
# Install the required dependencies for local repos in the precommit hooks
- name: Install Dependencies from setup.py
run: pip install -e .[dev]
# Determine which python files have changed in the PR.
- name: Get Changed Files
id: changed-files
uses: tj-actions/changed-files@v42
with:
files: '**/*.py'
# Run the precommit hooks only on the changed files.
- name: Execute Precommit Hooks on Changed Files in PR
uses: pre-commit/action@v3.0.0
with:
extra_args: --files ${{ steps.changed-files.outputs.all_changed_files }}