Skip to content

Commit f030341

Browse files
committed
use js to find the version substring from the label string
1 parent 3cc870e commit f030341

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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:
8+
// 1. Gets an array of labels on a PR
9+
// 2. Finds one with the relevant Algolia text
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+
// Find the relevant label
16+
const algoliaLabel = labelsArray.find(label => label.startsWith(labelText))
17+
18+
// Given: sync-english-index-for-enterprise-server@3.0
19+
// Returns: enterprise-server@3.0
20+
const versionToSync = algoliaLabel.split(labelText)[1]
21+
22+
// Store the version so we can access it later in the workflow
23+
core.setOutput('versionToSync', versionToSync)
24+
process.exit(0)

.github/workflows/sync-single-english-algolia-index.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
jobs:
1616
updateIndices:
1717
name: Update English index for single version based on a label's version
18-
if: github.repository == 'github/docs-internal' && startsWith(github.event.label.name, 'sync-english-index-for-')
18+
if: github.repository == 'github/docs-internal' && contains(github.event.pull_request.labels.*.name, 'sync-english-index-for-')
1919
runs-on: ubuntu-latest
2020
steps:
2121
- name: checkout
@@ -34,11 +34,10 @@ jobs:
3434
run: npm ci
3535
- name: Get version from label
3636
id: getVersion
37-
run: |
38-
echo "::set-output name=version::$(github.event.label.name.split('sync-english-index-for-')[1])"
37+
run: $GITHUB_WORKSPACE/.github/actions-scripts/enterprise-algolia-label.js
3938
- name: Sync English index for single version
4039
env:
41-
VERSION: ${{ steps.getVersion.outputs.version }}
40+
VERSION: ${{ steps.getVersion.outputs.versionToSync }}
4241
LANGUAGE: 'en'
4342
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
4443
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}

0 commit comments

Comments
 (0)