Skip to content

Commit ea96e2e

Browse files
committed
Fix pre-commit workflow on forks
1 parent 5b39040 commit ea96e2e

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

.github/workflows/format.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,34 @@ on:
44
pull_request:
55
types: [opened, synchronize, reopened]
66

7+
permissions:
8+
contents: read
9+
710
jobs:
811
detect_changes:
912
runs-on: ubuntu-latest
1013
outputs:
1114
changed: ${{ steps.changed_files.outputs.changed }}
1215

1316
steps:
14-
- name: Checkout full history
17+
- name: Checkout PR
1518
uses: actions/checkout@v6
1619
with:
1720
fetch-depth: 0
21+
persist-credentials: false
1822

1923
- name: Detect changed files
2024
id: changed_files
2125
run: |
22-
git fetch origin ${{ github.base_ref }}
23-
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
26+
# git fetch origin ${{ github.base_ref }}
27+
# CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
28+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
29+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
30+
31+
echo "Base SHA: $BASE_SHA"
32+
echo "Head SHA: $HEAD_SHA"
33+
34+
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
2435
2536
{
2637
echo "changed<<EOF"
@@ -39,11 +50,12 @@ jobs:
3950
if: ${{ needs.detect_changes.outputs.changed != '' }}
4051

4152
steps:
42-
- name: Checkout PR branch
53+
- name: Checkout PR head commit
4354
uses: actions/checkout@v6
4455
with:
4556
fetch-depth: 0
46-
ref: ${{ github.head_ref }}
57+
ref: ${{ github.event.pull_request.head.sha }}
58+
persist-credentials: false
4759

4860
- name: Set up Python
4961
uses: actions/setup-python@v6

0 commit comments

Comments
 (0)