Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bee41c0

Browse files
authored
Merge pull request #213 from per1234/check-go
Use "Check Go" template workflow and related tasks
2 parents 06d44af + a897ddf commit bee41c0

File tree

20 files changed

+232
-122
lines changed

20 files changed

+232
-122
lines changed

‎.github/workflows/check-formatting.yml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
- ".github/workflows/check-formatting.yml"
77
- "Taskfile.yml"
88
- ".prettierrc"
9-
- "**.go"
109
- "**.json"
1110
- "**.md"
1211
- "**.yaml"
@@ -16,7 +15,6 @@ on:
1615
- ".github/workflows/check-formatting.yml"
1716
- "Taskfile.yml"
1817
- ".prettierrc"
19-
- "**.go"
2018
- "**.json"
2119
- "**.md"
2220
- "**.yaml"
@@ -36,9 +34,6 @@ jobs:
3634
repo-token: ${{ secrets.GITHUB_TOKEN }}
3735
version: 3.x
3836

39-
- name: Check Go code formatting
40-
run: task go:check-formatting
41-
4237
- name: Check shell script formatting
4338
# https://github.com/mvdan/sh
4439
run: |

‎.github/workflows/check-go-task.yml‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-task.md
2+
name: Check Go
3+
4+
env:
5+
# See: https://github.com/actions/setup-go/tree/v2#readme
6+
GO_VERSION: "1.14"
7+
8+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
9+
on:
10+
push:
11+
paths:
12+
- ".github/workflows/check-go-task.ya?ml"
13+
- "Taskfile.ya?ml"
14+
- "go.mod"
15+
- "go.sum"
16+
- "**.go"
17+
pull_request:
18+
paths:
19+
- ".github/workflows/check-go-task.ya?ml"
20+
- "Taskfile.ya?ml"
21+
- "go.mod"
22+
- "go.sum"
23+
- "**.go"
24+
workflow_dispatch:
25+
repository_dispatch:
26+
27+
jobs:
28+
check-errors:
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v2
34+
35+
- name: Install Go
36+
uses: actions/setup-go@v2
37+
with:
38+
go-version: ${{ env.GO_VERSION }}
39+
40+
- name: Install Task
41+
uses: arduino/setup-task@v1
42+
with:
43+
repo-token: ${{ secrets.GITHUB_TOKEN }}
44+
version: 3.x
45+
46+
- name: Check for errors
47+
run: task go:vet
48+
49+
check-outdated:
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- name: Checkout repository
54+
uses: actions/checkout@v2
55+
56+
- name: Install Go
57+
uses: actions/setup-go@v2
58+
with:
59+
go-version: ${{ env.GO_VERSION }}
60+
61+
- name: Install Task
62+
uses: arduino/setup-task@v1
63+
with:
64+
repo-token: ${{ secrets.GITHUB_TOKEN }}
65+
version: 3.x
66+
67+
- name: Modernize usages of outdated APIs
68+
run: task go:fix
69+
70+
- name: Check if any fixes were needed
71+
run: git diff --color --exit-code
72+
73+
check-style:
74+
runs-on: ubuntu-latest
75+
76+
steps:
77+
- name: Checkout repository
78+
uses: actions/checkout@v2
79+
80+
- name: Install Go
81+
uses: actions/setup-go@v2
82+
with:
83+
go-version: ${{ env.GO_VERSION }}
84+
85+
- name: Install Task
86+
uses: arduino/setup-task@v1
87+
with:
88+
repo-token: ${{ secrets.GITHUB_TOKEN }}
89+
version: 3.x
90+
91+
- name: Check style
92+
run: task --silent go:lint
93+
94+
check-formatting:
95+
runs-on: ubuntu-latest
96+
97+
steps:
98+
- name: Checkout repository
99+
uses: actions/checkout@v2
100+
101+
- name: Install Go
102+
uses: actions/setup-go@v2
103+
with:
104+
go-version: ${{ env.GO_VERSION }}
105+
106+
- name: Install Task
107+
uses: arduino/setup-task@v1
108+
with:
109+
repo-token: ${{ secrets.GITHUB_TOKEN }}
110+
version: 3.x
111+
112+
- name: Format code
113+
run: task go:format
114+
115+
- name: Check formatting
116+
run: git diff --color --exit-code
117+
118+
check-config:
119+
runs-on: ubuntu-latest
120+
121+
steps:
122+
- name: Checkout repository
123+
uses: actions/checkout@v2
124+
125+
- name: Install Go
126+
uses: actions/setup-go@v2
127+
with:
128+
go-version: ${{ env.GO_VERSION }}
129+
130+
- name: Run go mod tidy
131+
run: go mod tidy
132+
133+
- name: Check whether any tidying was needed
134+
run: git diff --color --exit-code

‎.github/workflows/lint-code.yml‎

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Arduino Lint
22

33
[![Tests Status](https://github.com/arduino/arduino-lint/workflows/Run%20tests/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Run+tests)
4+
[![Check Go status](https://github.com/arduino/arduino-lint/actions/workflows/check-go-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-go-task.yml)
45
[![Nightly Status](https://github.com/arduino/arduino-lint/workflows/Nightly%20build/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Nightly+build)
56
[![Docs Status](https://github.com/arduino/arduino-lint/workflows/Publish%20documentation/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Publish+documentation)
67
[![Codecov](https://codecov.io/gh/arduino/arduino-lint/branch/main/graph/badge.svg?token=nprqPQMbdh)](https://codecov.io/gh/arduino/arduino-lint)

‎Taskfile.yml‎

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tasks:
2828
go:test-unit:
2929
desc: Run unit tests
3030
cmds:
31-
- go test -short -run '{{ default ".*" .TEST_REGEX }}' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default .DEFAULT_PACKAGES .PACKAGES }}
31+
- go test -short -run '{{ default ".*" .TEST_REGEX }}' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default .DEFAULT_GO_PACKAGES .GO_PACKAGES }}
3232

3333
test-integration:
3434
desc: Run integration tests
@@ -49,6 +49,7 @@ tasks:
4949
lint:
5050
desc: Lint all files
5151
cmds:
52+
- task: go:vet
5253
- task: go:lint
5354
- task: python:lint
5455
- task: docs:lint
@@ -57,7 +58,6 @@ tasks:
5758
check-formatting:
5859
desc: Check formatting of all files
5960
cmds:
60-
- task: go:check-formatting
6161
- task: docs:check-formatting
6262
- task: config:check-formatting
6363

@@ -69,32 +69,46 @@ tasks:
6969
- task: docs:format
7070
- task: config:format
7171

72+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
7273
go:check:
73-
desc: Lint and check formatting of Go code
74-
cmds:
74+
desc: Check for problems with Go code
75+
deps:
76+
- task: go:vet
7577
- task: go:lint
76-
- task: go:check-formatting
7778

79+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
80+
go:vet:
81+
desc: Check for errors in Go code
82+
cmds:
83+
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
84+
85+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
86+
go:fix:
87+
desc: Modernize usages of outdated APIs
88+
cmds:
89+
- go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
90+
91+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
7892
go:lint:
7993
desc: Lint Go code
8094
cmds:
81-
- go vet {{ default .DEFAULT_PACKAGES .PACKAGES }}
8295
- |
96+
PROJECT_PATH="$PWD"
97+
# `go get` and `go list` commands must be run from a temporary folder to avoid polluting go.mod
98+
cd "$(mktemp -d "${TMPDIR-${TMP-/tmp}}/task-temporary-XXXXX")"
99+
go get golang.org/x/lint/golint
83100
GOLINT_PATH="$(go list -f '{{"{{"}}.Target{{"}}"}}' golang.org/x/lint/golint || echo "false")"
84-
"$GOLINT_PATH" {{.GOLINTFLAGS}} "{{ default .DEFAULT_TARGETS .TARGETS }}"
85-
86-
go:check-formatting:
87-
desc: Check Go code formatting
88-
cmds:
89-
- |
90-
RESULTS="$(gofmt -l {{ default .DEFAULT_PATHS .PATHS }})"
91-
echo "$RESULTS"
92-
test -z "$RESULTS"
101+
# `golint` must be run from the module folder
102+
cd "$PROJECT_PATH"
103+
"$GOLINT_PATH" \
104+
{{default "-min_confidence 0.8 -set_exit_status" .GO_LINT_FLAGS}} \
105+
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
93106
107+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
94108
go:format:
95109
desc: Format Go code
96110
cmds:
97-
- gofmt -l -w {{ default .DEFAULT_PATHS .PATHS }}
111+
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
98112

99113
python:check:
100114
cmds:
@@ -263,10 +277,8 @@ tasks:
263277
vars:
264278
PROJECT_NAME: "arduino-lint"
265279
DIST_DIR: "dist"
266-
DEFAULT_PACKAGES:
267-
sh: echo `go list ./... | tr '\n' ' '`
268-
DEFAULT_PATHS:
269-
sh: echo '`go list -f '{{"{{"}}.Dir{{"}}"}}' ./...`'
280+
DEFAULT_GO_PACKAGES:
281+
sh: echo `go list ./... | grep --invert-match 'github.com/arduino/arduino-lint/internal/rule/schema/schemadata' | tr '\n' ' '`
270282
# build vars
271283
COMMIT:
272284
sh: echo "$(git log -n 1 --format=%h)"
@@ -286,7 +298,6 @@ vars:
286298
-X {{ .CONFIGURATION_PACKAGE }}.buildTimestamp={{.TIMESTAMP}}
287299
'
288300
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"
289-
GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status"
290301

291302
DOCS_VERSION: dev
292303
DOCS_ALIAS: ""

‎go.sum‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,8 +1194,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
11941194
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
11951195
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
11961196
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
1197-
golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY=
1198-
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
11991197
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
12001198
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
12011199
golang.org/x/net v0.0.0-20180406214816-61147c48b25b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

‎internal/project/projecttype/projecttype.go‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ import (
2626
type Type int
2727

2828
const (
29-
Sketch Type = iota // sketch
30-
Library // library
31-
Platform // platform
32-
PackageIndex // package-index
33-
All // all
34-
Not // N/A
29+
// Sketch is used for Arduino sketch projects.
30+
Sketch Type = iota // sketch
31+
// Library is used for Arduino library projects.
32+
Library // library
33+
// Platform is used for Arduino boards platform projects.
34+
Platform // platform
35+
// PackageIndex is used for Arduino package index projects.
36+
PackageIndex // package-index
37+
// All is the catch-all for all supported Arduino project types.
38+
All // all
39+
// Not is the project type used when an Arduino project was not detected.
40+
Not // N/A
3541
)
3642

3743
// FromString parses the --project-type flag value and returns the corresponding project type.

‎internal/result/outputformat/outputformat.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ import (
2626
type Type int
2727

2828
const (
29+
// Text is the text output format.
2930
Text Type = iota // text
30-
JSON // json
31+
// JSON is the JSON output format.
32+
JSON // json
3133
)
3234

3335
// FromString parses the --format flag value and returns the corresponding output format type.

‎internal/result/result.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ func (results *Type) AddProjectSummary(lintedProject project.Type) {
200200
for _, ruleReport := range results.Projects[projectReportIndex].Rules {
201201
if ruleReport.Result == ruleresult.Fail.String() {
202202
if ruleReport.Level == rulelevel.Warning.String() {
203-
warningCount+=1
203+
warningCount++
204204
} else if ruleReport.Level == rulelevel.Error.String() {
205-
errorCount+=1
205+
errorCount++
206206
pass = false
207207
}
208208
}

‎internal/result/result_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func TestAddProjectSummary(t *testing.T) {
208208
if (result == ruleresult.Fail) || configuration.Verbose() {
209209
level := testTable.levels[testDataIndex].String()
210210
results.Projects[0].Rules[ruleIndex].Level = level
211-
ruleIndex+=1
211+
ruleIndex++
212212
}
213213
}
214214
results.AddProjectSummary(lintedProject)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /