Skip to content

Commit 3222d17

Browse files
authored
Sync testing assets with templates (#106)
We have assembled a collection of reusable project assets: https://github.com/arduino/tooling-project-assets These assets will be used in the repositories of all Arduino tooling projects. Some improvements and standardizations have been made in the upstream "template" testing assets, and those are introduced to this repository here. Notable: - Split into separate workflows for each distinct testing type - Use Codecov to track code coverage - Make integration test work directory path canonical - Do clean up of integration test work directory - Update integration test dependencies Some task names have changed: - `test-unit` -> `go:test` - `test-integration` -> `go:test-integration`
1 parent b2f212c commit 3222d17

9 files changed

+251
-61
lines changed

.github/workflows/test.yaml renamed to .github/workflows/check-go-cross-build-task.yml

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
1-
name: Run tests
1+
name: Check Cross Build
22

3+
env:
4+
# See: https://github.com/actions/setup-go/tree/v2#readme
5+
GO_VERSION: "1.15"
6+
7+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
38
on:
49
push:
5-
branches:
6-
- main
10+
paths:
11+
- ".github/workflows/check-go-cross-build-task.ya?ml"
12+
- "go.mod"
13+
- "go.sum"
14+
- "Taskfile.ya?ml"
15+
- "**.go"
716
pull_request:
17+
paths:
18+
- ".github/workflows/check-go-cross-build-task.ya?ml"
19+
- "go.mod"
20+
- "go.sum"
21+
- "Taskfile.ya?ml"
22+
- "**.go"
23+
workflow_dispatch:
24+
repository_dispatch:
825

926
jobs:
10-
native-os-build:
27+
build:
1128
strategy:
1229
matrix:
13-
os: [ubuntu-latest, windows-latest, macos-latest]
30+
os:
31+
- ubuntu-latest
32+
- windows-latest
33+
- macos-latest
1434

1535
runs-on: ${{ matrix.os }}
1636

1737
steps:
18-
- name: Disable EOL conversions
19-
run: git config --global core.autocrlf false
20-
2138
- name: Checkout
2239
uses: actions/checkout@v2
2340

2441
- name: Install Go
2542
uses: actions/setup-go@v2
2643
with:
27-
go-version: "1.15"
44+
go-version: ${{ env.GO_VERSION }}
2845

2946
- name: Install Taskfile
3047
uses: arduino/setup-task@v1
@@ -33,7 +50,6 @@ jobs:
3350
version: 3.x
3451

3552
- name: Build native
36-
shell: bash
3753
run: task build
3854

3955
- name: Cross-build for 386
@@ -47,14 +63,3 @@ jobs:
4763
env:
4864
GOARCH: "arm"
4965
run: task build
50-
51-
- name: Install Python
52-
uses: actions/setup-python@v2
53-
with:
54-
python-version: "3.8"
55-
56-
- name: Install Poetry
57-
run: pip install poetry
58-
59-
- name: Run unit and integration tests
60-
run: task test
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/test-go-integration-task.md
2+
name: Test Integration
3+
4+
env:
5+
# See: https://github.com/actions/setup-go/tree/v2#readme
6+
GO_VERSION: "1.15"
7+
# See: https://github.com/actions/setup-python/tree/v2#available-versions-of-python
8+
PYTHON_VERSION: "3.9"
9+
10+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
11+
on:
12+
push:
13+
paths:
14+
- ".github/workflows/test-go-integration-task.ya?ml"
15+
- "Taskfile.ya?ml"
16+
- "**.go"
17+
- "go.mod"
18+
- "go.sum"
19+
- "poetry.lock"
20+
- "pyproject.toml"
21+
- "tests/**"
22+
pull_request:
23+
paths:
24+
- ".github/workflows/test-go-integration-task.ya?ml"
25+
- "Taskfile.ya?ml"
26+
- "**.go"
27+
- "go.mod"
28+
- "go.sum"
29+
- "poetry.lock"
30+
- "pyproject.toml"
31+
- "tests/**"
32+
workflow_dispatch:
33+
repository_dispatch:
34+
35+
jobs:
36+
test:
37+
strategy:
38+
matrix:
39+
operating-system:
40+
- ubuntu-latest
41+
- windows-latest
42+
- macos-latest
43+
44+
runs-on: ${{ matrix.operating-system }}
45+
46+
steps:
47+
# By default, actions/checkout converts the repo's LF line endings to CRLF on the Windows runner.
48+
- name: Disable EOL conversions
49+
run: git config --global core.autocrlf false
50+
51+
- name: Checkout repository
52+
uses: actions/checkout@v2
53+
54+
- name: Install Go
55+
uses: actions/setup-go@v2
56+
with:
57+
go-version: ${{ env.GO_VERSION }}
58+
59+
- name: Install Python
60+
uses: actions/setup-python@v2
61+
with:
62+
python-version: ${{ env.PYTHON_VERSION }}
63+
64+
- name: Install Poetry
65+
run: pip install poetry
66+
67+
- name: Install Task
68+
uses: arduino/setup-task@v1
69+
with:
70+
repo-token: ${{ secrets.GITHUB_TOKEN }}
71+
version: 3.x
72+
73+
- name: Run integration tests
74+
run: task go:test-integration

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/test-go-task.md
2+
name: Test Go
3+
4+
env:
5+
# See: https://github.com/actions/setup-go/tree/v2#readme
6+
GO_VERSION: "1.15"
7+
8+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
9+
on:
10+
push:
11+
paths:
12+
- ".github/workflows/test-go-task.ya?ml"
13+
- "codecov.ya?ml"
14+
- "**/go.mod"
15+
- "**/go.sum"
16+
- "Taskfile.ya?ml"
17+
- "**.go"
18+
- "**/testdata/**"
19+
pull_request:
20+
paths:
21+
- ".github/workflows/test-go-task.ya?ml"
22+
- "codecov.ya?ml"
23+
- "**/go.mod"
24+
- "**/go.sum"
25+
- "Taskfile.ya?ml"
26+
- "**.go"
27+
- "**/testdata/**"
28+
workflow_dispatch:
29+
repository_dispatch:
30+
31+
jobs:
32+
test:
33+
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
34+
35+
strategy:
36+
fail-fast: false
37+
38+
matrix:
39+
operating-system:
40+
- ubuntu-latest
41+
- windows-latest
42+
- macos-latest
43+
module:
44+
- path: ./
45+
codecov-flags: unit
46+
47+
runs-on: ${{ matrix.operating-system }}
48+
49+
steps:
50+
# By default, actions/checkout converts the repo's LF line endings to CRLF on the Windows runner.
51+
- name: Disable EOL conversions
52+
run: git config --global core.autocrlf false
53+
54+
- name: Checkout repository
55+
uses: actions/checkout@v2
56+
57+
- name: Install Go
58+
uses: actions/setup-go@v2
59+
with:
60+
go-version: ${{ env.GO_VERSION }}
61+
62+
- name: Install Task
63+
uses: arduino/setup-task@v1
64+
with:
65+
repo-token: ${{ secrets.GITHUB_TOKEN }}
66+
version: 3.x
67+
68+
- name: Run tests
69+
env:
70+
GO_MODULE_PATH: ${{ matrix.module.path }}
71+
run: task go:test
72+
73+
- name: Send unit tests coverage to Codecov
74+
if: runner.os == 'Linux'
75+
uses: codecov/codecov-action@v2
76+
with:
77+
file: ${{ matrix.module.path }}coverage_unit.txt
78+
flags: ${{ matrix.module.codecov-flags }}
79+
fail_ci_if_error: ${{ github.repository == 'arduino/arduino-fwuploader' }}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
The Arduino Firmware Uploader is a tool made to update the firmware and/or add SSL certificates for any Arduino board
44
equipped with WINC or NINA Wi-Fi module.
55

6-
[![tests-badge]](https://github.com/arduino/arduino-fwuploader/actions/workflows/test.yaml)
6+
[![Test Go status](https://github.com/arduino/arduino-fwuploader/actions/workflows/test-go-task.yml/badge.svg)](https://github.com/arduino/arduino-fwuploader/actions/workflows/test-go-task.yml)
7+
[![Codecov](https://codecov.io/gh/arduino/arduino-fwuploader/branch/main/graph/badge.svg)](https://codecov.io/gh/arduino/arduino-fwuploader)
8+
[![Test Integration status](https://github.com/arduino/arduino-fwuploader/actions/workflows/test-go-integration-task.yml/badge.svg)](https://github.com/arduino/arduino-fwuploader/actions/workflows/test-go-integration-task.yml)
79
[![Deploy Website status](https://github.com/arduino/arduino-fwuploader/actions/workflows/deploy-cobra-mkdocs-versioned-poetry.yml/badge.svg)](https://github.com/arduino/arduino-fwuploader/actions/workflows/deploy-cobra-mkdocs-versioned-poetry.yml)
810

911
## ❗❗❗Notice regarding versions before 2.0.0 ❗❗❗
@@ -28,7 +30,6 @@ and report the bug to our Security Team 🛡️ Thank you!
2830

2931
e-mail contact: [email protected]
3032

31-
[tests-badge]: https://github.com/arduino/arduino-fwuploader/actions/workflows/test.yaml/badge.svg
3233
[security policy]: https://github.com/arduino/arduino-fwuploader/security/policy
3334
[user documentation]: https://arduino.github.io/arduino-fwuploader/
3435
[install]: https://arduino.github.io/arduino-fwuploader/latest/installation

Taskfile.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,47 @@ tasks:
131131
cmds:
132132
- npx markdownlint-cli "**/*.md"
133133

134-
build:
135-
desc: Build the project
134+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
135+
go:build:
136+
desc: Build the Go code
137+
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
136138
cmds:
137139
- go build -v {{.LDFLAGS}}
138140

141+
build:
142+
desc: Build the project
143+
deps:
144+
- task: go:build
145+
139146
test:
140147
desc: Run tests
141148
cmds:
142149
- task: test-unit
143-
- task: test-integration
150+
- task: go:test-integration
144151

145-
test-unit:
152+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
153+
go:test:
146154
desc: Run unit tests
155+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
147156
cmds:
148-
- go test -short -race -run '.*' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt ./... {{.TEST_LDFLAGS}}
157+
- |
158+
go test \
159+
-v \
160+
-short \
161+
-race \
162+
-run '{{default ".*" .GO_TEST_REGEX}}' \
163+
{{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
164+
-coverprofile=coverage_unit.txt \
165+
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} \
166+
{{.TEST_LDFLAGS}}
149167
150-
test-integration:
168+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-integration-task/Taskfile.yml
169+
go:test-integration:
151170
desc: Run integration tests
152-
cmds:
153-
- task: build
171+
deps:
172+
- task: go:build
154173
- task: poetry:install-deps
174+
cmds:
155175
- poetry run pytest test
156176

157177
check:
@@ -235,7 +255,6 @@ vars:
235255
-X {{.CONFIGURATION_PACKAGE}}.date={{.TIMESTAMP}}
236256
'
237257
# test vars
238-
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"
239258
TEST_VERSION: "0.0.0-test.preview"
240259
TEST_COMMIT: "deadbeef"
241260
TEST_LDFLAGS: >

0 commit comments

Comments
 (0)