Skip to content

Commit 3f2e910

Browse files
authored
[skip changelog] Run formatting and linting CI checks on all Go modules (#1390)
The repository contains multiple Go modules. Previously, the CI workflow that lints and checks the formatting of the repository's Go code was only checking the primary module in the root of the repo. This workflow is now expanded to cover all Go code through the use of a dedicated matrix job for each of the modules. Arbitrary Go module paths can be specified to the tasks by defining the `GO_MODULE_PATH` environment variable. If this variable is not defined, the default root module path is used as default, preserving the previous task behavior.
1 parent d052cf6 commit 3f2e910

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,20 @@ on:
2626

2727
jobs:
2828
check-errors:
29+
name: check-errors (${{ matrix.module.path }})
2930
runs-on: ubuntu-latest
3031

32+
strategy:
33+
fail-fast: false
34+
35+
matrix:
36+
module:
37+
- path: ./
38+
- path: arduino/discovery/discovery_client
39+
- path: client_example
40+
- path: commands/daemon/term_example
41+
- path: docsgen
42+
3143
steps:
3244
- name: Checkout repository
3345
uses: actions/checkout@v2
@@ -44,11 +56,25 @@ jobs:
4456
version: 3.x
4557

4658
- name: Check for errors
59+
env:
60+
GO_MODULE_PATH: ${{ matrix.module.path }}
4761
run: task go:vet
4862

4963
check-outdated:
64+
name: check-outdated (${{ matrix.module.path }})
5065
runs-on: ubuntu-latest
5166

67+
strategy:
68+
fail-fast: false
69+
70+
matrix:
71+
module:
72+
- path: ./
73+
- path: arduino/discovery/discovery_client
74+
- path: client_example
75+
- path: commands/daemon/term_example
76+
- path: docsgen
77+
5278
steps:
5379
- name: Checkout repository
5480
uses: actions/checkout@v2
@@ -65,14 +91,28 @@ jobs:
6591
version: 3.x
6692

6793
- name: Modernize usages of outdated APIs
94+
env:
95+
GO_MODULE_PATH: ${{ matrix.module.path }}
6896
run: task go:fix
6997

7098
- name: Check if any fixes were needed
7199
run: git diff --color --exit-code
72100

73101
check-style:
102+
name: check-style (${{ matrix.module.path }})
74103
runs-on: ubuntu-latest
75104

105+
strategy:
106+
fail-fast: false
107+
108+
matrix:
109+
module:
110+
- path: ./
111+
- path: arduino/discovery/discovery_client
112+
- path: client_example
113+
- path: commands/daemon/term_example
114+
- path: docsgen
115+
76116
steps:
77117
- name: Checkout repository
78118
uses: actions/checkout@v2
@@ -92,11 +132,25 @@ jobs:
92132
run: go install golang.org/x/lint/golint@latest
93133

94134
- name: Check style
135+
env:
136+
GO_MODULE_PATH: ${{ matrix.module.path }}
95137
run: task --silent go:lint
96138

97139
check-formatting:
140+
name: check-formatting (${{ matrix.module.path }})
98141
runs-on: ubuntu-latest
99142

143+
strategy:
144+
fail-fast: false
145+
146+
matrix:
147+
module:
148+
- path: ./
149+
- path: arduino/discovery/discovery_client
150+
- path: client_example
151+
- path: commands/daemon/term_example
152+
- path: docsgen
153+
100154
steps:
101155
- name: Checkout repository
102156
uses: actions/checkout@v2
@@ -113,6 +167,8 @@ jobs:
113167
version: 3.x
114168

115169
- name: Format code
170+
env:
171+
GO_MODULE_PATH: ${{ matrix.module.path }}
116172
run: task go:format
117173

118174
- name: Check formatting

Taskfile.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tasks:
2121
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
2222
go:build:
2323
desc: Build the Go code
24+
dir: '{{default "./" .GO_MODULE_PATH}}'
2425
cmds:
2526
- go build -v {{.LDFLAGS}}
2627

@@ -37,18 +38,21 @@ tasks:
3738
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
3839
go:fix:
3940
desc: Modernize usages of outdated APIs
41+
dir: '{{default "./" .GO_MODULE_PATH}}'
4042
cmds:
4143
- go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
4244

4345
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
4446
go:format:
4547
desc: Format Go code
48+
dir: '{{default "./" .GO_MODULE_PATH}}'
4649
cmds:
4750
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
4851

4952
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
5053
go:lint:
5154
desc: Lint Go code
55+
dir: '{{default "./" .GO_MODULE_PATH}}'
5256
cmds:
5357
- |
5458
if ! which golint &>/dev/null; then
@@ -63,6 +67,7 @@ tasks:
6367
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
6468
go:test:
6569
desc: Run unit tests
70+
dir: '{{default "./" .GO_MODULE_PATH}}'
6671
cmds:
6772
- |
6873
go test \
@@ -86,6 +91,7 @@ tasks:
8691
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
8792
go:vet:
8893
desc: Check for errors in Go code
94+
dir: '{{default "./" .GO_MODULE_PATH}}'
8995
cmds:
9096
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
9197

@@ -289,7 +295,8 @@ vars:
289295
DIST_DIR: "dist"
290296
# all modules of this project except for "legacy/..." module
291297
DEFAULT_GO_PACKAGES:
292-
sh: echo $(go list ./... | grep -v legacy | tr '\n' ' ')
298+
sh: |
299+
echo $(cd {{default "./" .GO_MODULE_PATH}} && go list ./... | grep -v legacy | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
293300
# build vars
294301
COMMIT:
295302
sh: echo "$(git log --no-show-signature -n 1 --format=%h)"

0 commit comments

Comments
 (0)