-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathaction.yaml
More file actions
62 lines (55 loc) · 1.79 KB
/
action.yaml
File metadata and controls
62 lines (55 loc) · 1.79 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright 2022 Chainguard, Inc.
# SPDX-License-Identifier: Apache-2.0
name: 'gofmt'
description: |
This action runs gofmt over the working tree and then verifies
that there are no differences from running the tool.
inputs:
args:
description: |
The arguments to pass to gofmt
required: false
working-directory:
description: |
The working directory to run goimports
default: "."
dirs:
description: |
Space separated list of dirs to search for go modules. Defaults to current directory.
default: "."
runs:
using: "composite"
steps:
- name: gofmt ${{ inputs.args }}
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
DIRS: ${{ inputs.dirs }}
run: |
set -xv
for subdir in ${DIRS}; do
echo "::subdir:: $subdir"
pushd $subdir
# We limit the depth to 3 mostly to avoid go.mod files that get pulled into `third_party` like some hashicorp repos.
for dir in $(find . -type d \( -path "*/third_party" -o -path "*/testdata" -o -path "*/.terraform" \) -prune -o -name go.mod -exec dirname {} \;| sort ); do
echo "::group:: $dir"
pushd $dir
gofmt ${{ inputs.args }} -w \
$(find . \
-path './vendor' -prune \
-o -path '*/third_party' -prune \
-o -path '*/testdata' -prune \
-o -name '*.pb.go' -prune \
-o -name '*.pb.gw.go' -prune \
-o -name 'wire_gen.go' -prune \
-o -type f -name '*.go' -print)
popd
echo ::endgroup::
done
popd
echo ::endsubdir::
done
- name: Verify gofmt
uses: chainguard-dev/actions/nodiff@71714a76c3df10b544595a2294c16649dc3472e5 # v1.6.5
with:
fixup-command: "gofmt ${{ inputs.args }}"