Skip to content

[GitHub] Unused partials check #9

[GitHub] Unused partials check

[GitHub] Unused partials check #9

Workflow file for this run

name: Partial audit
# **What it does**: Regularly audits our documentation for unused image files.
# **Why we have it**: Good hygiene + helps simplify future image audits.
# **Who does it impact**: PCX team
on:
pull_request:
branches:
- production
workflow_dispatch:
schedule:
- cron: "0 0 1 * *"
jobs:
partial-audit:
permissions:
issues: write
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Find Unused Files
id: find-files
run: |
# Find all .mdx files, but only in the ./src/content/partials directory
FILES=$(find ./src/content/partials -type f -name "*.mdx")
# Check if files are referenced in any Render component
UNUSED_FILES=""
for FILE in $FILES; do
# Extract product and file name from the path
PRODUCT=$(echo "$FILE" | awk -F'/' '{print $(NF-1)}')
TEMP_PATH=${FILE#*src/content/partials/*/}
FILENAME=${TEMP_PATH%.mdx}
# Construct the individual search strings for product and file
SEARCH_PRODUCT="product=\"$PRODUCT\""
SEARCH_FILE="file=\"$FILENAME\""
# --- START LOGGING ---
echo "----------------------------------------"
echo "Checking file: $FILE"
echo " - SEARCH_PRODUCT: $SEARCH_PRODUCT"
echo " - SEARCH_FILE: $SEARCH_FILE"
# --- END LOGGING ---
# Use a chained grep to find lines containing BOTH strings, regardless of order
if ! grep -q -r --exclude-dir=.github --include="*.mdx" -e "$SEARCH_PRODUCT" -e "$SEARCH_FILE" .; then
UNUSED_FILES+="$FILE\n"
echo " -> UNUSED! Adding to list."
else
echo " -> Used. Skipping."
fi
echo "" # Add a blank line for readability
done
# If there are unused files, output them
if [ -n "$UNUSED_FILES" ]; then
echo "unused_files=$UNUSED_FILES" >> "$GITHUB_OUTPUT"
fi