Skip to content

Commit 04ca5ee

Browse files
committed
[GitHub] Unused partials check
1 parent 6b50f39 commit 04ca5ee

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Image audit
2+
3+
# **What it does**: Regularly audits our documentation for unused image files.
4+
# **Why we have it**: Good hygiene + helps simplify future image audits.
5+
# **Who does it impact**: PCX team
6+
7+
on:
8+
pull_request:
9+
branches:
10+
- production
11+
workflow_dispatch:
12+
schedule:
13+
- cron: "0 0 1 * *"
14+
15+
jobs:
16+
image-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 Files
26+
id: find-files
27+
run: |
28+
# Find all files in the partial folder
29+
FILES=$(find . -type f \( -name "*.mdx" -o -name "*.md" \) -path "./src/content/partials/*")
30+
31+
# Check if files are referenced in any Render component
32+
UNUSED_FILES=""
33+
for FILE in $FILES; do
34+
# Extract product and file name from the path
35+
PRODUCT=$(echo "$FILE" | awk -F'/' '{print $(NF-1)}')
36+
FILENAME=$(basename "$FILE" .mdx)
37+
38+
# Construct the individual search strings for product and file
39+
SEARCH_PRODUCT="product=\"$PRODUCT\""
40+
SEARCH_FILE="file=\"$FILENAME\""
41+
42+
# Use a chained grep to find lines containing BOTH strings, regardless of order
43+
if ! grep -q -r --exclude-dir=.github "$SEARCH_PRODUCT" --include="*.mdx" . | grep -q "$SEARCH_FILE"; then
44+
UNUSED_FILES+="$FILE\n"
45+
fi
46+
done
47+
48+
# If there are unused files, output them
49+
if [ -n "$UNUSED_FILES" ]; then
50+
echo "unused_files=$UNUSED_FILES" >> "$GITHUB_OUTPUT"
51+
fi

0 commit comments

Comments
 (0)