Skip to content

Commit 7a8a7a4

Browse files
committed
[GH] Unused partials workflow
1 parent 9fad7dd commit 7a8a7a4

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

.github/workflows/image-audit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
id: find-files
2424
run: |
2525
# Find all .png and .svg files, but only look in the ./src/assets/images directory
26-
FILES=$(find . -type f \( -name "*.png" -o -name "*.svg" \) -path "./src/assets/images/*" -not -path "./src/assets/images/workers-ai/*.svg" -not -path "./src/assets/images/workers/ai/*.png" -not -path "./src/assets/images/changelog/*")
26+
FILES=$(find . -type f \( -name "*.png" -o -name "*.svg" \) -path "./src/assets/images/*" -not -path "./src/assets/images/workers-ai/*.svg" -not -path "./src/assets/images/workers/ai/*.png")
2727
2828
# Check if files are referenced in any markdown file
2929
UNUSED_FILES=""
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Partials audit
2+
3+
# **What it does**: Regularly audits our documentation for unused partials files.
4+
# **Why we have it**: Good hygiene + helps simplify future content audits.
5+
# **Who does it impact**: PCX team
6+
7+
on:
8+
workflow_dispatch:
9+
schedule:
10+
- cron: "0 0 1 * *"
11+
pull_request:
12+
branches:
13+
- production
14+
15+
jobs:
16+
partials-audit:
17+
permissions:
18+
issues: write
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout Repository
23+
uses: actions/checkout@v4
24+
25+
- name: Find Unused Partials
26+
id: find-partials
27+
run: |
28+
# Find all partials files
29+
FILES=$(find src/content/partials -type f -name "*.mdx")
30+
31+
# Check if files are referenced in any markdown file via Render components
32+
UNUSED_FILES=""
33+
for FILE in $FILES; do
34+
# Get the relative path from src/content/partials/
35+
RELATIVE_PATH=${FILE#src/content/partials/}
36+
# Get the filename without extension
37+
FILENAME=$(basename "$RELATIVE_PATH" .mdx)
38+
# Get the product directory (first part of the path)
39+
PRODUCT_DIR=$(dirname "$RELATIVE_PATH")
40+
41+
FOUND=false
42+
43+
# Search for Render components that reference this file
44+
# Look for files with explicit product parameter matching our product directory
45+
if grep -q -r -E "<Render[^>]*file=\"$FILENAME\"[^>]*product=\"$PRODUCT_DIR\"" --include="*.mdx" .; then
46+
FOUND=true
47+
fi
48+
49+
# Look for files with explicit product parameter matching our product directory (reverse order)
50+
if grep -q -r -E "<Render[^>]*product=\"$PRODUCT_DIR\"[^>]*file=\"$FILENAME\"" --include="*.mdx" .; then
51+
FOUND=true
52+
fi
53+
54+
# Look for files without product parameter in matching docs directory
55+
if grep -l -r -E "<Render[^>]*file=\"$FILENAME\"" --include="*.mdx" src/content/docs/$PRODUCT_DIR/ 2>/dev/null | grep -v -E "product=" | head -1 >/dev/null 2>&1; then
56+
FOUND=true
57+
fi
58+
59+
if [ "$FOUND" = false ]; then
60+
UNUSED_FILES+="$FILE\n"
61+
fi
62+
done
63+
64+
# If there are unused files, output them
65+
if [ -n "$UNUSED_FILES" ]; then
66+
echo "unused_files=$UNUSED_FILES" >> "$GITHUB_OUTPUT"
67+
fi
68+
69+
- name: Create Issue if Unused Files Found
70+
if: steps.find-partials.outputs.unused_files
71+
env:
72+
UNUSED_FILES: ${{ steps.find-partials.outputs.unused_files }}
73+
run: |
74+
# Create the issue and reference the unused_files variable
75+
echo "The following files are not referenced in any markdown file:\n${UNUSED_FILES}" > unused_files.txt
76+
curl --silent -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
77+
-H "Accept: application/vnd.github+json" \
78+
"https://api.github.com/repos/cloudflare/cloudflare-docs/issues" \
79+
-d "{\"title\": \"Unused Image Files Found\", \"body\": \"$(cat unused_files.txt)\", \"assignees\": [\"haleycode\"]}"

0 commit comments

Comments
 (0)