-
Notifications
You must be signed in to change notification settings - Fork 0
44 lines (42 loc) · 1.69 KB
/
get-version-label.yml
File metadata and controls
44 lines (42 loc) · 1.69 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
38
39
40
41
42
43
44
name: Get Version Label
on:
workflow_call:
inputs:
workflow_dispatch_version_label:
description: "Version type"
required: false
type: string
outputs:
version_label:
description: the major, minor or patch version label
value: ${{ jobs.get_version_label.outputs.version_label }}
permissions:
contents: read
jobs:
get_version_label:
runs-on: ubuntu-latest
outputs:
version_label: ${{ steps.get_version_label.outputs.version_label }}
steps:
- name: Determine version label
id: get_version_label
uses: actions/github-script@v7
with:
script: |
if (context.payload.inputs?.workflow_dispatch_version_label) {
core.setOutput('version_label', context.payload.inputs.workflow_dispatch_version_label.toLowerCase());
return;
}
if (context.payload.pull_request) {
const allowed = ['patch', 'minor', 'major'];
const versionLabels = context.payload.pull_request.labels.map(l => l.name.toLowerCase()).filter(label => allowed.includes(label));
if (versionLabels.length === 0) {
core.setFailed(`PR must contain one of the version labels: ${allowed.join(', ')}`);
} else if (versionLabels.length > 1) {
core.setFailed(`PR contains multiple version labels: ${versionLabels.join(', ')}. Only one of ${allowed.join(', ')} is allowed.`);
} else {
core.setOutput('version_label', versionLabels[0]);
}
} else {
core.setFailed('No version input provided and not triggered by a pull request');
}