|
1 | 1 | name: Sync search indexes
|
2 | 2 |
|
3 |
| -# **What it does**: This updates our search indexes after each deployment. |
| 3 | +# **What it does**: This workflow syncs the Lunr search indexes. |
| 4 | +# The search indexes are checked into the lib/search/indexes directory. |
| 5 | +# Search indexes are checked directly into the `main` branch on both the |
| 6 | +# internal and open-source docs repositories. This workflow should be the |
| 7 | +# only mechanism that the search indexes are modified. Because of that, |
| 8 | +# repo-sync will not sync the search indexes because it should not detect |
| 9 | +# a change. |
4 | 10 | # **Why we have it**: We want our search indexes kept up to date.
|
5 | 11 | # **Who does it impact**: Anyone using search on docs.
|
6 | 12 |
|
| 13 | +# **Testing: To test this workflow, use the workflow_dispatch event and trigger |
| 14 | +# the workflow from the action tab. Select the branch with the changes to the |
| 15 | +# workflow. Set `fetch-depth: 0` as an input to the checkout action to get all |
| 16 | +# branches, including your test branch. Otherwise, you'll only get the main |
| 17 | +# branch. For git lfs push and git push commands use the --dry-run switch to |
| 18 | +# prevent pushes (e.g., git push --dry-run origin main --no-verify and |
| 19 | +# git lfs push --dry-run public-docs-repo). |
| 20 | +# The dry-run switch does everything but actually send the updates. |
| 21 | + |
7 | 22 | on:
|
8 | 23 | workflow_dispatch:
|
9 |
| - push: |
10 |
| - branches: |
11 |
| - - main |
| 24 | + schedule: |
| 25 | + - cron: '53 0/4 * * *' # Run every four hours at 53 minutes past the hour |
12 | 26 |
|
13 | 27 | jobs:
|
14 |
| - updateIndices: |
15 |
| - name: Update indices |
| 28 | + updateIndexes: |
| 29 | + name: Update indexes |
16 | 30 | if: github.repository == 'github/docs-internal'
|
17 | 31 | runs-on: ubuntu-latest
|
18 | 32 | steps:
|
| 33 | + # Check out internal docs repository |
19 | 34 | - name: checkout
|
20 | 35 | uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
|
| 36 | + with: |
| 37 | + token: ${{ secrets.DOCS_BOT }} |
| 38 | + |
21 | 39 | - name: Setup Node
|
22 | 40 | uses: actions/setup-node@38d90ce44d5275ad62cc48384b3d8a58c500bb5f
|
23 | 41 | with:
|
24 | 42 | node-version: 16.x
|
25 | 43 | cache: npm
|
| 44 | + |
26 | 45 | - name: Install dependencies
|
27 | 46 | run: npm ci
|
| 47 | + |
28 | 48 | - name: Run build scripts
|
29 | 49 | run: npm run build
|
30 |
| - - name: sync indices |
| 50 | + |
| 51 | + - name: Update search indexes |
31 | 52 | env:
|
32 |
| - ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }} |
33 |
| - ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }} |
34 | 53 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
35 |
| - run: npm run sync-search |
| 54 | + # TODO remove version and language after first successful run to test |
| 55 | + run: VERSION=github-ae@latest LANGUAGE=pt npm run sync-search |
| 56 | + |
| 57 | + - name: Update private docs repository search indexes |
| 58 | + # Git pre-push hooks push the LFS objects, so if you don't run them and |
| 59 | + # don't push the LFS objects manually, the LFS objects won't get |
| 60 | + # pushed. That will likely result in the push getting rejected. |
| 61 | + # So if you don't use the pre-push hooks or you run with --no-verify |
| 62 | + # the LFS objects need to be pushed first. |
| 63 | + run: | |
| 64 | + echo 'git checkout main' |
| 65 | + git checkout main |
| 66 | + echo 'git config user.name "GitHub Actions"' |
| 67 | + git config user.name "GitHub Actions" |
| 68 | + echo 'git config user.email [email protected]' |
| 69 | + git config user.email [email protected] |
| 70 | + echo 'git commit -am "update search indexes"' |
| 71 | + git commit -am "update search indexes" |
| 72 | + echo 'git lfs push origin' |
| 73 | + git lfs push origin |
| 74 | + echo 'git push origin main --no-verify' |
| 75 | + git push origin main --no-verify |
| 76 | +
|
| 77 | + - name: Update open-source docs repository search indexes |
| 78 | + # Git pre-push hooks push the LFS objects, so if you don't run them and |
| 79 | + # don't push the LFS objects manually, the LFS objects won't get |
| 80 | + # pushed. That will likely result in the push getting rejected. |
| 81 | + # So if you don't use the pre-push hooks or you run with --no-verify |
| 82 | + # the LFS objects need to be pushed first. |
| 83 | + run: | |
| 84 | + echo 'git remote add public-docs-repo https://github.com/github/docs.git' |
| 85 | + git remote add public-docs-repo https://github.com/github/docs.git |
| 86 | + echo 'git lfs push public-docs-repo' |
| 87 | + git lfs push public-docs-repo |
| 88 | + echo 'git pull public-docs-repo main' |
| 89 | + git pull public-docs-repo main |
| 90 | + echo 'git push public-docs-repo main --no-verify' |
| 91 | + git push public-docs-repo main --no-verify |
| 92 | +
|
36 | 93 | - name: Send slack notification if workflow run fails
|
37 | 94 | uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd
|
38 | 95 | if: failure()
|
|
0 commit comments