Skip to content

Commit 8096c62

Browse files
committed
Add multi-module support to project infrastructure
This projects contains two Go modules, one in the root and one in the `docsgen` subfolder. More will be added. In order to support checks on the supplemental modules in the project subfolders, it's necessary to configure the commands to run from their path. This is passed to the task via 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. The workflows use a job matrix to allow easy configuration for any number of module paths and a dedicated parallel job for each module.
1 parent bed7e04 commit 8096c62

File tree

3 files changed

+76
-7
lines changed

3 files changed

+76
-7
lines changed

Diff for: .github/workflows/check-go-task.yml

+44
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,19 @@ jobs:
5050
echo "::set-output name=result::$RESULT"
5151
5252
check-errors:
53+
name: check-errors (${{ matrix.module.path }})
5354
needs: run-determination
5455
if: needs.run-determination.outputs.result == 'true'
5556
runs-on: ubuntu-latest
5657

58+
strategy:
59+
fail-fast: false
60+
61+
matrix:
62+
module:
63+
- path: ./
64+
- path: docsgen
65+
5766
steps:
5867
- name: Checkout repository
5968
uses: actions/checkout@v2
@@ -70,13 +79,24 @@ jobs:
7079
version: 3.x
7180

7281
- name: Check for errors
82+
env:
83+
GO_MODULE_PATH: ${{ matrix.module.path }}
7384
run: task go:vet
7485

7586
check-outdated:
87+
name: check-outdated (${{ matrix.module.path }})
7688
needs: run-determination
7789
if: needs.run-determination.outputs.result == 'true'
7890
runs-on: ubuntu-latest
7991

92+
strategy:
93+
fail-fast: false
94+
95+
matrix:
96+
module:
97+
- path: ./
98+
- path: docsgen
99+
80100
steps:
81101
- name: Checkout repository
82102
uses: actions/checkout@v2
@@ -93,16 +113,27 @@ jobs:
93113
version: 3.x
94114

95115
- name: Modernize usages of outdated APIs
116+
env:
117+
GO_MODULE_PATH: ${{ matrix.module.path }}
96118
run: task go:fix
97119

98120
- name: Check if any fixes were needed
99121
run: git diff --color --exit-code
100122

101123
check-style:
124+
name: check-style (${{ matrix.module.path }})
102125
needs: run-determination
103126
if: needs.run-determination.outputs.result == 'true'
104127
runs-on: ubuntu-latest
105128

129+
strategy:
130+
fail-fast: false
131+
132+
matrix:
133+
module:
134+
- path: ./
135+
- path: docsgen
136+
106137
steps:
107138
- name: Checkout repository
108139
uses: actions/checkout@v2
@@ -122,13 +153,24 @@ jobs:
122153
run: go install golang.org/x/lint/golint@latest
123154

124155
- name: Check style
156+
env:
157+
GO_MODULE_PATH: ${{ matrix.module.path }}
125158
run: task --silent go:lint
126159

127160
check-formatting:
161+
name: check-formatting (${{ matrix.module.path }})
128162
needs: run-determination
129163
if: needs.run-determination.outputs.result == 'true'
130164
runs-on: ubuntu-latest
131165

166+
strategy:
167+
fail-fast: false
168+
169+
matrix:
170+
module:
171+
- path: ./
172+
- path: docsgen
173+
132174
steps:
133175
- name: Checkout repository
134176
uses: actions/checkout@v2
@@ -145,6 +187,8 @@ jobs:
145187
version: 3.x
146188

147189
- name: Format code
190+
env:
191+
GO_MODULE_PATH: ${{ matrix.module.path }}
148192
run: task go:format
149193

150194
- name: Check formatting

Diff for: .github/workflows/test-go-task.yml

+14-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ on:
1212
paths:
1313
- ".github/workflows/test-go-task.ya?ml"
1414
- "codecov.ya?ml"
15-
- "go.mod"
16-
- "go.sum"
15+
- "**/go.mod"
16+
- "**/go.sum"
1717
- "Taskfile.ya?ml"
1818
- "**.go"
1919
- "**/testdata/**"
2020
pull_request:
2121
paths:
2222
- ".github/workflows/test-go-task.ya?ml"
2323
- "codecov.ya?ml"
24-
- "go.mod"
25-
- "go.sum"
24+
- "**/go.mod"
25+
- "**/go.sum"
2626
- "Taskfile.ya?ml"
2727
- "**.go"
2828
- "**/testdata/**"
@@ -54,15 +54,21 @@ jobs:
5454
echo "::set-output name=result::$RESULT"
5555
5656
test:
57+
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
5758
needs: run-determination
5859
if: needs.run-determination.outputs.result == 'true'
5960

6061
strategy:
62+
fail-fast: false
63+
6164
matrix:
6265
operating-system:
6366
- ubuntu-latest
6467
- windows-latest
6568
- macos-latest
69+
module:
70+
- path: ./
71+
codecov-flags: unit
6672

6773
runs-on: ${{ matrix.operating-system }}
6874

@@ -82,12 +88,14 @@ jobs:
8288
version: 3.x
8389

8490
- name: Run tests
91+
env:
92+
GO_MODULE_PATH: ${{ matrix.module.path }}
8593
run: task go:test
8694

8795
- name: Send unit tests coverage to Codecov
8896
if: runner.os == 'Linux'
8997
uses: codecov/codecov-action@v2
9098
with:
91-
file: ./coverage_unit.txt
92-
flags: unit
99+
file: ${{ matrix.module.path }}coverage_unit.txt
100+
flags: ${{ matrix.module.codecov-flags }}
93101
fail_ci_if_error: ${{ github.repository == 'arduino/arduino-lint' }}

Diff for: Taskfile.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@ vars:
88
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/release-go-task/Taskfile.yml
99
PROJECT_NAME: "arduino-lint"
1010
DIST_DIR: "dist"
11+
# Path of the project's primary Go module:
12+
DEFAULT_GO_MODULE_PATH: ./
1113
DEFAULT_GO_PACKAGES:
12-
sh: echo $(go list ./... | grep --invert-match 'github.com/arduino/arduino-lint/internal/rule/schema/schemadata' | tr '\n' ' ')
14+
sh: |
15+
echo $( \
16+
cd {{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}} \
17+
&& \
18+
go list ./... | \
19+
grep --invert-match 'github.com/arduino/arduino-lint/internal/rule/schema/schemadata' | \
20+
tr '\n' ' ' \
21+
|| \
22+
echo '"ERROR: Unable to discover Go packages"' \
23+
)
1324
# build vars
1425
COMMIT:
1526
sh: echo "$(git log --no-show-signature -n 1 --format=%h)"
@@ -134,6 +145,7 @@ tasks:
134145
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
135146
go:build:
136147
desc: Build the Go code
148+
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
137149
cmds:
138150
- go build -v {{.LDFLAGS}}
139151

@@ -150,12 +162,14 @@ tasks:
150162
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
151163
go:fix:
152164
desc: Modernize usages of outdated APIs
165+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
153166
cmds:
154167
- go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
155168

156169
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
157170
go:format:
158171
desc: Format Go code
172+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
159173
cmds:
160174
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
161175

@@ -172,6 +186,7 @@ tasks:
172186
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
173187
go:lint:
174188
desc: Lint Go code
189+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
175190
cmds:
176191
- |
177192
if ! which golint &>/dev/null; then
@@ -186,6 +201,7 @@ tasks:
186201
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
187202
go:test:
188203
desc: Run unit tests
204+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
189205
cmds:
190206
- |
191207
go test \
@@ -208,6 +224,7 @@ tasks:
208224
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
209225
go:vet:
210226
desc: Check for errors in Go code
227+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
211228
cmds:
212229
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
213230

0 commit comments

Comments
 (0)