|
1 | 1 | name: Navigation File Change Checker |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
| 4 | + pull_request_target: |
5 | 5 | branches: |
6 | | - - url-test # target branch |
| 6 | + - url-test # target branch |
7 | 7 | paths: |
8 | | - - '**/.nav.yml' |
| 8 | + - '**/*.nav.yml' |
| 9 | + - '**/*.nav.yaml' |
9 | 10 |
|
10 | 11 | jobs: |
11 | 12 | check-nav-changes: |
12 | 13 | runs-on: ubuntu-latest |
13 | 14 | steps: |
14 | | - # 1️⃣ Checkout the PR branch safely (fork-safe) |
15 | | - - name: Checkout PR |
| 15 | + # 1️⃣ Checkout the PR branch (fork-safe) |
| 16 | + - name: Checkout PR branch |
16 | 17 | uses: actions/checkout@v4 |
17 | 18 | with: |
18 | 19 | fetch-depth: 0 |
19 | 20 | ref: ${{ github.event.pull_request.head.ref }} |
20 | 21 | repository: ${{ github.event.pull_request.head.repo.full_name }} |
21 | 22 |
|
22 | | - # 2️⃣ Identify nav file changes |
| 23 | + # 2️⃣ Fetch the base branch so git diff works |
| 24 | + - name: Fetch base branch |
| 25 | + run: | |
| 26 | + git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1 |
| 27 | +
|
| 28 | + # 3️⃣ Detect nav file changes |
23 | 29 | - name: Detect nav file changes |
24 | 30 | run: | |
| 31 | + BASE_BRANCH=origin/${{ github.event.pull_request.base.ref }} |
| 32 | + HEAD_SHA=${{ github.event.pull_request.head.sha }} |
| 33 | +
|
25 | 34 | # Deleted nav files |
26 | | - DELETED_NAV=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep '^D.*\.nav\.ya?ml$' | cut -f2- || true) |
| 35 | + DELETED_NAV=$(git diff --name-status $BASE_BRANCH $HEAD_SHA | grep '^D.*\.nav\.ya?ml$' | cut -f2- || true) |
27 | 36 |
|
28 | 37 | # Added or modified nav files |
29 | | - MODIFIED_NAV=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep -E '^[AM].*\.nav\.ya?ml$' | cut -f2- || true) |
| 38 | + MODIFIED_NAV=$(git diff --name-status $BASE_BRANCH $HEAD_SHA | grep -E '^[AM].*\.nav\.ya?ml$' | cut -f2- || true) |
30 | 39 |
|
31 | 40 | NAV_CHANGES="" |
32 | 41 |
|
|
37 | 46 |
|
38 | 47 | # Process added or modified files |
39 | 48 | for FILE in $MODIFIED_NAV; do |
40 | | - DIFF=$(git diff origin/master ${{ github.event.pull_request.head.sha }} -- "$FILE" | grep -vE '^\+\+\+|^---' || true) |
| 49 | + DIFF=$(git diff $BASE_BRANCH $HEAD_SHA -- "$FILE" | grep -vE '^\+\+\+|^---' || true) |
41 | 50 | NAV_CHANGES+="$FILE:\n$DIFF\n\n" |
42 | 51 | done |
43 | 52 |
|
|
56 | 65 | # Debug output |
57 | 66 | echo -e "NAV file changes detected:\n$NAV_CHANGES" |
58 | 67 |
|
59 | | - # 3️⃣ Post PR comment if changes exist |
| 68 | + # 4️⃣ Post a comment if changes exist |
60 | 69 | - name: Post PR comment |
61 | 70 | if: env.warning == 'true' |
62 | 71 | uses: actions/github-script@v7 |
|
0 commit comments