Sync search indexes #2043
This file contains 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: Sync search indexes | |
# **What it does**: This workflow syncs the Lunr search indexes. | |
# The search indexes are checked into the lib/search/indexes directory. | |
# Search indexes are checked directly into the `main` branch on both the | |
# internal and open-source docs repositories. This workflow should be the | |
# only mechanism that the search indexes are modified. Because of that, | |
# repo-sync will not sync the search indexes because it should not detect | |
# a change. | |
# **Why we have it**: We want our search indexes kept up to date. | |
# **Who does it impact**: Anyone using search on docs. | |
# **Testing: To test this workflow, use the workflow_dispatch event and trigger | |
# the workflow from the action tab. Select the branch with the changes to the | |
# workflow. Set `fetch-depth: 0` as an input to the checkout action to get all | |
# branches, including your test branch. Otherwise, you'll only get the main | |
# branch. For git lfs push and git push commands use the --dry-run switch to | |
# prevent pushes (e.g., git push --dry-run origin main --no-verify and | |
# git lfs push --dry-run public-docs-repo). | |
# The dry-run switch does everything but actually send the updates. | |
on: | |
workflow_dispatch: | |
inputs: | |
language: | |
description: 'Language to generate the search index for. Can be one of: `en` English, `cn` Chinese simplified, `ja` Japanese, `es` Spanish, `pt` Portuguese., `all` all languages.' | |
required: false | |
default: 'all' | |
version: | |
description: 'Version to generate the search index for. Can be one of: `free-pro-team@latest`, `enterprise-server@<RELEASE NUMBER>`, `github-ae@latest`, `all` all versions.' | |
required: false | |
default: 'all' | |
schedule: | |
- cron: '53 0/8 * * *' # Run every eight hours at 53 minutes past the hour | |
permissions: | |
contents: none | |
env: | |
FREEZE: ${{ secrets.FREEZE }} | |
jobs: | |
updateIndexes: | |
name: Update indexes | |
if: github.repository == 'github/docs-internal' | |
runs-on: ubuntu-latest | |
steps: | |
- if: ${{ env.FREEZE == 'true' }} | |
run: | | |
echo 'The repo is currently frozen! Exiting this workflow.' | |
exit 1 # prevents further steps from running | |
# Check out internal docs repository | |
- name: checkout | |
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 | |
with: | |
token: ${{ secrets.DOCS_BOT_FR }} | |
- name: Setup Node | |
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561 | |
with: | |
node-version: 16.13.x | |
cache: npm | |
- name: Install dependencies | |
run: npm ci | |
- name: Cache nextjs build | |
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed | |
with: | |
path: .next/cache | |
key: ${{ runner.os }}-nextjs-${{ hashFiles('package*.json') }} | |
- name: Run build scripts | |
run: npm run build | |
- name: Update search indexes | |
env: | |
VERSION: ${{ github.event.inputs.version }} | |
LANGUAGE: ${{ github.event.inputs.language }} | |
run: npm run sync-search | |
- name: Update private docs repository search indexes | |
# Git pre-push hooks push the LFS objects, so if you don't run them and | |
# don't push the LFS objects manually, the LFS objects won't get | |
# pushed. That will likely result in the push getting rejected. | |
# So if you don't use the pre-push hooks or you run with --no-verify | |
# the LFS objects need to be pushed first. | |
run: | | |
echo 'git config user.name "GitHub Actions"' | |
git config user.name "GitHub Actions" | |
echo 'git config user.email [email protected]' | |
git config user.email [email protected] | |
echo 'git config pull.ff only' | |
git config pull.ff only | |
echo 'git pull origin main --no-verify' | |
git pull origin main --no-verify | |
echo 'git add lib/search/indexes/*' | |
git add lib/search/indexes/* | |
echo 'git commit -m "update search indexes"' | |
git commit -m "update search indexes" | |
echo 'git lfs push --all origin' | |
git lfs push --all origin | |
echo 'git push origin main --no-verify' | |
git push origin main --no-verify | |
- name: Update open-source docs repository search indexes | |
# Git pre-push hooks push the LFS objects, so if you don't run them and | |
# don't push the LFS objects manually, the LFS objects won't get | |
# pushed. That will likely result in the push getting rejected. | |
# So if you don't use the pre-push hooks or you run with --no-verify | |
# the LFS objects need to be pushed first. | |
run: | | |
echo 'git remote add public-docs-repo https://github.com/github/docs.git' | |
git remote add public-docs-repo https://github.com/github/docs.git | |
echo 'git lfs push --all public-docs-repo' | |
git lfs push --all public-docs-repo | |
- name: Send slack notification if workflow run fails | |
uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340 | |
if: failure() && env.FREEZE != 'true' | |
with: | |
channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} | |
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} | |
color: failure | |
text: The last search index workflow run for ${{github.repository}} failed. Search actions for `workflow:search` |