DIY-aux #26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Validate Driver Documentation | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - 'src/content/docs/**' | |
| - 'public/images/**' | |
| jobs: | |
| validate-files: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '18' | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Validate driver documentation structure | |
| run: | | |
| # Check for one .md and one .yaml file per driver | |
| find src/content/docs -mindepth 2 -maxdepth 2 -type d | while read -r category_dir; do | |
| category_name=$(basename "$category_dir") | |
| find "$category_dir" -mindepth 1 -maxdepth 1 -type d | while read -r driver_dir; do | |
| driver_name=$(basename "$driver_dir") | |
| md_files=$(find "$driver_dir" -maxdepth 1 -type f -name "*.md" | wc -l) | |
| yaml_files=$(find "$driver_dir" -maxdepth 1 -type f -name "*.yaml" | wc -l) | |
| if [ "$md_files" -ne 1 ]; then | |
| echo "::error file=$driver_dir::Driver directory '$driver_dir' must contain exactly one .md file. Found $md_files." | |
| exit 1 | |
| fi | |
| if [ "$yaml_files" -ne 1 ]; then | |
| echo "::error file=$driver_dir::Driver directory '$driver_dir' must contain exactly one .yaml file. Found $yaml_files." | |
| exit 1 | |
| fi | |
| done | |
| done | |
| - name: Validate image formats | |
| run: | | |
| # Check driver thumbnails | |
| find src/content/docs -type f ! -name "*.webp" -print0 | while IFS= read -r -d $'\0' file; do | |
| echo "::error file=$file::Driver thumbnail '$file' must be in .webp format." | |
| exit 1 | |
| done | |
| # Check manufacturer logos | |
| find public/images/manufacturers -type f ! -name "*.webp" -print0 | while IFS= read -r -d $'\0' file; do | |
| echo "::error file=$file::Manufacturer logo '$file' must be in .webp format." | |
| exit 1 | |
| done | |
| # Check category icons | |
| find public/images/categories -type f ! -name "*.webp" -print0 | while IFS= read -r -d $'\0' file; do | |
| echo "::error file=$file::Category icon '$file' must be in .webp format." | |
| exit 1 | |
| done | |
| - name: Validate images exist | |
| run: | | |
| find src/content/docs -name "*.yaml" | while read -r yaml_file; do | |
| manufacturer=$(grep "Manufacturer:" "$yaml_file" | awk -F': ' '{print $2}' | tr -d '\r') | |
| if [ -n "$manufacturer" ]; then | |
| manufacturer_slug=$(echo "$manufacturer" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/--/-/g' | sed 's/^-//' | sed 's/-$//') | |
| manufacturer_image="public/images/manufacturers/${manufacturer_slug}.webp" | |
| if [ ! -f "$manufacturer_image" ]; then | |
| echo "::error file=$yaml_file::Manufacturer image for '$manufacturer' not found at '$manufacturer_image'." | |
| exit 1 | |
| fi | |
| else | |
| echo "::error file=$yaml_file::Manufacturer name not found in '$yaml_file'." | |
| exit 1 | |
| fi | |
| done | |
| find src/content/docs -name "*.md" | while read -r md_file; do | |
| category=$(grep "category:" "$md_file" | awk -F': ' '{print $2}' | tr -d '\r') | |
| if [ -n "$category" ]; then | |
| category_slug=$(echo "$category" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/--/-/g' | sed 's/^-//' | sed 's/-$//') | |
| category_image="public/images/categories/${category_slug}.webp" | |
| if [ ! -f "$category_image" ]; then | |
| echo "::error file=$md_file::Category image for '$category' not found at '$category_image'." | |
| exit 1 | |
| fi | |
| else | |
| echo "::error file=$md_file::Category name not found in '$md_file'." | |
| exit 1 | |
| fi | |
| thumbnail=$(grep "thumbnail:" "$md_file" | awk -F': ' '{print $2}' | tr -d '\r') | |
| title=$(grep "title:" "$md_file" | awk -F': ' '{print $2}' | tr -d '\r') | |
| if [ -n "$thumbnail" ]; then | |
| thumbnail_image="public${thumbnail}" | |
| if [ ! -f "$thumbnail_image" ]; then | |
| echo "::error file=$md_file::Thumbnail image for '$title' not found at '$thumbnail_image'." | |
| exit 1 | |
| fi | |
| else | |
| echo "::error file=$md_file::Thumbnail image not found in '$md_file'." | |
| exit 1 | |
| fi | |
| done |