diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index a4ac5dea06..bf1741c3ec 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -12,7 +12,16 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} + + - name: Get changed files + id: changed-files + run: | + if ${{ github.event_name == 'pull_request' }}; then + echo "changed_files=$(git diff -diff-filter=ACMR --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT + else + echo "changed_files=$(git diff -diff-filter=ACMR --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT + fi - uses: actions/setup-python@v4 with: @@ -27,4 +36,4 @@ jobs: key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} - name: Lint - run: pre-commit run --files $(git diff --name-only --diff-filter=ACMR ${{ github.event.before }} ${{ github.event.after }}) + run: pre-commit run --files ${{ steps.changed-files.outputs.changed_files }}