File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ const fs = require ( 'fs' )
4+ const core = require ( '@actions/core' )
5+ const eventPayload = JSON . parse ( fs . readFileSync ( process . env . GITHUB_EVENT_PATH , 'utf8' ) )
6+
7+ // This workflow-run script does the following:
8+ // 1. Gets an array of labels on a PR.
9+ // 2. Finds one with the relevant Algolia text; if none found, exits early.
10+ // 3. Gets the version substring from the label string.
11+
12+ const labelText = 'sync-english-index-for-'
13+ const labelsArray = eventPayload . pull_request . labels
14+
15+ // Exit early if no labels are on this PR
16+ if ( ! ( labelsArray && labelsArray . length ) ) {
17+ process . exit ( 0 )
18+ }
19+
20+ // Find the relevant label
21+ const algoliaLabel = labelsArray
22+ . map ( label => label . name )
23+ . find ( label => label . startsWith ( labelText ) )
24+
25+ // Exit early if no relevant label is found
26+ if ( ! algoliaLabel ) {
27+ process . exit ( 0 )
28+ }
29+
30+ // Given: sync-english-index-for-enterprise-server@3.0
31+ // Returns: enterprise-server@3.0
32+ const versionToSync = algoliaLabel . split ( labelText ) [ 1 ]
33+
34+ // Store the version so we can access it later in the workflow
35+ core . setOutput ( 'versionToSync' , versionToSync )
36+ process . exit ( 0 )
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ name: Algolia Sync Single English Index
33on :
44 pull_request :
55 types :
6+ - labeled
7+ - unlabeled
68 - opened
79 - reopened
810 - synchronize
1315jobs :
1416 updateIndices :
1517 name : Update English index for single version based on a label's version
16- if : github.repository == 'github/docs-internal' && startsWith(github.event.label.name, 'sync-english-index-for-')
18+ if : github.repository == 'github/docs-internal'
1719 runs-on : ubuntu-latest
1820 steps :
1921 - name : checkout
@@ -30,13 +32,13 @@ jobs:
3032 ${{ runner.os }}-node-
3133 - name : npm ci
3234 run : npm ci
33- - name : Get version from label
35+ - name : Get version from Algolia label if present; only continue if the label is found.
3436 id : getVersion
35- run : |
36- echo "::set-output name=version::$(github.event.label.name.split('sync-english-index-for-')[1])"
37- - name : Sync English index for single version
37+ run : $GITHUB_WORKSPACE/.github/actions-scripts/enterprise-algolia-label.js
38+ - if : ${{ steps.getVersion.outputs.versionToSync }}
39+ name : Sync English index for single version
3840 env :
39- VERSION : ${{ steps.getVersion.outputs.version }}
41+ VERSION : ${{ steps.getVersion.outputs.versionToSync }}
4042 LANGUAGE : ' en'
4143 ALGOLIA_APPLICATION_ID : ${{ secrets.ALGOLIA_APPLICATION_ID }}
4244 ALGOLIA_API_KEY : ${{ secrets.ALGOLIA_API_KEY }}
Original file line number Diff line number Diff line change 7777 "webpack-cli" : " ^3.3.12"
7878 },
7979 "devDependencies" : {
80+ "@actions/core" : " ^1.2.6" ,
8081 "ajv" : " ^6.11.0" ,
8182 "async" : " ^3.2.0" ,
8283 "await-sleep" : " 0.0.1" ,
You can’t perform that action at this time.
0 commit comments