Skip to content

Commit 8c3be7d

Browse files
committed
run the script to check labels at the start of the workflow; exit if none is found
1 parent f030341 commit 8c3be7d

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

.github/actions-scripts/enterprise-algolia-label.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ const fs = require('fs')
44
const core = require('@actions/core')
55
const eventPayload = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8'))
66

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
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.
1111

1212
const labelText = 'sync-english-index-for-'
1313
const labelsArray = eventPayload.pull_request.labels
1414

1515
// Find the relevant label
1616
const algoliaLabel = labelsArray.find(label => label.startsWith(labelText))
1717

18+
// Exit early if no relevant label is found
19+
if (!algoliaLabel) {
20+
process.exit(0)
21+
}
22+
1823
// Given: sync-english-index-for-enterprise-server@3.0
1924
// Returns: enterprise-server@3.0
2025
const versionToSync = algoliaLabel.split(labelText)[1]

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,32 @@ 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' && contains(github.event.pull_request.labels.*.name, 'sync-english-index-for-')
18+
if: github.repository == 'github/docs-internal'
1919
runs-on: ubuntu-latest
2020
steps:
21-
- name: checkout
21+
- name: Get version from label if present
22+
id: getVersion
23+
run: $GITHUB_WORKSPACE/.github/actions-scripts/enterprise-algolia-label.js
24+
- if: ${{ steps.getVersion.outputs.versionToSync }}
25+
name: checkout
2226
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
23-
- uses: actions/setup-node@56899e050abffc08c2b3b61f3ec6a79a9dc3223d
27+
- if: ${{ steps.getVersion.outputs.versionToSync }}
28+
uses: actions/setup-node@56899e050abffc08c2b3b61f3ec6a79a9dc3223d
2429
with:
2530
node-version: 14.x
26-
- name: cache node modules
31+
- if: ${{ steps.getVersion.outputs.versionToSync }}
32+
name: cache node modules
2733
uses: actions/cache@0781355a23dac32fd3bac414512f4b903437991a
2834
with:
2935
path: ~/.npm
3036
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
3137
restore-keys: |
3238
${{ runner.os }}-node-
33-
- name: npm ci
39+
- if: ${{ steps.getVersion.outputs.versionToSync }}
40+
name: npm ci
3441
run: npm ci
35-
- name: Get version from label
36-
id: getVersion
37-
run: $GITHUB_WORKSPACE/.github/actions-scripts/enterprise-algolia-label.js
38-
- name: Sync English index for single version
42+
- if: ${{ steps.getVersion.outputs.versionToSync }}
43+
name: Sync English index for single version
3944
env:
4045
VERSION: ${{ steps.getVersion.outputs.versionToSync }}
4146
LANGUAGE: 'en'

0 commit comments

Comments
 (0)