Skip to content

[Apply lint] Add PR-only pre-commit workflow & lint all #2

[Apply lint] Add PR-only pre-commit workflow & lint all

[Apply lint] Add PR-only pre-commit workflow & lint all #2

Workflow file for this run

name: pre-commit (PR only on changed files)
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
detect_changes:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.changed_files.outputs.changed }}
steps:
- name: Checkout full history
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Detect changed files
id: changed_files
run: |
git fetch origin ${{ github.base_ref }}
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
echo "changed=$CHANGED_FILES" >> $GITHUB_OUTPUT
- name: Show changed files
run: |
echo "Changed files: ${{ steps.changed_files.outputs.changed }}"
precommit:
runs-on: ubuntu-latest
needs: detect_changes
if: ${{ needs.detect_changes.outputs.changed != '' }}
steps:
- name: Checkout PR branch
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit on changed files
run: pre-commit run --files ${{ needs.detect_changes.outputs.changed }}