1
0
mirror of synced 2025-12-22 03:16:52 -05:00

remove enterprise and lunr sync search workflows (#32430)

This commit is contained in:
Rachael Sewell
2022-11-07 14:36:30 -08:00
committed by GitHub
parent ca22e90b38
commit 1256add363
5 changed files with 1 additions and 274 deletions

View File

@@ -1,37 +0,0 @@
#!/usr/bin/env node
import fs from 'fs/promises'
import { setOutput } from '@actions/core'
const eventPayload = JSON.parse(await fs.readFile(process.env.GITHUB_EVENT_PATH, 'utf8'))
// This workflow-run script does the following:
// 1. Gets an array of labels on a PR.
// 2. Finds one with the relevant search text; if none found, exits early.
// 3. Gets the version substring from the label string.
const labelText = 'sync-english-index-for-'
const labelsArray = eventPayload.pull_request.labels
// Exit early if no labels are on this PR
if (!(labelsArray && labelsArray.length)) {
process.exit(0)
}
// Find the relevant label
const searchLabel = labelsArray
.map((label) => label.name)
.find((label) => label.startsWith(labelText))
// Exit early if no relevant label is found
if (!searchLabel) {
process.exit(0)
}
// Given: sync-english-index-for-enterprise-server@3.0
// Returns: enterprise-server@3.0
const versionToSync = searchLabel.split(labelText)[1]
// Store the version so we can access it later in the workflow
setOutput('versionToSync', versionToSync)
process.exit(0)

View File

@@ -1,94 +0,0 @@
name: Enterprise Server Release Search Sync
# **What it does**: This workflow is used during the Enterprise Server release
# process. The Enterprise release checklist includes a step to add a label in
# the format `sync-english-index-for-enterprise-server@<RELEASE NUMBER>`. When
# that label is added, this workflow runs anytime new commits are made to the
# Enterprise release megabranch. The Docubot user commits the search indexes in
# the `lib/search/indexes` directory.
#
# **Why we have it**: The Lunr index for the next Enterprise release doesn't yet
# exist, so we need to generate it. Search wouldn't work at all if we shipped
# the new release without shipping the index for that release at the same time.
#
# **Who does it impact**: The DRI for the Enterprise release, the content
# writers that are a part of the release and the docs-engineering DRI.
on:
workflow_dispatch:
pull_request:
types:
- labeled
- unlabeled
- opened
- reopened
- synchronize
- ready_for_review
- unlocked
permissions:
contents: write
# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
# This workflow requires a label in the format `sync-english-index-for-<PLAN@RELEASE>`
jobs:
updateIndices:
name: Update English index for new GHES release
# Skip this check if the event originated from Docubot, to prevent
# infinite runs when Docubot checks in the search indexes in this workflow
if: github.repository == 'github/docs-internal' && github.event.sender.login != 'Docubot' && github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.DOCUBOT_REPO_PAT }}
- name: Setup Node
uses: actions/setup-node@17f8bd926464a1afa4c6a11669539e9c1ba77048
with:
node-version: '16.17.0'
cache: npm
- name: Install dependencies
run: npm ci
- name: Get GHES release number from search label if present; only continue if the label is found.
id: getVersion
run: $GITHUB_WORKSPACE/.github/actions-scripts/enterprise-search-label.js
- name: Cache nextjs build
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09
with:
path: .next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('package*.json') }}
- name: Generate the search index files
if: ${{ steps.getVersion.outputs.versionToSync }}
env:
VERSION: ${{ steps.getVersion.outputs.versionToSync }}
LANGUAGE: 'en'
run: |
npm run build
npm run sync-search
- name: Commit the index files and push LFS objects
if: ${{ steps.getVersion.outputs.versionToSync }}
run: |
echo 'git config user.name Docubot'
git config user.name Docubot
echo 'git config user.email 67483024+docubot@users.noreply.github.com'
git config user.email 67483024+docubot@users.noreply.github.com
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' $GITHUB_HEAD_REF '--set-upstream'
git push origin $GITHUB_HEAD_REF --set-upstream

View File

@@ -1,134 +0,0 @@
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@dcd71f646680f2efd8db4afa5ad64fdcba30e748
with:
token: ${{ secrets.DOCS_BOT_FR }}
- name: Setup Node
uses: actions/setup-node@17f8bd926464a1afa4c6a11669539e9c1ba77048
with:
node-version: '16.17.0'
cache: npm
- name: Install dependencies
run: npm ci
- name: Cache nextjs build
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09
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 }}
# If a reusable, or anything in the `data/*` directory is deleted
# you might get a
#
# RenderError: Can't find the key 'site.data.reusables...' in the scope
#
# But that'll get fixed in the next translation pipeline. For now,
# let's just accept an empty string instead.
THROW_ON_EMPTY: false
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 action@github.com'
git config user.email action@github.com
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_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 GIT_TRACE=1 git lfs push --all public-docs-repo'
GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 GIT_TRACE=1 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`

View File

@@ -16,7 +16,6 @@ const webhooksStaticDir = path.join(process.cwd(), 'lib/webhooks/static')
const graphqlStaticDir = path.join(process.cwd(), 'lib/graphql/static')
const restDecoratedDir = path.join(process.cwd(), 'lib/rest/static/decorated')
const restDereferencedDir = path.join(process.cwd(), 'lib/rest/static/dereferenced')
const lunrIndexDir = path.join(process.cwd(), 'lib/search/indexes')
const supportedEnterpriseVersions = Object.values(allVersions).filter(
(v) => v.plan === 'enterprise-server'
@@ -48,13 +47,6 @@ const openApiBaseName = supportedEnterpriseVersions.map((v) => v.openApiBaseName
removeFiles(dir, openApiBaseName, supportedOpenApiVersions)
})
// Lunr
const lunrBaseName = 'github-docs-'
const supportedLunrVersions = Object.values(allVersions).map((v) =>
v.miscVersionName.replace('ghes-', '')
)
removeFiles(lunrIndexDir, lunrBaseName, supportedLunrVersions)
function removeFiles(dir, baseName, supportedVersions) {
fs.readdirSync(dir)
.filter((file) => file.includes(baseName))

View File

@@ -238,7 +238,7 @@ async function indexVersion(
) {
// Note, it's a bit "weird" that numbered releases versions are
// called the number but that's how the lib/search/indexes
// files are named at the moment.
// files were.
const indexVersion = shortNames[version].hasNumberedReleases
? shortNames[version].currentRelease
: shortNames[version].miscBaseName