Skip to content

Commit dfdcafd

Browse files
committed
nav
1 parent 924a92b commit dfdcafd

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

.github/workflows/check-url-changes.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
11
name: Navigation File Change Checker
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
branches:
6-
- url-test # target branch
6+
- url-test # target branch
77
paths:
8-
- '**/.nav.yml'
8+
- '**/*.nav.yml'
9+
- '**/*.nav.yaml'
910

1011
jobs:
1112
check-nav-changes:
1213
runs-on: ubuntu-latest
1314
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
1617
uses: actions/checkout@v4
1718
with:
1819
fetch-depth: 0
1920
ref: ${{ github.event.pull_request.head.ref }}
2021
repository: ${{ github.event.pull_request.head.repo.full_name }}
2122

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
2329
- name: Detect nav file changes
2430
run: |
31+
BASE_BRANCH=origin/${{ github.event.pull_request.base.ref }}
32+
HEAD_SHA=${{ github.event.pull_request.head.sha }}
33+
2534
# 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)
2736
2837
# 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)
3039
3140
NAV_CHANGES=""
3241
@@ -37,7 +46,7 @@ jobs:
3746
3847
# Process added or modified files
3948
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)
4150
NAV_CHANGES+="$FILE:\n$DIFF\n\n"
4251
done
4352
@@ -56,7 +65,7 @@ jobs:
5665
# Debug output
5766
echo -e "NAV file changes detected:\n$NAV_CHANGES"
5867
59-
# 3️⃣ Post PR comment if changes exist
68+
# 4️⃣ Post a comment if changes exist
6069
- name: Post PR comment
6170
if: env.warning == 'true'
6271
uses: actions/github-script@v7

0 commit comments

Comments
 (0)