-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
204 lines (167 loc) · 7.75 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
---
name: fmtya
author: norwd
description: "GitHub Action to run yamlfmt"
branding:
icon: edit
color: blue
inputs:
token:
description: "Used to authenticate with GitHub, this should be a PAT with `repo: write` and `workflow: write` permissions."
yamlfmt-version:
default: "latest"
description: "The specifc version of the yamlfmt tool to use, defaults to the latest vailable version."
commit-message:
default: "Auto yamlfmt"
description: "The message used to commit any changes made by yamlfmt."
commit-user-name:
default: "github-actions[bot]"
description: "Who the commit should be attributed to, defaults to the GitHub Actions bot."
commit-user-email:
default: "41898282+github-actions[bot]@users.noreply.github.com"
description: "Who the commit should be attributed to, defaults to the GitHub Actions bot."
signing-private-key:
description: "A GPG private key to sign the commit with. This must be exported as an ASCII armored version or its base64 encoding."
signing-passphrase:
description: "The password or passphrase for the signing key, if one was used."
signoff-on-commit:
default: false
description: "Certify the commit, this will use the provided username and email. Must be one of 'true', 'false', 'yes', or 'no'. See https://developercertificate.org"
include-files:
default: "**/*.{yaml,yml}"
description: "Which files or file patterns to include in the formatter, one pattern per line. Defaults to all yaml files. The glob paths are implemented using the bmatcuk/doublestar package."
exclude-files:
description: "Which files or file patterns to exclude from the formatter, one pattern per line. Glob paths follow the same format as `include-files`."
indent-size:
default: 2
description: "How big to make each indent level."
include-document-start:
default: true
description: "Whether yaml files should begin with `---` at the start."
line-ending-type:
default: "lf"
description: "Determines the type of newline characters to use, must be either `lf` or `crlf`."
keep-line-breaks:
default: true
description: "Keep existing line breaks in formatted yaml."
disallow-anchors:
default: false
description: "Whether to reject any YAML anchors or aliases found in the document."
runs:
using: composite
steps:
- name: "Report Missing Yamlfmt Version"
if: inputs.yamlfmt-version == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No yamlfmt version provided" ; exit 1
- name: "Report Missing Commit Message"
if: inputs.commit-message == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No commit message provided" ; exit 1
- name: "Report Missing Commit User Name"
if: inputs.commit-user-name == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No commit user name provided" ; exit 1
- name: "Report Missing Commit User Email"
if: inputs.commit-user-email == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No commit user email provided" ; exit 1
- name: "Report Missing Indent Size"
if: inputs.indent-size == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No indent size provided" ; exit 1
- name: "Report Missing Include Document Start Setting"
if: inputs.include-document-start == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No include document start setting provided" ; exit 1
- name: "Report Missing Line Ending Type"
if: inputs.line-ending-type == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No line ending type provided" ; exit 1
- name: "Report Missing Line Breaks Setting"
if: inputs.keep-line-breaks == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No keep line breaks setting provided" ; exit 1
- name: "Report Missing Anchors Setting"
if: inputs.disallow-anchors == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No disallow anchors setting provided" ; exit 1
- name: "Report Missing Signoff On Commit"
if: inputs.signoff-on-commit == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No signoff on commit provided" ; exit 1
- name: "Report Invalid Signoff On Commit"
if: inputs.signoff-on-commit != 'true' && inputs.signoff-on-commit != 'false' && inputs.signoff-on-commit != 'yes' && inputs.signoff-on-commit != 'no'
shell: bash
run: echo "::error title=Fmtya Input Validation Error::Invalid boolean for signoff on commit '$SIGNOFF_ON_COMMIT'" ; exit 1
env:
SIGNOFF_ON_COMMIT: ${{ inputs.signoff-on-commit }}
- name: "Report Missing Files To Format"
if: inputs.include-files == ''
shell: bash
run: echo "::error title=Fmtya Input Validation Error::No include files provided" ; exit 1
- name: "Parse Configuration"
id: config
shell: bash
env:
INCLUDE_FILES: ${{ inputs.include-files }}
EXCLUDE_FILES: ${{ inputs.exclude-files }}
run: |
DELIMITER="$(openssl rand -hex 8)"
echo "::add-mask::$DELIMITER"
echo "include-files=$(echo "$INCLUDE_FILES" | awk 'NF>0' | jq -R | jq -R | jq -s | jq -r tostring)" | tee -a "$GITHUB_OUTPUT"
echo "exclude-files=$(echo "$EXCLUDE_FILES" | awk 'NF>0' | jq -R | jq -R | jq -s | jq -r tostring)" | tee -a "$GITHUB_OUTPUT"
echo "delimiter=$DELIMITER" | tee -a "$GITHUB_OUTPUT"
- name: "Configure yamlfmt"
shell: bash
run: |
cat << ${{ steps.config.outputs.delimiter }} | awk 'NF>0' | tee ${{ runner.temp }}/yamlfmt.conf
${{ steps.config.outputs.include-files && 'include:
- '|| '' }}${{ join(fromJSON(steps.config.outputs.include-files), '
- ') || '' }}
${{ steps.config.outputs.exclude-files && 'exclude:
- '|| '' }}${{ join(fromJSON(steps.config.outputs.exclude-files), '
- ') || '' }}
formatter:
type: basic
indent: ${{ inputs.indent-size }}
include_document_start: ${{ inputs.include-document-start }}
line_ending: ${{ inputs.line-ending-type }}
retain_line_breaks: ${{ inputs.keep-line-breaks }}
disallow_anchors: ${{ inputs.disallow-anchors }}
${{ steps.config.outputs.delimiter }}
- name: "Checkout"
uses: actions/checkout@v3.3.0
with:
ref: ${{ github.head_ref }}
token: ${{ inputs.token || github.token }}
- name: "Setup Go"
uses: actions/setup-go@v4.0.0
with:
token: ${{ inputs.token || github.token }}
- name: "Install yamlfmt"
shell: bash
run: go install "github.com/google/yamlfmt/cmd/yamlfmt@$VERSION"
env:
VERSION: ${{ inputs.yamlfmt-version }}
- name: "Run yamlfmt"
shell: bash
run: ~/go/bin/yamlfmt -conf "${{ runner.temp }}/yamlfmt.conf"
- name: "Setup GPG Keys"
if: inputs.signing-private-key != ''
continue-on-error: true
uses: crazy-max/ghaction-import-gpg@v5.2.0
with:
gpg_private_key: ${{ inputs.signing-private-key }}
passphrase: ${{ inputs.signing-passphrase }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: "Commit Changes"
uses: stefanzweifel/git-auto-commit-action@v4.16.0
with:
commit_user_name: ${{ inputs.commit-user-name }}
commit_user_email: ${{ inputs.commit-user-email }}
commit_message: ${{ inputs.commit-message }}
commit_options: >-
${{ inputs.signing-private-key != '' && '-S' || '' }}
${{ (inputs.signoff-on-commit == 'true' || inputs.signoff-on-commit == 'yes') && '-s' || '' }}