1
0
mirror of synced 2025-12-23 11:54:18 -05:00

workflow_dispatch version input for sync search (#32207)

This commit is contained in:
Peter Bengtsson
2022-11-01 21:24:58 +01:00
committed by GitHub
parent fe491f1cda
commit 96ae1fa44d
2 changed files with 44 additions and 2 deletions

View File

@@ -7,6 +7,11 @@ name: Sync search Elasticsearch
on:
workflow_dispatch:
inputs:
version:
description: "Version to exclusively generate the search index for. E.g. 'dotcom', 'ghes-3.7', 'ghae'"
required: false
default: ''
schedule:
- cron: '23 */4 * * *' # Run every 4 hours at 23 minutes past the hour
@@ -88,6 +93,10 @@ jobs:
# let's just accept an empty string instead.
THROW_ON_EMPTY: false
# Note that by default, this is '' (empty string) and that means
# the same as not set within the script.
VERSION: ${{ github.event.inputs.version }}
run: |
mkdir /tmp/records
npm run sync-search-indices -- \
@@ -102,6 +111,11 @@ jobs:
curl --fail --retry-connrefused --retry 5 -I ${{ env.ELASTICSEARCH_URL }}
- name: Index into Elasticsearch
env:
# Must match what we used when scraping (npm run sync-search-indices)
# otherwise the script will seek other versions from disk that might
# not exist.
VERSION: ${{ github.event.inputs.version }}
run: |
./script/search/index-elasticsearch.js \
--language ${{ matrix.language }} -- /tmp/records

View File

@@ -137,12 +137,40 @@ async function main(opts, args) {
async function indexAll(node, sourceDirectory, opts) {
const client = new Client({ node })
const { version, language, verbose, notLanguage, indexPrefix } = opts
const { language, verbose, notLanguage, indexPrefix } = opts
let version
if ('version' in opts) {
version = opts.version
if (process.env.VERSION) {
console.warn(
`'version' specified as argument ('${version}') AND environment variable ('${process.env.VERSION}')`
)
}
} else {
if (process.env.VERSION && process.env.VERSION !== 'all') {
version = process.env.VERSION
if (!allVersionKeys.includes(version)) {
throw new Error(
`Environment variable 'VERSION' (${version}) is not recognized. Must be one of ${allVersionKeys}`
)
}
}
}
let versionKeys = allVersionKeys
// If it came from the `--version` argument parsing, it might be a string
// or an array of strings because it uses `--version [VERSION...]`.
if (version) {
if (Array.isArray(version)) {
versionKeys = version
} else {
versionKeys = [version]
}
}
// This will throw if it can't ping
await client.ping()
const versionKeys = version || allVersionKeys
const languages =
language || languageKeys.filter((lang) => !notLanguage || !notLanguage.includes(lang))
if (verbose) {