-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
130 lines (113 loc) · 3.53 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
name: 'yamlfmt action'
description: 'Format YAML files using yamlfmt'
branding:
icon: zap
color: gray-dark
inputs:
version:
description: 'The version of yamlfmt to use'
required: false
default: 'latest'
path:
description: 'Path to the YAML file or directory to format'
required: false
default: '.'
dstar:
description: 'Enable double-star expansion'
required: false
default: ''
exclude:
description: 'Exclude files matching the given pattern'
required: false
default: ''
gitignore_excludes:
description: 'Exclude files matching the patterns in .gitignore'
required: false
default: true
gitignore_path:
description: 'Path to the .gitignore file'
required: false
default: ''
extensions:
description: 'Comma-separated list of file extensions to include'
required: false
default: ''
formatter:
description: 'Configures the formatter to use'
required: false
default: ''
runs:
using: "composite"
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
check-latest: true
cache: false
- id: get_gobin
name: Get GOBIN
run: |
gobin=$(go env GOBIN)
if [ -z "$gobin" ]; then
gobin=$(go env GOPATH)/bin
fi
echo "path=$gobin" >> $GITHUB_OUTPUT
shell: bash
- id: get_yamlfmt_version
name: Get yamlfmt version
run: |
if [ "${{ inputs.version }}" = "latest" ]; then
version=$(go list -m -versions -json github.com/google/yamlfmt | jq -r '.Versions[-1]')
else
version="${{ inputs.version }}"
fi
echo "version=$version" >> $GITHUB_OUTPUT
shell: bash
- id: cache_gobin
name: Cache GOBIN
uses: actions/cache@v4
with:
path: ${{ steps.get_gobin.outputs.path }}
key: yamlfmt-${{ runner.os }}-${{ runner.arch }}-${{ steps.get_yamlfmt_version.outputs.version }}
- name: Install yamlfmt
if: steps.cache_gobin.outputs.cache-hit != 'true'
run: go install github.com/google/yamlfmt/cmd/yamlfmt@${{ steps.get_yamlfmt_version.outputs.version }}
shell: bash
- id: build_command
name: Build command options
run: |
cmd="yamlfmt -lint"
# Check if 'path' is not the default value
if [ "${{ inputs.path }}" != "" ]; then
cmd="$cmd ${{ inputs.path }}"
fi
# Check if 'dstar' is enabled
if [ "${{ inputs.dstar }}" != "" ]; then
cmd="$cmd --dstar ${{ inputs.dstar }}"
fi
# Check if 'exclude' has a value
if [ "${{ inputs.exclude }}" != "" ]; then
cmd="$cmd --exclude ${{ inputs.exclude }}"
fi
# Check if 'gitignore_excludes' is true
if [ "${{ inputs.gitignore_excludes }}" == "true" ]; then
cmd="$cmd --gitignore-excludes"
fi
# Check if 'gitignore_path' has a value
if [ "${{ inputs.gitignore_path }}" != "" ]; then
cmd="$cmd --gitignore-path ${{ inputs.gitignore_path }}"
fi
# Check if 'extensions' has a value
if [ "${{ inputs.extensions }}" != "" ]; then
cmd="$cmd --extensions ${{ inputs.extensions }}"
fi
# Check if 'formatter' has a value
if [ "${{ inputs.formatter }}" != "" ]; then
cmd="$cmd --formatter ${{ inputs.formatter }}"
fi
echo "command=$cmd" >> $GITHUB_OUTPUT
shell: bash
- name: Run yamlfmt
run: ${{ steps.build_command.outputs.command }}
shell: bash