Skip to content

Commit 6355b7c

Browse files
authored
Merge pull request #136 from per1234/multi-module
Add multi-module support to Go "templates"
2 parents e952f84 + e5b2bf7 commit 6355b7c

File tree

9 files changed

+145
-25
lines changed

9 files changed

+145
-25
lines changed

workflow-templates/assets/check-go-task/Taskfile.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# See: https://taskfile.dev/#/usage
22
version: "3"
33

4-
vars:
5-
DEFAULT_GO_PACKAGES:
6-
sh: echo $(go list ./... | tr '\n' ' ')
7-
84
tasks:
95
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
106
go:check:
@@ -16,18 +12,21 @@ tasks:
1612
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
1713
go:vet:
1814
desc: Check for errors in Go code
15+
dir: '{{default "./" .GO_MODULE_PATH}}'
1916
cmds:
2017
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
2118

2219
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
2320
go:fix:
2421
desc: Modernize usages of outdated APIs
22+
dir: '{{default "./" .GO_MODULE_PATH}}'
2523
cmds:
2624
- go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
2725

2826
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
2927
go:lint:
3028
desc: Lint Go code
29+
dir: '{{default "./" .GO_MODULE_PATH}}'
3130
cmds:
3231
- |
3332
if ! which golint &>/dev/null; then
@@ -42,5 +41,6 @@ tasks:
4241
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
4342
go:format:
4443
desc: Format Go code
44+
dir: '{{default "./" .GO_MODULE_PATH}}'
4545
cmds:
4646
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}

workflow-templates/assets/go-task/Taskfile.yml

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

44
vars:
55
DEFAULT_GO_PACKAGES:
6-
sh: echo $(go list ./... | tr '\n' ' ')
6+
sh: |
7+
echo $(cd {{default "./" .GO_MODULE_PATH}} && go list ./... | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
78
LDFLAGS:
89

910
tasks:

workflow-templates/assets/test-go-task/Taskfile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tasks:
55
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
66
go:test:
77
desc: Run unit tests
8+
dir: '{{default "./" .GO_MODULE_PATH}}'
89
cmds:
910
- |
1011
go test \

workflow-templates/check-go-task.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ Install the [`check-go-task.yml`](check-go-task.yml) GitHub Actions workflow to
1919

2020
Configure the version of Go used for development of the project in the `env.GO_VERSION` field of `check-go-task.yml`.
2121

22+
If the project contains Go modules in paths other than the root of the repository, add their paths to the [job matrices](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) of `check-go-task.yml` at:
23+
24+
- `jobs.check-errors.strategy.matrix.module[].path`
25+
- `jobs.check-outdated.strategy.matrix.module[].path`
26+
- `jobs.check-style.strategy.matrix.module[].path`
27+
- `jobs.check-formatting.strategy.matrix.module[].path`
28+
- `jobs.check-config.strategy.matrix.module[].path`
29+
2230
### Readme badge
2331

2432
Markdown badge:

workflow-templates/check-go-task.yml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,32 @@ on:
1111
paths:
1212
- ".github/workflows/check-go-task.ya?ml"
1313
- "Taskfile.ya?ml"
14-
- "go.mod"
15-
- "go.sum"
14+
- "**/go.mod"
15+
- "**/go.sum"
1616
- "**.go"
1717
pull_request:
1818
paths:
1919
- ".github/workflows/check-go-task.ya?ml"
2020
- "Taskfile.ya?ml"
21-
- "go.mod"
22-
- "go.sum"
21+
- "**/go.mod"
22+
- "**/go.sum"
2323
- "**.go"
2424
workflow_dispatch:
2525
repository_dispatch:
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+
# TODO: add paths of all Go modules here
38+
- path: ./
39+
3140
steps:
3241
- name: Checkout repository
3342
uses: actions/checkout@v2
@@ -44,11 +53,22 @@ jobs:
4453
version: 3.x
4554

4655
- name: Check for errors
56+
env:
57+
GO_MODULE_PATH: ${{ matrix.module.path }}
4758
run: task go:vet
4859

4960
check-outdated:
61+
name: check-outdated (${{ matrix.module.path }})
5062
runs-on: ubuntu-latest
5163

64+
strategy:
65+
fail-fast: false
66+
67+
matrix:
68+
module:
69+
# TODO: add paths of all Go modules here
70+
- path: ./
71+
5272
steps:
5373
- name: Checkout repository
5474
uses: actions/checkout@v2
@@ -65,14 +85,25 @@ jobs:
6585
version: 3.x
6686

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

7092
- name: Check if any fixes were needed
7193
run: git diff --color --exit-code
7294

7395
check-style:
96+
name: check-style (${{ matrix.module.path }})
7497
runs-on: ubuntu-latest
7598

99+
strategy:
100+
fail-fast: false
101+
102+
matrix:
103+
module:
104+
# TODO: add paths of all Go modules here
105+
- path: ./
106+
76107
steps:
77108
- name: Checkout repository
78109
uses: actions/checkout@v2
@@ -92,11 +123,22 @@ jobs:
92123
run: go install golang.org/x/lint/golint@latest
93124

94125
- name: Check style
126+
env:
127+
GO_MODULE_PATH: ${{ matrix.module.path }}
95128
run: task --silent go:lint
96129

97130
check-formatting:
131+
name: check-formatting (${{ matrix.module.path }})
98132
runs-on: ubuntu-latest
99133

134+
strategy:
135+
fail-fast: false
136+
137+
matrix:
138+
module:
139+
# TODO: add paths of all Go modules here
140+
- path: ./
141+
100142
steps:
101143
- name: Checkout repository
102144
uses: actions/checkout@v2
@@ -113,6 +155,8 @@ jobs:
113155
version: 3.x
114156

115157
- name: Format code
158+
env:
159+
GO_MODULE_PATH: ${{ matrix.module.path }}
116160
run: task go:format
117161

118162
- name: Check formatting

workflow-templates/dependabot/workflow-template-copies/.github/workflows/check-go-task.yml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,32 @@ on:
1111
paths:
1212
- ".github/workflows/check-go-task.ya?ml"
1313
- "Taskfile.ya?ml"
14-
- "go.mod"
15-
- "go.sum"
14+
- "**/go.mod"
15+
- "**/go.sum"
1616
- "**.go"
1717
pull_request:
1818
paths:
1919
- ".github/workflows/check-go-task.ya?ml"
2020
- "Taskfile.ya?ml"
21-
- "go.mod"
22-
- "go.sum"
21+
- "**/go.mod"
22+
- "**/go.sum"
2323
- "**.go"
2424
workflow_dispatch:
2525
repository_dispatch:
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+
# TODO: add paths of all Go modules here
38+
- path: ./
39+
3140
steps:
3241
- name: Checkout repository
3342
uses: actions/checkout@v2
@@ -44,11 +53,22 @@ jobs:
4453
version: 3.x
4554

4655
- name: Check for errors
56+
env:
57+
GO_MODULE_PATH: ${{ matrix.module.path }}
4758
run: task go:vet
4859

4960
check-outdated:
61+
name: check-outdated (${{ matrix.module.path }})
5062
runs-on: ubuntu-latest
5163

64+
strategy:
65+
fail-fast: false
66+
67+
matrix:
68+
module:
69+
# TODO: add paths of all Go modules here
70+
- path: ./
71+
5272
steps:
5373
- name: Checkout repository
5474
uses: actions/checkout@v2
@@ -65,14 +85,25 @@ jobs:
6585
version: 3.x
6686

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

7092
- name: Check if any fixes were needed
7193
run: git diff --color --exit-code
7294

7395
check-style:
96+
name: check-style (${{ matrix.module.path }})
7497
runs-on: ubuntu-latest
7598

99+
strategy:
100+
fail-fast: false
101+
102+
matrix:
103+
module:
104+
# TODO: add paths of all Go modules here
105+
- path: ./
106+
76107
steps:
77108
- name: Checkout repository
78109
uses: actions/checkout@v2
@@ -92,11 +123,22 @@ jobs:
92123
run: go install golang.org/x/lint/golint@latest
93124

94125
- name: Check style
126+
env:
127+
GO_MODULE_PATH: ${{ matrix.module.path }}
95128
run: task --silent go:lint
96129

97130
check-formatting:
131+
name: check-formatting (${{ matrix.module.path }})
98132
runs-on: ubuntu-latest
99133

134+
strategy:
135+
fail-fast: false
136+
137+
matrix:
138+
module:
139+
# TODO: add paths of all Go modules here
140+
- path: ./
141+
100142
steps:
101143
- name: Checkout repository
102144
uses: actions/checkout@v2
@@ -113,6 +155,8 @@ jobs:
113155
version: 3.x
114156

115157
- name: Format code
158+
env:
159+
GO_MODULE_PATH: ${{ matrix.module.path }}
116160
run: task go:format
117161

118162
- name: Check formatting

workflow-templates/dependabot/workflow-template-copies/.github/workflows/test-go-task.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ on:
1111
paths:
1212
- ".github/workflows/test-go-task.ya?ml"
1313
- "codecov.ya?ml"
14-
- "go.mod"
15-
- "go.sum"
14+
- "**/go.mod"
15+
- "**/go.sum"
1616
- "Taskfile.ya?ml"
1717
- "**.go"
1818
- "**/testdata/**"
1919
pull_request:
2020
paths:
2121
- ".github/workflows/test-go-task.ya?ml"
2222
- "codecov.ya?ml"
23-
- "go.mod"
24-
- "go.sum"
23+
- "**/go.mod"
24+
- "**/go.sum"
2525
- "Taskfile.ya?ml"
2626
- "**.go"
2727
- "**/testdata/**"
@@ -30,12 +30,20 @@ on:
3030

3131
jobs:
3232
test:
33+
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
34+
3335
strategy:
36+
fail-fast: false
37+
3438
matrix:
3539
operating-system:
3640
- ubuntu-latest
3741
- windows-latest
3842
- macos-latest
43+
module:
44+
# TODO: add paths of all Go modules here
45+
- path: ./
46+
codecov-flags: unit
3947

4048
runs-on: ${{ matrix.operating-system }}
4149

@@ -55,12 +63,14 @@ jobs:
5563
version: 3.x
5664

5765
- name: Run tests
66+
env:
67+
GO_MODULE_PATH: ${{ matrix.module.path }}
5868
run: task go:test
5969

6070
- name: Send unit tests coverage to Codecov
6171
if: matrix.operating-system == 'ubuntu-latest'
6272
uses: codecov/codecov-action@v2
6373
with:
64-
file: ./coverage_unit.txt
65-
flags: unit
74+
file: ${{ matrix.module.path }}coverage_unit.txt
75+
flags: ${{ matrix.module.codecov-flags }}
6676
fail_ci_if_error: true

workflow-templates/test-go-task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Install the [`test-go-task.yml`](test-go-task.yml) GitHub Actions workflow to `.
2323

2424
Configure the version of Go used for development of the project in the `env.GO_VERSION` field of `test-go-task.yml`.
2525

26+
If the project contains Go modules in paths other than the root of the repository, add their paths to the [job matrix](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) in `check-go-task.yml` at `jobs.test.strategy.matrix.module[].path` and the [Codecov flag](https://docs.codecov.com/docs/flags) to group their data under at `jobs.test.strategy.matrix.module[].codecov-flags`
27+
2628
#### `.gitignore`
2729

2830
Add the following to `.gitignore`:

0 commit comments

Comments
 (0)