Skip to content

Add multi-module support to project infrastructure #71

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 1 commit into from
Aug 23, 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
57 changes: 53 additions & 4 deletions .github/workflows/check-go-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ on:
paths:
- ".github/workflows/check-go-task.yml"
- "Taskfile.yml"
- "go.mod"
- "go.sum"
- "**/go.mod"
- "**/go.sum"
- "**.go"
pull_request:
paths:
- ".github/workflows/check-go-task.yml"
- "Taskfile.yml"
- "go.mod"
- "go.sum"
- "**/go.mod"
- "**/go.sum"
- "**.go"
schedule:
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to tools.
Expand All @@ -28,8 +28,16 @@ on:

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

strategy:
fail-fast: false

matrix:
module:
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -46,11 +54,21 @@ 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:
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -67,14 +85,24 @@ 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:
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -94,11 +122,21 @@ 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:
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -115,14 +153,24 @@ jobs:
version: 3.x

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

- name: Check formatting
run: git diff --color --exit-code

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

strategy:
fail-fast: false

matrix:
module:
- path: ./

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -133,6 +181,7 @@ jobs:
go-version: ${{ env.GO_VERSION }}

- name: Run go mod tidy
working-directory: ${{ matrix.module.path }}
run: go mod tidy

- name: Check whether any tidying was needed
Expand Down
23 changes: 18 additions & 5 deletions .github/workflows/test-go-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ on:
push:
paths:
- ".github/workflows/test-go-task.ya?ml"
- "go.mod"
- "go.sum"
- "**/go.mod"
- "**/go.sum"
- "Taskfile.ya?ml"
- "**/testdata/**"
- "**.go"
pull_request:
paths:
- ".github/workflows/test-go-task.ya?ml"
- "go.mod"
- "go.sum"
- "**/go.mod"
- "**/go.sum"
- "Taskfile.ya?ml"
- "**/testdata/**"
- "**.go"
Expand Down Expand Up @@ -56,7 +56,18 @@ jobs:
name: libraries-repository-engine

test:
runs-on: ubuntu-latest
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})

strategy:
fail-fast: false

matrix:
operating-system:
- ubuntu-latest
module:
- path: ./

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

steps:
- name: Checkout repository
Expand Down Expand Up @@ -88,4 +99,6 @@ jobs:
version: 3.x

- name: Run tests
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:test
11 changes: 10 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
version: "3"

vars:
# Path of the project's primary Go module:
DEFAULT_GO_MODULE_PATH: ./
DEFAULT_GO_PACKAGES:
sh: echo $(go list ./... | tr '\n' ' ')
sh: |
echo $(cd {{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}} && go list ./... | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')

tasks:
build:
Expand Down Expand Up @@ -31,12 +34,14 @@ tasks:
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
go:build:
desc: Build the Go code
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
cmds:
- go build -v -o libraries-repository-engine{{exeExt}}

# 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 .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
cmds:
- 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}}

Expand All @@ -58,18 +63,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 .DEFAULT_GO_MODULE_PATH .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 .DEFAULT_GO_MODULE_PATH .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 .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
cmds:
- |
if ! which golint &>/dev/null; then
Expand All @@ -84,6 +92,7 @@ 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 .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
cmds:
- go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}

Expand Down