Update Version Support Policy for 3.17 EoL #492
Workflow file for this run
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: Ensure nav is updated if files added/deleted | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| is-nav-updated: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get added and deleted .mdx files | |
| id: mdx-files | |
| run: | | |
| git fetch origin ${{ github.base_ref }} | |
| added_files="" | |
| deleted_files="" | |
| # Process added files - only include .mdx files | |
| while IFS= read -r file; do | |
| [ -z "$file" ] && continue | |
| [[ "$file" == *.mdx ]] || continue | |
| [[ "$file" == snippets/* ]] && continue | |
| [[ "$file" == api-reference/* ]] && continue | |
| [[ "$file" == custom/* ]] && continue | |
| [[ "$file" == errors/* ]] && continue | |
| added_files+="$file"$'\n' | |
| done < <(git diff --name-only --diff-filter=A origin/${{ github.base_ref }}...HEAD) | |
| # Process deleted files - only include .mdx files | |
| while IFS= read -r file; do | |
| [ -z "$file" ] && continue | |
| [[ "$file" == *.mdx ]] || continue | |
| [[ "$file" == snippets/* ]] && continue | |
| [[ "$file" == api-reference/* ]] && continue | |
| [[ "$file" == custom/* ]] && continue | |
| [[ "$file" == errors/* ]] && continue | |
| deleted_files+="$file"$'\n' | |
| done < <(git diff --name-only --diff-filter=D origin/${{ github.base_ref }}...HEAD) | |
| echo "added_files<<EOF" >> $GITHUB_OUTPUT | |
| echo "$added_files" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| echo "deleted_files<<EOF" >> $GITHUB_OUTPUT | |
| echo "$deleted_files" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Check docs.json updated | |
| run: | | |
| added_files="${{ steps.mdx-files.outputs.added_files }}" | |
| deleted_files="${{ steps.mdx-files.outputs.deleted_files }}" | |
| # Check if any .mdx files were added or deleted | |
| if [ -z "$added_files" ] && [ -z "$deleted_files" ]; then | |
| echo "No .mdx files were added or deleted in this PR." | |
| exit 0 | |
| fi | |
| # Filter out added files with noSidebar: true | |
| echo "Checking if the files you added have noSidebar: true in the frontmatter." | |
| filtered_added_files=() | |
| while IFS= read -r file; do | |
| if [ -z "$file" ]; then | |
| continue | |
| fi | |
| if git show HEAD:"$file" 2>/dev/null | grep -qE "^noSidebar:\s*true"; then | |
| echo "⊘ Ignoring $file (has noSidebar: true)" | |
| else | |
| filtered_added_files+=("$file") | |
| fi | |
| done <<< "$added_files" | |
| # Check if we have any files that need navigation updates | |
| if [ ${#filtered_added_files[@]} -eq 0 ] && [ -z "$deleted_files" ]; then | |
| echo "No .mdx files require navigation updates (all added files have noSidebar: true)." | |
| exit 0 | |
| fi | |
| # Check if docs.json was modified | |
| git fetch origin ${{ github.base_ref }} | |
| docs_json_changed=false | |
| if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q '^docs.json$'; then | |
| docs_json_changed=true | |
| fi | |
| if [ "$docs_json_changed" = false ]; then | |
| # docs.json was not changed, but we have added/deleted files | |
| # For deleted files, check if they were ever in navigation | |
| navigation_string=$(jq -c '.navigation' docs.json) | |
| files_in_nav_but_not_updated=() | |
| # Check if any deleted files exist in navigation | |
| while IFS= read -r file; do | |
| if [ -z "$file" ]; then | |
| continue | |
| fi | |
| path_without_ext="${file%.mdx}" | |
| if echo "$navigation_string" | grep -q "$path_without_ext"; then | |
| echo "::error file=$file::Deleted file exists in navigation but docs.json was not updated: $file" | |
| files_in_nav_but_not_updated+=("$file") | |
| else | |
| echo "⊘ Deleted file was never in navigation, skipping: $file" | |
| fi | |
| done <<< "$deleted_files" | |
| # If we have added files (after filtering) OR deleted files that were in navigation, fail | |
| if [ ${#filtered_added_files[@]} -gt 0 ] || [ ${#files_in_nav_but_not_updated[@]} -gt 0 ]; then | |
| echo "::error file=docs.json::docs.json was not updated, but .mdx files were added or deleted." | |
| echo "" | |
| echo "❌ The navigation array in docs.json must be updated when adding or deleting .mdx files. If you're creating a page that you don't want in the sidebar, add noSidebar: true to the frontmatter." | |
| exit 1 | |
| else | |
| echo "✓ All deleted files were never in navigation. No docs.json update required." | |
| exit 0 | |
| fi | |
| fi | |
| echo "docs.json was modified. Checking navigation array..." | |
| # Get navigation as a string for searching | |
| navigation_string=$(jq -c '.navigation' docs.json) | |
| missing_paths=() | |
| # Check added files - they should exist in navigation | |
| for file in "${filtered_added_files[@]}"; do | |
| # Remove .mdx extension | |
| path_without_ext="${file%.mdx}" | |
| echo "Checking if added file is in navigation: $path_without_ext" | |
| if echo "$navigation_string" | grep -q "$path_without_ext"; then | |
| echo "✓ Found in navigation: $file" | |
| else | |
| echo "::error file=$file::Added file not found in docs.json navigation: $file (expected: $path_without_ext)" | |
| missing_paths+=("+ $file → $path_without_ext") | |
| fi | |
| done | |
| # Check deleted files - they should NOT exist in navigation | |
| while IFS= read -r file; do | |
| if [ -z "$file" ]; then | |
| continue | |
| fi | |
| # Remove .mdx extension | |
| path_without_ext="${file%.mdx}" | |
| echo "Checking if deleted file is removed from navigation: $path_without_ext" | |
| if echo "$navigation_string" | grep -q "$path_without_ext"; then | |
| echo "::error file=$file::Deleted file still exists in docs.json navigation: $file (path: $path_without_ext)" | |
| missing_paths+=("- $file → $path_without_ext") | |
| else | |
| echo "✓ Removed from navigation: $file" | |
| fi | |
| done <<< "$deleted_files" | |
| if [ ${#missing_paths[@]} -gt 0 ]; then | |
| echo "" | |
| echo "❌ The following file changes are not reflected in docs.json:" | |
| printf ' %s\n' "${missing_paths[@]}" | |
| echo "" | |
| echo "Please update docs.json to include these file paths." | |
| exit 1 | |
| else | |
| echo "" | |
| echo "✓ All .mdx file changes are properly reflected in docs.json." | |
| fi |