Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion .github/workflows/revalidate-sdk-content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,80 @@ jobs:
if [ -z "$CHANGED_FILES" ]; then
echo "No MDX files changed in /docs/pages/ directory"
echo "filePaths=[]" >> $GITHUB_OUTPUT
echo "frontmatterChanged=false" >> $GITHUB_OUTPUT
exit 0
Comment on lines 42 to 45
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redirects to $GITHUB_OUTPUT should be quoted (e.g., >> "$GITHUB_OUTPUT") to avoid edge cases if the path contains spaces or special characters. This is the pattern recommended by GitHub Actions docs and makes the step more robust.

Copilot uses AI. Check for mistakes.
fi

# Detect whether any changed file has frontmatter changes
FRONTMATTER_CHANGED=false
extract_frontmatter() {
local ref="$1"
local path="$2"

if ! git cat-file -e "${ref}:${path}" 2>/dev/null; then
return 0
fi

git show "${ref}:${path}" | awk '
NR == 1 && $0 != "---" { exit }
NR == 1 && $0 == "---" { in_frontmatter = 1; next }
in_frontmatter && $0 == "---" { exit }
in_frontmatter { print }
'
}

while IFS= read -r FILE; do
[ -z "$FILE" ] && continue
OLD_FRONTMATTER=$(extract_frontmatter "${{ github.event.before }}" "$FILE")
NEW_FRONTMATTER=$(extract_frontmatter "${{ github.event.after }}" "$FILE")

if [ "$OLD_FRONTMATTER" != "$NEW_FRONTMATTER" ]; then
FRONTMATTER_CHANGED=true
echo "Frontmatter changed in: $FILE"
break
fi
done <<< "$CHANGED_FILES"

# Strip docs/ prefix to get file paths matching Redis cache keys
# e.g., docs/pages/reference/... -> pages/reference/...
FILE_PATHS_JSON=$(echo "$CHANGED_FILES" | sed 's|^docs/||' | jq -R -s -c 'split("\n") | map(select(length > 0))')

FILE_COUNT=$(echo "$FILE_PATHS_JSON" | jq 'length')
echo "Found $FILE_COUNT changed files"
echo "frontmatterChanged: $FRONTMATTER_CHANGED"
echo "filePaths=$FILE_PATHS_JSON" >> $GITHUB_OUTPUT
echo "frontmatterChanged=$FRONTMATTER_CHANGED" >> $GITHUB_OUTPUT
Comment on lines +84 to +86
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote $GITHUB_OUTPUT in these output writes (e.g., >> "$GITHUB_OUTPUT") for robustness and to match GitHub Actions recommendations.

Copilot uses AI. Check for mistakes.

- name: Call revalidation API
if: steps.changed-files.outputs.filePaths != '[]'
run: |
ALL_PATHS='${{ steps.changed-files.outputs.filePaths }}'
FRONTMATTER_CHANGED='${{ steps.changed-files.outputs.frontmatterChanged }}'
TOTAL=$(echo "$ALL_PATHS" | jq 'length')
BATCH_SIZE=50
SUCCEEDED=0
FAILED=0
BATCH_NUM=0
REINDEX_CHECKED=false
REINDEX_FAILED=false

echo "Revalidating $TOTAL files in batches of $BATCH_SIZE"

for ((i = 0; i < TOTAL; i += BATCH_SIZE)); do
BATCH_NUM=$((BATCH_NUM + 1))
BATCH=$(echo "$ALL_PATHS" | jq -c ".[$i:$((i + BATCH_SIZE))]")
CHUNK_SIZE=$(echo "$BATCH" | jq 'length')
INCLUDE_REINDEX=false

echo ""
echo "=== Batch $BATCH_NUM ($CHUNK_SIZE paths, $((i + CHUNK_SIZE))/$TOTAL) ==="

PAYLOAD=$(jq -n --argjson paths "$BATCH" '{filePaths: $paths}')
if [ "$FRONTMATTER_CHANGED" = "true" ] && [ "$REINDEX_CHECKED" = "false" ]; then
INCLUDE_REINDEX=true
PAYLOAD=$(jq -n --argjson paths "$BATCH" '{filePaths: $paths, frontmatterChanged: true}')
else
PAYLOAD=$(jq -n --argjson paths "$BATCH" '{filePaths: $paths}')
fi

HTTP_CODE=$(curl -X POST "${{ secrets.DOCS_SITE_URL }}/docs/api/revalidate/markdown" \
-H "Authorization: Bearer ${{ secrets.DOCS_SITE_API_KEY }}" \
Expand Down Expand Up @@ -102,6 +144,18 @@ jobs:
FAILED=$((FAILED + CHUNK_SIZE))
fi

if [ "$INCLUDE_REINDEX" = "true" ]; then
REINDEX_CHECKED=true
REINDEX_TRIGGERED=$(jq -r '.reindexTriggered.triggered // "false"' response.json 2>/dev/null || echo "false")
if [ "$REINDEX_TRIGGERED" != "true" ]; then
REINDEX_FAILED=true
REINDEX_ERROR=$(jq -r '.reindexTriggered.error // "Reindex trigger failed or was not returned by API"' response.json 2>/dev/null || echo "Unable to parse reindex response")
echo "::error::Reindex requested but not triggered: $REINDEX_ERROR"
else
echo "✅ Reindex workflow trigger acknowledged"
fi
fi

if [ $((i + BATCH_SIZE)) -lt "$TOTAL" ]; then
sleep 2
fi
Expand All @@ -116,4 +170,9 @@ jobs:
exit 1
fi

if [ "$REINDEX_FAILED" = "true" ]; then
echo "::error::Frontmatter changed, but reindex was not successfully triggered"
exit 1
fi

echo "::notice::Successfully revalidated $SUCCEEDED files"
Loading