From 26b1bd4df72f828c16363688c60e7c1857baf027 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Thu, 1 Dec 2022 22:52:18 +0100 Subject: [PATCH] sync-search after successful production deployment (#31233) --- .../workflows/sync-search-elasticsearch.yml | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sync-search-elasticsearch.yml b/.github/workflows/sync-search-elasticsearch.yml index 51cd597f3e..86a95d933f 100644 --- a/.github/workflows/sync-search-elasticsearch.yml +++ b/.github/workflows/sync-search-elasticsearch.yml @@ -12,15 +12,23 @@ on: description: "Version to exclusively generate the search index for. E.g. 'dotcom', 'ghes-3.7', 'ghae'" required: false default: '' + languages: + description: "Comma separated languages. E.g. 'en,ja, es' (defaults to all)" + required: false + default: '' schedule: - - cron: '20 */4 * * *' # Run every 4 hours at 20 minutes after + - cron: '20 */24 * * *' # Run every 24 hours at 20 minutes past the hour + workflow_run: + workflows: ['Azure Production - Build and Deploy'] + types: + - completed permissions: contents: read # This allows a subsequently queued workflow run to cancel previous runs concurrency: - group: '${{ github.workflow }} @ ${{ github.head_ref }}' + group: '${{ github.workflow }} @ ${{ github.head_ref }} ${{ github.event_name }}' cancel-in-progress: true env: @@ -28,7 +36,51 @@ env: ELASTICSEARCH_URL: ${{ secrets.ELASTICSEARCH_URL }} jobs: + figureOutMatrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.result }} + steps: + - uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 + id: set-matrix + with: + script: | + // Edit this list for the definitive list of languages + // (other than English) we want to index in Elasticsearch. + const allNonEnglish = ["ja", "es", "pt", "cn", "ru", "fr", "ko", "de"] + const allPossible = ["en", ...allNonEnglish] + + if (context.eventName === "workflow_run") { + if (context.payload.workflow_run.conclusion === "success") { + return ["en"] + } + throw new Error(`It was a workflow_run but not success ('${context.payload.workflow_run.conclusion}')`) + } + + if (context.eventName === "workflow_dispatch") { + if (context.payload.inputs.languages) { + const clean = context.payload.inputs.languages.split(',').map(x => x.trim()).filter(Boolean) + const notRecognized = clean.find(x => !allPossible.includes(x)) + if (notRecognized) { + throw new Error(`'${notRecognized}' is not a recognized language code`) + } + return clean + } + return allPossible + } + + if (context.eventName === "schedule") { + return allNonEnglish + } + + console.log(context) + throw new Error(`Unable figure out what languages to run (${context.eventName})`) + + - name: Debug output + run: echo "${{ steps.set-matrix.outputs.result }}" + updateElasticsearchIndexes: + needs: figureOutMatrix name: Update indexes if: ${{ github.repository == 'github/docs-internal' }} runs-on: ubuntu-20.04-xl @@ -36,8 +88,7 @@ jobs: fail-fast: false max-parallel: 3 matrix: - # This needs to match the languages we support - language: [en, ja, es, pt, cn, ru, fr, ko, de] + language: ${{ fromJSON(needs.figureOutMatrix.outputs.matrix) }} steps: - if: ${{ env.FREEZE == 'true' }} run: |