Skip to content

Commit e709fb5

Browse files
authored
Merge pull request #71 from per1234/multi-module-support
Add multi-module support to project infrastructure
2 parents e598ad7 + fc19c7d commit e709fb5

File tree

3 files changed

+81
-10
lines changed

3 files changed

+81
-10
lines changed

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

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ on:
1010
paths:
1111
- ".github/workflows/check-go-task.yml"
1212
- "Taskfile.yml"
13-
- "go.mod"
14-
- "go.sum"
13+
- "**/go.mod"
14+
- "**/go.sum"
1515
- "**.go"
1616
pull_request:
1717
paths:
1818
- ".github/workflows/check-go-task.yml"
1919
- "Taskfile.yml"
20-
- "go.mod"
21-
- "go.sum"
20+
- "**/go.mod"
21+
- "**/go.sum"
2222
- "**.go"
2323
schedule:
2424
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to tools.
@@ -28,8 +28,16 @@ on:
2828

2929
jobs:
3030
check-errors:
31+
name: check-errors (${{ matrix.module.path }})
3132
runs-on: ubuntu-latest
3233

34+
strategy:
35+
fail-fast: false
36+
37+
matrix:
38+
module:
39+
- path: ./
40+
3341
steps:
3442
- name: Checkout repository
3543
uses: actions/checkout@v2
@@ -46,11 +54,21 @@ jobs:
4654
version: 3.x
4755

4856
- name: Check for errors
57+
env:
58+
GO_MODULE_PATH: ${{ matrix.module.path }}
4959
run: task go:vet
5060

5161
check-outdated:
62+
name: check-outdated (${{ matrix.module.path }})
5263
runs-on: ubuntu-latest
5364

65+
strategy:
66+
fail-fast: false
67+
68+
matrix:
69+
module:
70+
- path: ./
71+
5472
steps:
5573
- name: Checkout repository
5674
uses: actions/checkout@v2
@@ -67,14 +85,24 @@ jobs:
6785
version: 3.x
6886

6987
- name: Modernize usages of outdated APIs
88+
env:
89+
GO_MODULE_PATH: ${{ matrix.module.path }}
7090
run: task go:fix
7191

7292
- name: Check if any fixes were needed
7393
run: git diff --color --exit-code
7494

7595
check-style:
96+
name: check-style (${{ matrix.module.path }})
7697
runs-on: ubuntu-latest
7798

99+
strategy:
100+
fail-fast: false
101+
102+
matrix:
103+
module:
104+
- path: ./
105+
78106
steps:
79107
- name: Checkout repository
80108
uses: actions/checkout@v2
@@ -94,11 +122,21 @@ jobs:
94122
run: go install golang.org/x/lint/golint@latest
95123

96124
- name: Check style
125+
env:
126+
GO_MODULE_PATH: ${{ matrix.module.path }}
97127
run: task --silent go:lint
98128

99129
check-formatting:
130+
name: check-formatting (${{ matrix.module.path }})
100131
runs-on: ubuntu-latest
101132

133+
strategy:
134+
fail-fast: false
135+
136+
matrix:
137+
module:
138+
- path: ./
139+
102140
steps:
103141
- name: Checkout repository
104142
uses: actions/checkout@v2
@@ -115,14 +153,24 @@ jobs:
115153
version: 3.x
116154

117155
- name: Format code
156+
env:
157+
GO_MODULE_PATH: ${{ matrix.module.path }}
118158
run: task go:format
119159

120160
- name: Check formatting
121161
run: git diff --color --exit-code
122162

123163
check-config:
164+
name: check-config (${{ matrix.module.path }})
124165
runs-on: ubuntu-latest
125166

167+
strategy:
168+
fail-fast: false
169+
170+
matrix:
171+
module:
172+
- path: ./
173+
126174
steps:
127175
- name: Checkout repository
128176
uses: actions/checkout@v2
@@ -133,6 +181,7 @@ jobs:
133181
go-version: ${{ env.GO_VERSION }}
134182

135183
- name: Run go mod tidy
184+
working-directory: ${{ matrix.module.path }}
136185
run: go mod tidy
137186

138187
- name: Check whether any tidying was needed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ on:
1010
push:
1111
paths:
1212
- ".github/workflows/test-go-task.ya?ml"
13-
- "go.mod"
14-
- "go.sum"
13+
- "**/go.mod"
14+
- "**/go.sum"
1515
- "Taskfile.ya?ml"
1616
- "**/testdata/**"
1717
- "**.go"
1818
pull_request:
1919
paths:
2020
- ".github/workflows/test-go-task.ya?ml"
21-
- "go.mod"
22-
- "go.sum"
21+
- "**/go.mod"
22+
- "**/go.sum"
2323
- "Taskfile.ya?ml"
2424
- "**/testdata/**"
2525
- "**.go"
@@ -56,7 +56,18 @@ jobs:
5656
name: libraries-repository-engine
5757

5858
test:
59-
runs-on: ubuntu-latest
59+
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
60+
61+
strategy:
62+
fail-fast: false
63+
64+
matrix:
65+
operating-system:
66+
- ubuntu-latest
67+
module:
68+
- path: ./
69+
70+
runs-on: ${{ matrix.operating-system }}
6071

6172
steps:
6273
- name: Checkout repository
@@ -88,4 +99,6 @@ jobs:
8899
version: 3.x
89100

90101
- name: Run tests
102+
env:
103+
GO_MODULE_PATH: ${{ matrix.module.path }}
91104
run: task go:test

Taskfile.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
version: "3"
33

44
vars:
5+
# Path of the project's primary Go module:
6+
DEFAULT_GO_MODULE_PATH: ./
57
DEFAULT_GO_PACKAGES:
6-
sh: echo $(go list ./... | tr '\n' ' ')
8+
sh: |
9+
echo $(cd {{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}} && go list ./... | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
710
811
tasks:
912
build:
@@ -31,12 +34,14 @@ tasks:
3134
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
3235
go:build:
3336
desc: Build the Go code
37+
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
3438
cmds:
3539
- go build -v -o libraries-repository-engine{{exeExt}}
3640

3741
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
3842
go:test:
3943
desc: Run unit tests
44+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
4045
cmds:
4146
- go test -v -short -run '{{default ".*" .GO_TEST_REGEX}}' {{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} -coverprofile=coverage_unit.txt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
4247

@@ -58,18 +63,21 @@ tasks:
5863
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
5964
go:vet:
6065
desc: Check for errors in Go code
66+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
6167
cmds:
6268
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
6369

6470
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
6571
go:fix:
6672
desc: Modernize usages of outdated APIs
73+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
6774
cmds:
6875
- go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
6976

7077
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
7178
go:lint:
7279
desc: Lint Go code
80+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
7381
cmds:
7482
- |
7583
if ! which golint &>/dev/null; then
@@ -84,6 +92,7 @@ tasks:
8492
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
8593
go:format:
8694
desc: Format Go code
95+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
8796
cmds:
8897
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
8998

0 commit comments

Comments
 (0)