Skip to content

Commit bb50a32

Browse files
committed
apply feedback
1 parent 74bc8c7 commit bb50a32

File tree

1 file changed

+88
-48
lines changed

1 file changed

+88
-48
lines changed
Lines changed: 88 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,112 @@
1-
name: Nav Validator
1+
name: Check Documentation URL Changes
2+
3+
24
on:
35
pull_request:
46
branches:
57
- master
8+
9+
610
jobs:
7-
check-doc-nav-changes:
11+
check-url-changes:
812
runs-on: ubuntu-latest
913
steps:
10-
- name: Checkout PR branch
14+
- name: Checkout code
1115
uses: actions/checkout@v4
1216
with:
13-
fetch-depth: 1
14-
ref: ${{ github.event.pull_request.head.ref }}
15-
repository: ${{ github.event.pull_request.head.repo.full_name }}
16-
- name: Fetch base branch
17-
run: git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
18-
- name: Identify .md and .nav changes
17+
fetch-depth: 0
18+
19+
20+
- name: Identify deleted and renamed files
1921
run: |
20-
BASE=origin/${{ github.event.pull_request.base.ref }}
21-
HEAD=${{ github.event.pull_request.head.sha }}
22-
23-
# Markdown changes
24-
DELETED_MD=$(git diff --name-status $BASE $HEAD | grep '^D.*\.md$' | cut -f2- || true)
25-
RENAMED_MD=$(git diff --name-status $BASE $HEAD | grep '^R.*\.md$' | awk '{print $2 " -> " $3}' || true)
26-
27-
# Nav changes
28-
DELETED_NAV=$(git diff --name-status $BASE $HEAD | grep '^D.*\.nav\.ya?ml$' | cut -f2- || true)
29-
MODIFIED_NAV=$(git diff --name-status $BASE $HEAD | grep -E '^[AM].*\.nav\.ya?ml$' | cut -f2- || true)
30-
RENAMED_NAV=$(git diff --name-status $BASE $HEAD | grep '^R.*\.nav\.ya?ml$' | awk '{print $2 " -> " $3}' || true)
31-
32-
NAV_CHANGES=""
33-
for f in $DELETED_NAV; do NAV_CHANGES+="$f: [DELETED]\n\n"; done
34-
for f in $MODIFIED_NAV; do DIFF=$(git diff $BASE $HEAD -- "$f" | grep -E '^[+-]' | grep -vE '^\+\+\+|^---'); NAV_CHANGES+="$f:\n$DIFF\n\n"; done
35-
for f in $RENAMED_NAV; do NAV_CHANGES+="$f [RENAMED]\n\n"; done
36-
echo "DELETED_MD<<EOF" >> $GITHUB_ENV
37-
echo "$DELETED_MD" >> $GITHUB_ENV
38-
echo "EOF" >> $GITHUB_ENV
39-
echo "RENAMED_MD<<EOF" >> $GITHUB_ENV
40-
echo "$RENAMED_MD" >> $GITHUB_ENV
22+
BASE_REF=origin/${{ github.event.pull_request.base.ref }}
23+
HEAD_SHA=${{ github.event.pull_request.head.sha }}
24+
25+
26+
DELETED_FILES=$(git diff --name-status "$BASE_REF" "$HEAD_SHA" | grep '^D.*\.md$' | cut -f2- || true)
27+
RENAMED_FILES=$(git diff --name-status "$BASE_REF" "$HEAD_SHA" | grep '^R.*\.md$' | awk '{print $2 " -> " $3}' || true)
28+
29+
30+
NAV_FILES=$(git diff --name-only "$BASE_REF" "$HEAD_SHA" -- '*.nav.yml' '*.nav.yaml' || true)
31+
if [ -n "$NAV_FILES" ]; then
32+
while IFS= read -r nav_file; do
33+
[ -z "$nav_file" ] && continue
34+
NAV_DELETED_LINES=$(git diff "$BASE_REF" "$HEAD_SHA" -- "$nav_file" | grep '^-' | grep '\.md' | cut -c2- || true)
35+
NAV_ADDED_LINES=$(git diff "$BASE_REF" "$HEAD_SHA" -- "$nav_file" | grep '^+' | grep '\.md' | cut -c2- || true)
36+
37+
38+
if [ -n "$NAV_DELETED_LINES" ]; then
39+
while IFS= read -r line; do
40+
[ -z "$line" ] && continue
41+
entry="$nav_file: ${line# }"
42+
DELETED_FILES="${DELETED_FILES:+$DELETED_FILES"$'\n'"}$entry"
43+
done <<< "$NAV_DELETED_LINES"
44+
fi
45+
46+
47+
if [ -n "$NAV_ADDED_LINES" ]; then
48+
while IFS= read -r line; do
49+
[ -z "$line" ] && continue
50+
entry="$nav_file: ${line# }"
51+
RENAMED_FILES="${RENAMED_FILES:+$RENAMED_FILES"$'\n'"}$entry"
52+
done <<< "$NAV_ADDED_LINES"
53+
fi
54+
done <<< "$NAV_FILES"
55+
fi
56+
57+
58+
echo "DELETED_FILES<<EOF" >> $GITHUB_ENV
59+
echo "$DELETED_FILES" >> $GITHUB_ENV
4160
echo "EOF" >> $GITHUB_ENV
42-
echo "NAV_CHANGES<<EOF" >> $GITHUB_ENV
43-
echo -e "$NAV_CHANGES" >> $GITHUB_ENV
61+
62+
63+
echo "RENAMED_FILES<<EOF" >> $GITHUB_ENV
64+
echo "$RENAMED_FILES" >> $GITHUB_ENV
4465
echo "EOF" >> $GITHUB_ENV
45-
if [ -n "$DELETED_MD$RENAMED_MD$NAV_CHANGES" ]; then
66+
67+
68+
if [ -n "$DELETED_FILES" ] || [ -n "$RENAMED_FILES" ]; then
4669
echo "warning=true" >> $GITHUB_ENV
4770
else
4871
echo "warning=false" >> $GITHUB_ENV
4972
fi
50-
- name: Post PR comment if relevant
73+
74+
75+
echo "Deleted files:"
76+
echo "$DELETED_FILES"
77+
echo -e "\nRenamed/Moved files:"
78+
echo "$RENAMED_FILES"
79+
80+
81+
- name: Post PR warning
5182
if: env.warning == 'true'
5283
uses: actions/github-script@v7
5384
with:
5485
github-token: ${{ secrets.GITHUB_TOKEN }}
5586
script: |
56-
const deletedMd = `${process.env.DELETED_MD}`.trim();
57-
const renamedMd = `${process.env.RENAMED_MD}`.trim();
58-
const navChanges = `${process.env.NAV_CHANGES}`.trim();
59-
60-
let message = "🔍 **Documentation & Navigation Checker**\n\nThis PR modifies `.md` or `.nav.yml` files.\n\n";
61-
if (deletedMd) message += `**Deleted Markdown files:**\n\`\`\`\n${deletedMd}\n\`\`\`\n\n`;
62-
if (renamedMd) message += `**Renamed Markdown files:**\n\`\`\`\n${renamedMd}\n\`\`\`\n\n`;
63-
if (navChanges) message += `**Navigation file changes:**\n\`\`\`\n${navChanges}\n\`\`\`\n\n`;
64-
65-
message += "🚨 Please verify links remain valid and any deleted or renamed entries are handled.🚨 ";
66-
67-
github.rest.issues.createComment({
87+
const deletedFiles = `${process.env.DELETED_FILES}`.trim();
88+
const renamedFiles = `${process.env.RENAMED_FILES}`.trim();
89+
const sections = [];
90+
91+
92+
if (deletedFiles) {
93+
sections.push(`**Deleted Markdown files:**\n\`\`\`\n${deletedFiles}\n\`\`\``);
94+
}
95+
96+
97+
if (renamedFiles) {
98+
sections.push(`**Renamed Markdown files:**\n\`\`\`\n${renamedFiles}\n\`\`\``);
99+
}
100+
101+
102+
if (!sections.length) {
103+
return;
104+
}
105+
106+
107+
await github.rest.issues.createComment({
68108
owner: context.repo.owner,
69109
repo: context.repo.repo,
70110
issue_number: context.payload.pull_request.number,
71-
body: message
72-
});
111+
body: sections.join('\n\n')
112+
});

0 commit comments

Comments
 (0)