Skip to content

Add multi-module support to Go "templates" #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions workflow-templates/assets/check-go-task/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# See: https://taskfile.dev/#/usage
version: "3"

vars:
DEFAULT_GO_PACKAGES:
sh: echo $(go list ./... | tr '\n' ' ')

tasks:
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:check:
Expand All @@ -16,18 +12,21 @@ tasks:
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:vet:
desc: Check for errors in Go code
dir: '{{default "./" .GO_MODULE_PATH}}'
cmds:
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}

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

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:lint:
desc: Lint Go code
dir: '{{default "./" .GO_MODULE_PATH}}'
cmds:
- |
if ! which golint &>/dev/null; then
Expand All @@ -42,5 +41,6 @@ tasks:
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:format:
desc: Format Go code
dir: '{{default "./" .GO_MODULE_PATH}}'
cmds:
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
3 changes: 2 additions & 1 deletion workflow-templates/assets/go-task/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ version: "3"

vars:
DEFAULT_GO_PACKAGES:
sh: echo $(go list ./... | tr '\n' ' ')
sh: |
echo $(cd {{default "./" .GO_MODULE_PATH}} && go list ./... | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
LDFLAGS:

tasks:
Expand Down
1 change: 1 addition & 0 deletions workflow-templates/assets/test-go-task/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tasks:
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
go:test:
desc: Run unit tests
dir: '{{default "./" .GO_MODULE_PATH}}'
cmds:
- |
go test \
Expand Down
8 changes: 8 additions & 0 deletions workflow-templates/check-go-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Install the [`check-go-task.yml`](check-go-task.yml) GitHub Actions workflow to

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

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:

- `jobs.check-errors.strategy.matrix.module[].path`
- `jobs.check-outdated.strategy.matrix.module[].path`
- `jobs.check-style.strategy.matrix.module[].path`
- `jobs.check-formatting.strategy.matrix.module[].path`
- `jobs.check-config.strategy.matrix.module[].path`

### Readme badge

Markdown badge:
Expand Down
52 changes: 48 additions & 4 deletions workflow-templates/check-go-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,32 @@ on:
paths:
- ".github/workflows/check-go-task.ya?ml"
- "Taskfile.ya?ml"
- "go.mod"
- "go.sum"
- "**/go.mod"
- "**/go.sum"
- "**.go"
pull_request:
paths:
- ".github/workflows/check-go-task.ya?ml"
- "Taskfile.ya?ml"
- "go.mod"
- "go.sum"
- "**/go.mod"
- "**/go.sum"
- "**.go"
workflow_dispatch:
repository_dispatch:

jobs:
check-errors:
name: check-errors (${{ matrix.module.path }})
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
module:
# TODO: add paths of all Go modules here
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -44,11 +53,22 @@ jobs:
version: 3.x

- name: Check for errors
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:vet

check-outdated:
name: check-outdated (${{ matrix.module.path }})
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
module:
# TODO: add paths of all Go modules here
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -65,14 +85,25 @@ jobs:
version: 3.x

- name: Modernize usages of outdated APIs
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:fix

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

check-style:
name: check-style (${{ matrix.module.path }})
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
module:
# TODO: add paths of all Go modules here
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -92,11 +123,22 @@ jobs:
run: go install golang.org/x/lint/golint@latest

- name: Check style
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task --silent go:lint

check-formatting:
name: check-formatting (${{ matrix.module.path }})
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
module:
# TODO: add paths of all Go modules here
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -113,6 +155,8 @@ jobs:
version: 3.x

- name: Format code
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:format

- name: Check formatting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,32 @@ on:
paths:
- ".github/workflows/check-go-task.ya?ml"
- "Taskfile.ya?ml"
- "go.mod"
- "go.sum"
- "**/go.mod"
- "**/go.sum"
- "**.go"
pull_request:
paths:
- ".github/workflows/check-go-task.ya?ml"
- "Taskfile.ya?ml"
- "go.mod"
- "go.sum"
- "**/go.mod"
- "**/go.sum"
- "**.go"
workflow_dispatch:
repository_dispatch:

jobs:
check-errors:
name: check-errors (${{ matrix.module.path }})
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
module:
# TODO: add paths of all Go modules here
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -44,11 +53,22 @@ jobs:
version: 3.x

- name: Check for errors
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:vet

check-outdated:
name: check-outdated (${{ matrix.module.path }})
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
module:
# TODO: add paths of all Go modules here
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -65,14 +85,25 @@ jobs:
version: 3.x

- name: Modernize usages of outdated APIs
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:fix

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

check-style:
name: check-style (${{ matrix.module.path }})
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
module:
# TODO: add paths of all Go modules here
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -92,11 +123,22 @@ jobs:
run: go install golang.org/x/lint/golint@latest

- name: Check style
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task --silent go:lint

check-formatting:
name: check-formatting (${{ matrix.module.path }})
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
module:
# TODO: add paths of all Go modules here
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -113,6 +155,8 @@ jobs:
version: 3.x

- name: Format code
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:format

- name: Check formatting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ on:
paths:
- ".github/workflows/test-go-task.ya?ml"
- "codecov.ya?ml"
- "go.mod"
- "go.sum"
- "**/go.mod"
- "**/go.sum"
- "Taskfile.ya?ml"
- "**.go"
- "**/testdata/**"
pull_request:
paths:
- ".github/workflows/test-go-task.ya?ml"
- "codecov.ya?ml"
- "go.mod"
- "go.sum"
- "**/go.mod"
- "**/go.sum"
- "Taskfile.ya?ml"
- "**.go"
- "**/testdata/**"
Expand All @@ -30,12 +30,20 @@ on:

jobs:
test:
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})

strategy:
fail-fast: false

matrix:
operating-system:
- ubuntu-latest
- windows-latest
- macos-latest
module:
# TODO: add paths of all Go modules here
- path: ./
codecov-flags: unit

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

Expand All @@ -55,12 +63,14 @@ jobs:
version: 3.x

- name: Run tests
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:test

- name: Send unit tests coverage to Codecov
if: matrix.operating-system == 'ubuntu-latest'
uses: codecov/codecov-action@v2
with:
file: ./coverage_unit.txt
flags: unit
file: ${{ matrix.module.path }}coverage_unit.txt
flags: ${{ matrix.module.codecov-flags }}
fail_ci_if_error: true
2 changes: 2 additions & 0 deletions workflow-templates/test-go-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Install the [`test-go-task.yml`](test-go-task.yml) GitHub Actions workflow to `.

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

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`

#### `.gitignore`

Add the following to `.gitignore`:
Expand Down
Loading