-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
action.yml
149 lines (144 loc) · 5.26 KB
/
action.yml
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Issue Forms Dropdown Options
description: Populates options for a version dropdown issue forms element
author: ShaMan123
branding:
icon: list
color: purple
inputs:
github_token:
description: Github token
default: ${{ github.token }}
template:
description: |
The location of the template file used to build the form, useful for ease of maintenance.
Dynamic dropdowns will persist between action runs.
Static dropdowns (dropdowns with populated options) take precedence over their built counterpart,
meaning that you should not edit the built form ever,
see https://github.com/ShaMan123/gha-form-dropdown-options/pull/2/commits/7cbd904caccb60c9bf52f066d11b303e439fe598.
This behavior makes sense but could have been handled with ease if flagging dynamic dropdowns in forms was possible.
It might change to a stricter approach in the future using id prefixing.
It is suggested using the template option once in the first step updating the form and omitting it afterwards.
type: string
form:
description: The location of the yaml form file
type: string
required: true
dropdown:
description: |
The id of the dropdown in the yaml form to populate options into
Prefix the id with the value of `id_prefix`, see `strategy` for more details
type: string
required: true
options:
description: |
A stringified array of options
Supports the dynamic substitution templates: `{...}`, `{{...}}`
type: string
required: true
label:
description: |
The label of the dropdown
Supports the dynamic substitution templates: `{...}`, `{{...}}`
type: string
description:
description: |
The description of the dropdown
Supports the dynamic substitution templates: `{...}`, `{{...}}`
type: string
unique:
description: |
Whether `options` should be unique
type: boolean
default: true
commit_message:
description: 'defaults to `chore(): update [REPORT_NAME]`'
type: string
strategy:
description: |
The strategy used to determine if a dropdown is static or not.
The `empty-options` strategy determines if a dropdown is dynamic by checking if the template's options are empty.
The `id-prefix` strategy determines if a dropdown is dynamic or not by checking its id prefix depending on the value of `id_prefix`.
`id-prefix` is strict and allows more flexibility, such as dynamic substitution.
The `mixed` strategy uses both.
type: choice
default: mixed
options:
- id-prefix
- empty-options
- mixed
id_prefix:
description: |
The prefix used by `strategy` to determine if a dropdown is dynamic
type: string
default: _
dry_run:
description: |
Pass `no-write` to leave `form` untouched
Pass `no-commit` to leave the git history untouched
Pass `no-push` to leave the commit untouched
type: choice
options:
- no-write
- no-commit
- no-push
# https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs#example-defining-outputs-for-a-job
outputs:
form:
description: JSON stringified form
value: ${{ steps.process.outputs.form }}
modified:
description: form has been modified by action
value: ${{ steps.process.outputs.modified }}
pushed:
description: pushed to origin
value: ${{ steps.commit.outputs.pushed || false }}
runs:
using: composite
steps:
- name: Update ${{ inputs.form }}
id: process
run: |
node ${{ github.action_path }}/dist/main.cjs
if [[ $(git status --porcelain | grep -c '.*\s*${{ inputs.form }}') -eq 1 ]]; then
echo "Form ${{ inputs.form }} has been modified"
echo "::set-output name=modified::true"
else
echo "Form ${{ inputs.form }} is up to date"
echo "::set-output name=modified::false"
fi
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
INPUT_TEMPLATE: ${{ inputs.template }}
INPUT_FORM: ${{ inputs.form }}
INPUT_DROPDOWN: ${{ inputs.dropdown }}
INPUT_OPTIONS: ${{ inputs.options }}
INPUT_LABEL: ${{ inputs.label }}
INPUT_DESCRIPTION: ${{ inputs.description }}
INPUT_UNIQUE: ${{ inputs.unique }}
INPUT_STRATEGY: ${{ inputs.strategy }}
INPUT_ID_PREFIX: ${{ inputs.id_prefix }}
INPUT_DRY_RUN: ${{ inputs.dry_run }}
- name: Commit & Push
id: commit
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
PUSHED=false
if [[ ${{ steps.process.outputs.modified }} == true ]] && [[ ${{ inputs.dry_run != 'no-commit' }} == true ]]; then
echo "Committing ${{ inputs.form }}"
git add ${{ inputs.form }}
MSG='${{ inputs.commit_message }}'
if [[ $MSG == '' ]]; then
MSG='chore(): update ${{ fromJSON(steps.process.outputs.form).name }}'
fi
git commit -m "$MSG"
if [[ ${{ inputs.dry_run != 'no-push' }} == true ]]; then
echo "Pushing to upstream"
git pull --ff-only
git push
PUSHED=true
fi
fi
echo "::set-output name=pushed::$PUSHED"
shell: bash