forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenterprise-search-label.js
More file actions
executable file
·37 lines (28 loc) · 1.07 KB
/
enterprise-search-label.js
File metadata and controls
executable file
·37 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
import fs from 'fs/promises'
import { setOutput } from '@actions/core'
const eventPayload = JSON.parse(await fs.readFile(process.env.GITHUB_EVENT_PATH, 'utf8'))
// This workflow-run script does the following:
// 1. Gets an array of labels on a PR.
// 2. Finds one with the relevant search text; if none found, exits early.
// 3. Gets the version substring from the label string.
const labelText = 'sync-english-index-for-'
const labelsArray = eventPayload.pull_request.labels
// Exit early if no labels are on this PR
if (!(labelsArray && labelsArray.length)) {
process.exit(0)
}
// Find the relevant label
const searchLabel = labelsArray
.map((label) => label.name)
.find((label) => label.startsWith(labelText))
// Exit early if no relevant label is found
if (!searchLabel) {
process.exit(0)
}
// Given: sync-english-index-for-enterprise-server@3.0
// Returns: enterprise-server@3.0
const versionToSync = searchLabel.split(labelText)[1]
// Store the version so we can access it later in the workflow
setOutput('versionToSync', versionToSync)
process.exit(0)