Reindex Algolia after production deploy #304
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: Reindex Algolia after production deploy | |
| # Triggers a full Algolia Crawler reindex whenever a Vercel *production* | |
| # deployment succeeds, so newly published docs pages appear in search right | |
| # away instead of waiting for the crawler's scheduled run. | |
| # | |
| # Vercel's Git integration posts a GitHub deployment status of | |
| # state=success / environment=Production once the deploy is live, which is | |
| # what this workflow keys off of (preview and staging deploys are ignored). | |
| # | |
| # To avoid unnecessary crawls, the reindex is skipped when the deployed commit | |
| # didn't touch docs content. `main` is squash-merged, so `git diff-tree HEAD` | |
| # lists exactly the files that publish changed. | |
| # | |
| # Requires (repo Settings -> Secrets and variables -> Actions): | |
| # - Variable ALGOLIA_CRAWLER_ID (fe95aa31-abbb-40ea-a31b-04a9ccd176b4) | |
| # - Secret ALGOLIA_CRAWLER_USER_ID (from Algolia dashboard -> Crawler -> API credentials) | |
| # - Secret ALGOLIA_CRAWLER_API_KEY (from Algolia dashboard -> Crawler -> API credentials) | |
| on: | |
| deployment_status: | |
| # Serialize reindexes so a non-docs deploy doesn't cancel an in-flight crawl | |
| # triggered by an earlier docs deploy. Queued runs each check their own commit; | |
| # only runs whose commit touched docs content actually trigger a crawl. | |
| concurrency: | |
| group: algolia-reindex | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| jobs: | |
| reindex: | |
| if: > | |
| github.event.deployment_status.state == 'success' && | |
| github.event.deployment_status.environment == 'Production' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.deployment.sha }} | |
| fetch-depth: 2 | |
| - name: Check whether docs content changed | |
| id: changed | |
| run: | | |
| files=$(git diff-tree --no-commit-id --name-only -r HEAD) | |
| if echo "$files" | grep -qE '^app/en/|^toolkit-docs-generator/data/toolkits/|^app/_components/toolkit-docs/|^app/_lib/toolkit-|^algolia/crawler-config\.js$|^scripts/sync-crawler-config\.ts$'; then | |
| echo "docs=true" >> "$GITHUB_OUTPUT" | |
| echo "Docs content changed — will reindex." | |
| else | |
| echo "docs=false" >> "$GITHUB_OUTPUT" | |
| echo "No docs content changed — skipping reindex." | |
| fi | |
| - name: Trigger Algolia Crawler reindex | |
| if: steps.changed.outputs.docs == 'true' | |
| env: | |
| CRAWLER_ID: ${{ vars.ALGOLIA_CRAWLER_ID }} | |
| CRAWLER_USER_ID: ${{ secrets.ALGOLIA_CRAWLER_USER_ID }} | |
| CRAWLER_API_KEY: ${{ secrets.ALGOLIA_CRAWLER_API_KEY }} | |
| run: | | |
| echo "Triggering reindex for crawler ${CRAWLER_ID}" | |
| curl -sS --fail-with-body -X POST \ | |
| "https://crawler.algolia.com/api/1/crawlers/${CRAWLER_ID}/reindex" \ | |
| -u "${CRAWLER_USER_ID}:${CRAWLER_API_KEY}" |