-
Notifications
You must be signed in to change notification settings - Fork 1
134 lines (122 loc) · 5.45 KB
/
go-lint.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
# Copyright 2023 The Authors (see AUTHORS file)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: 'go-lint'
on:
workflow_call:
inputs:
runs-on:
description: 'The GitHub runner on which to execute. This must be a valid JSON but can represent a string, array of strings, or object.'
type: 'string'
default: '"ubuntu-latest"'
go_version:
description: 'The version of Go to install and use.'
type: 'string'
go_version_file:
description: 'Path to the go.mod file to extract a version.'
type: 'string'
default: 'go.mod'
golangci_url:
description: 'The URL to a golangci file. This is only used if no file is found in the local directory.'
type: 'string'
default: 'https://raw.githubusercontent.com/abcxyz/pkg/main/.golangci.yml'
directory:
description: 'Directory in which Go files reside.'
type: 'string'
default: '.'
golangci_lint_version:
description: 'Version of golangci linter to use'
type: 'string'
default: 'v1.57'
jobs:
# modules checks if the go modules are all up-to-date. While rare with modern
# versions of Go, it's possible to take a dependency on a package without
# updating the module file.
#
# Do not change this job name. Job names are used as identifiers in status
# checks, and changing this name will cause status checks to fail.
modules:
runs-on: ${{ fromJSON(inputs.runs-on) }} # yamllint disable-line
steps:
- name: 'Checkout'
uses: 'actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b' # ratchet:actions/checkout@v4
- name: 'Setup Go'
uses: 'actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7' # ratchet:actions/setup-go@v5
with:
go-version: '${{ inputs.go_version }}'
go-version-file: '${{ inputs.go_version_file }}'
- name: 'Check modules'
shell: 'bash'
working-directory: '${{ inputs.directory }}'
run: |-
for d in $(find . -name go.mod); do
(cd $(dirname $d) && go mod tidy)
done
if [ -n "$(git status -s -uall)" ]; then
echo "::error title=Go module changes::Detected go module changes"
git -c color.ui=always diff
exit 1
fi
# golangci runs golangci-lint. If a .golangci.yml or .golangci.yaml file
# exists at the root of the repository, it uses those custom settings. If no
# such file exists, it uses a selection of sane defaults.
#
# Do not change this job name. Job names are used as identifiers in status
# checks, and changing this name will cause status checks to fail.
golangci:
runs-on: ${{ fromJSON(inputs.runs-on) }} # yamllint disable-line
steps:
- name: 'Checkout'
uses: 'actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b' # ratchet:actions/checkout@v4
- name: 'Setup Go'
uses: 'actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7' # ratchet:actions/setup-go@v5
with:
go-version: '${{ inputs.go_version }}'
go-version-file: '${{ inputs.go_version_file }}'
cache: false
- name: 'Lint (download default configuration)'
id: 'load-default-config'
if: |-
${{ hashFiles('.golangci.yml', '.golangci.yaml') == '' }}
run: |-
# Create a unique output file outside of the checkout.
GOLANGCI_YML="${RUNNER_TEMP}/${GITHUB_SHA:0:7}.golangci.yml"
# Download the file, passing in authentication to get a higher rate
# limit: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limits-for-requests-from-github-actions
curl "${{ inputs.golangci_url }}" \
--silent \
--fail \
--location \
--header "Authorization: Token ${{ github.token }}" \
--output "${GOLANGCI_YML}"
# Save the result to an output.
echo "::notice::Wrote configuration file to ${GOLANGCI_YML}"
echo "output-file=${GOLANGCI_YML}" >> "${GITHUB_OUTPUT}"
- name: 'Lint (default configuration)'
if: |-
${{ hashFiles('.golangci.yml', '.golangci.yaml') == '' }}
uses: 'golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc' # ratchet:golangci/golangci-lint-action@v5
with:
args: |-
--config "${{ steps.load-default-config.outputs.output-file }}"
skip-cache: true
version: '${{ inputs.golangci_lint_version }}'
working-directory: '${{ inputs.directory }}'
- name: 'Lint (custom configuration)'
if: |-
${{ hashFiles('.golangci.yml', '.golangci.yaml') != '' }}
uses: 'golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc' # ratchet:golangci/golangci-lint-action@v5
with:
skip-cache: true
version: '${{ inputs.golangci_lint_version }}'
working-directory: '${{ inputs.directory }}'