Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3b9a5f3

Browse files
committedDec 13, 2021
[skip-changelog] Add CI workflow to run integration tests and to test Go code (#659)
* Add CI workflow to test Go code On every push and pull request that affects relevant files, run the project's Go code tests. * rename test dir to tests (for uniformity with other tooling team repos) * Add CI workflow to run integration tests On every push and pull request that affects relevant files, run the integration tests. * add again step to install dependencies (used by systray) * disable actions/checkout action conversion of LF line endings to CRLF when checking out on a Windows runner. * remove testing from the release workflow, since it's already done in `test-go-task` and `test-go-integration-task` workflows * update release CI to use the new `task go:build`
1 parent 056c22e commit 3b9a5f3

File tree

16 files changed

+277
-153
lines changed

16 files changed

+277
-153
lines changed
 

‎.github/workflows/release.yml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,13 @@ jobs:
8585
- name: Check the code is good
8686
run: task check
8787

88-
- name: Run unit tests
89-
run: task test-unit
90-
9188
- name: Build the Agent for linux
92-
run: task build
89+
run: task go:build
9390
if: matrix.os == 'ubuntu-18.04'
9491

9592
# build the agent without GUI support (no tray icon)
9693
- name: Build the Agent-cli
97-
run: task build-cli
94+
run: task go:build-cli
9895
if: matrix.os == 'ubuntu-18.04'
9996

10097
# the manifest is required by windows GUI apps, otherwise the binary will crash with: "Unable to create main window: TTM_ADDTOOL failed" (for reference https://github.com/lxn/walk/issues/28)
@@ -108,32 +105,19 @@ jobs:
108105
env:
109106
GOARCH: 386 # 32bit architecture (for support)
110107
GO386: 387 # support old instruction sets without MMX (used in the Pentium 4) (will be deprecated in GO > 1.15 https://golang.org/doc/go1.15)
111-
run: task build-win
108+
run: task go:build-win
112109
if: matrix.os == 'windows-2019' && matrix.arch == '-386'
113110

114111
- name: Build the Agent for win64
115-
run: task build-win # GOARCH=amd64 by default on the runners
112+
run: task go:build-win # GOARCH=amd64 by default on the runners
116113
if: matrix.os == 'windows-2019' && matrix.arch == '-amd64'
117114

118115
- name: Build the Agent for macos
119116
env:
120117
MACOSX_DEPLOYMENT_TARGET: 10.11 # minimum supported version for mac
121118
CGO_CFLAGS: -mmacosx-version-min=10.11
122119
CGO_LDFLAGS: -mmacosx-version-min=10.11
123-
run: task build
124-
if: matrix.os == 'macos-10.15'
125-
126-
- name: Install Python
127-
uses: actions/setup-python@v2
128-
with:
129-
python-version: '3.9'
130-
architecture: 'x64'
131-
if: matrix.os == 'macos-10.15'
132-
133-
- name: Run e2e tests
134-
run: |
135-
pip install poetry
136-
task test-e2e
120+
run: task go:build
137121
if: matrix.os == 'macos-10.15'
138122

139123
# this will create `public/` dir with compressed full bin (<version>/<os>-<arch>.gz) and a json file
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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.14"
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+
create:
13+
push:
14+
paths:
15+
- ".github/workflows/test-go-integration-task.ya?ml"
16+
- "Taskfile.ya?ml"
17+
- "**.go"
18+
- "go.mod"
19+
- "go.sum"
20+
- "poetry.lock"
21+
- "pyproject.toml"
22+
- "tests/**"
23+
pull_request:
24+
paths:
25+
- ".github/workflows/test-go-integration-task.ya?ml"
26+
- "Taskfile.ya?ml"
27+
- "**.go"
28+
- "go.mod"
29+
- "go.sum"
30+
- "poetry.lock"
31+
- "pyproject.toml"
32+
- "tests/**"
33+
workflow_dispatch:
34+
repository_dispatch:
35+
36+
jobs:
37+
run-determination:
38+
runs-on: ubuntu-latest
39+
outputs:
40+
result: ${{ steps.determination.outputs.result }}
41+
steps:
42+
- name: Determine if the rest of the workflow should run
43+
id: determination
44+
run: |
45+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
46+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
47+
if [[ \
48+
"${{ github.event_name }}" != "create" || \
49+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \
50+
]]; then
51+
# Run the other jobs.
52+
RESULT="true"
53+
else
54+
# There is no need to run the other jobs.
55+
RESULT="false"
56+
fi
57+
58+
echo "::set-output name=result::$RESULT"
59+
60+
test:
61+
needs: run-determination
62+
if: needs.run-determination.outputs.result == 'true'
63+
64+
strategy:
65+
matrix:
66+
operating-system:
67+
- ubuntu-latest
68+
- windows-latest
69+
- macos-latest
70+
71+
runs-on: ${{ matrix.operating-system }}
72+
73+
steps:
74+
- name: Checkout repository
75+
uses: actions/checkout@v2
76+
77+
- name: Install Go
78+
uses: actions/setup-go@v2
79+
with:
80+
go-version: ${{ env.GO_VERSION }}
81+
82+
- name: Install Python
83+
uses: actions/setup-python@v2
84+
with:
85+
python-version: ${{ env.PYTHON_VERSION }}
86+
87+
- name: Install Poetry
88+
run: pip install poetry
89+
90+
- name: Install Task
91+
uses: arduino/setup-task@v1
92+
with:
93+
repo-token: ${{ secrets.GITHUB_TOKEN }}
94+
version: 3.x
95+
96+
# build the agent without GUI support (no tray icon) for integration testing
97+
- name: Build the Agent-cli
98+
run: task go:build-cli
99+
if: matrix.operating-system != 'windows-latest'
100+
101+
- name: Build the Agent-cli for win
102+
run: task go:build-win-cli
103+
if: matrix.operating-system == 'windows-latest'
104+
105+
- name: Run integration tests
106+
run: task go:test-integration

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

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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.14"
7+
8+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
9+
on:
10+
create:
11+
push:
12+
paths:
13+
- ".github/workflows/test-go-task.ya?ml"
14+
- "codecov.ya?ml"
15+
- "**/go.mod"
16+
- "**/go.sum"
17+
- "Taskfile.ya?ml"
18+
- "**.go"
19+
- "**/testdata/**"
20+
pull_request:
21+
paths:
22+
- ".github/workflows/test-go-task.ya?ml"
23+
- "codecov.ya?ml"
24+
- "**/go.mod"
25+
- "**/go.sum"
26+
- "Taskfile.ya?ml"
27+
- "**.go"
28+
- "**/testdata/**"
29+
workflow_dispatch:
30+
repository_dispatch:
31+
32+
jobs:
33+
run-determination:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
result: ${{ steps.determination.outputs.result }}
37+
steps:
38+
- name: Determine if the rest of the workflow should run
39+
id: determination
40+
run: |
41+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
42+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
43+
if [[ \
44+
"${{ github.event_name }}" != "create" || \
45+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \
46+
]]; then
47+
# Run the other jobs.
48+
RESULT="true"
49+
else
50+
# There is no need to run the other jobs.
51+
RESULT="false"
52+
fi
53+
54+
echo "::set-output name=result::$RESULT"
55+
56+
test:
57+
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
58+
needs: run-determination
59+
if: needs.run-determination.outputs.result == 'true'
60+
61+
strategy:
62+
fail-fast: false
63+
64+
matrix:
65+
operating-system:
66+
- ubuntu-latest
67+
- windows-latest
68+
- macos-latest
69+
module:
70+
- path: ./
71+
codecov-flags: unit
72+
73+
runs-on: ${{ matrix.operating-system }}
74+
75+
steps:
76+
# By default, actions/checkout converts the repo's LF line endings to CRLF on the Windows runner.
77+
- name: Disable EOL conversions
78+
run: git config --global core.autocrlf false
79+
80+
- name: Checkout repository
81+
uses: actions/checkout@v2
82+
83+
- name: Install Go
84+
uses: actions/setup-go@v2
85+
with:
86+
go-version: ${{ env.GO_VERSION }}
87+
88+
- name: Install Task
89+
uses: arduino/setup-task@v1
90+
with:
91+
repo-token: ${{ secrets.GITHUB_TOKEN }}
92+
version: 3.x
93+
94+
# https://github.com/getlantern/systray#linux
95+
- name: Install Dependencies (Linux)
96+
run: sudo apt update && sudo apt install -y --no-install-recommends build-essential libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev
97+
if: matrix.operating-system == 'ubuntu-latest'
98+
99+
- name: Run tests
100+
env:
101+
GO_MODULE_PATH: ${{ matrix.module.path }}
102+
run: task go:test
103+
104+
- name: Send unit tests coverage to Codecov
105+
if: runner.os == 'Linux'
106+
uses: codecov/codecov-action@v2
107+
with:
108+
file: ${{ matrix.module.path }}coverage_unit.txt
109+
flags: ${{ matrix.module.codecov-flags }}
110+
fail_ci_if_error: ${{ github.repository == 'arduino/arduino-create-agent' }}

‎.github/workflows/test.yml

Lines changed: 0 additions & 115 deletions
This file was deleted.

‎README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[![License: GPL v2](https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
2+
[![Test Go status](https://github.com/arduino/arduino-create-agent/actions/workflows/test-go-task.yml/badge.svg)](https://github.com/arduino/arduino-create-agent/actions/workflows/test-go-task.yml)
3+
[![Codecov](https://codecov.io/gh/arduino/arduino-create-agent/branch/main/graph/badge.svg)](https://codecov.io/gh/arduino/arduino-create-agent)
4+
[![Test Integration status](https://github.com/arduino/arduino-create-agent/actions/workflows/test-go-integration-task.yml/badge.svg)](https://github.com/arduino/arduino-create-agent/actions/workflows/test-go-integration-task.yml)
25

36
arduino-create-agent
47
====================

‎Taskfile.yml

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,76 @@
11
version: '3'
22

33
tasks:
4-
5-
build:
4+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
5+
go:build:
66
desc: Build the project, to use a specific version use `task build TAG_VERSION=x.x.x`
7+
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
78
cmds:
89
- go build -v -i {{default "" .ADDITIONAL_FLAGS}} -o {{default "arduino-create-agent" .APP_NAME}} -ldflags '-X main.version={{default .TAG_TEST .TAG_VERSION}} -X main.git_revision={{.COMMIT}} {{default "" .WIN_FLAGS}}'
910
vars:
1011
COMMIT:
1112
sh: git log -n 1 --format=%h
1213

13-
build-cli:
14-
desc: Build the project without tray support
14+
go:build-cli:
15+
desc: Build the project without tray icon support
1516
cmds:
16-
- task: build
17+
- task: go:build
1718
vars:
1819
APP_NAME: arduino-create-agent_cli
1920
ADDITIONAL_FLAGS: -tags cli
2021

21-
build-win:
22+
go:build-win:
2223
desc: Build the project for win, to build 32bit `export GOARCH=386` and for 64 bit `export GOARCH=amd64` before `task build-win`
2324
cmds:
2425
- rsrc -arch {{.GOARCH}} -manifest manifest.xml # GOARCH shoud be either amd64 or 386
25-
- task: build
26+
- task: go:build
2627
vars:
2728
APP_NAME: arduino-create-agent.exe
2829
WIN_FLAGS: -H=windowsgui
2930
- rm *.syso # rm file to avoid compilation problems on other platforms
3031

31-
test-unit:
32-
desc: Run unit tests only
32+
go:build-win-cli:
33+
desc: Build the project fow win without tray icon support
34+
cmds:
35+
- task: go:build
36+
vars:
37+
APP_NAME: arduino-create-agent_cli.exe
38+
ADDITIONAL_FLAGS: -tags cli
39+
40+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
41+
go:test:
42+
desc: Run unit tests
43+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
3344
cmds:
34-
- go test -short -run '{{ default ".*" .TEST_REGEX }}' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default .DEFAULT_TARGETS .TARGETS }} {{.TEST_LDFLAGS}}
45+
- |
46+
go test \
47+
-v \
48+
-short \
49+
-run '{{default ".*" .GO_TEST_REGEX}}' \
50+
{{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
51+
-coverprofile=coverage_unit.txt \
52+
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
3553
36-
test-e2e:
37-
desc: Run end 2 end tests
54+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-integration-task/Taskfile.yml
55+
go:test-integration:
56+
desc: Run integration tests
57+
deps:
58+
# - task: go:build # we build it in the CI and not in the task because _cli version is required and build procedure is different on win
59+
- task: poetry:install-deps
60+
cmds:
61+
- poetry run pytest tests
62+
63+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
64+
poetry:install-deps:
65+
desc: Install dependencies managed by Poetry
3866
cmds:
3967
- poetry install --no-root
40-
- poetry run pytest test
68+
69+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
70+
poetry:update-deps:
71+
desc: Update all dependencies managed by Poetry to their newest versions
72+
cmds:
73+
- poetry update
4174

4275
check:
4376
desc: Check fmt and lint
@@ -63,7 +96,10 @@ vars:
6396
# all modules of this project except for "gen/..." module
6497
DEFAULT_TARGETS:
6598
sh: echo `go list ./... | grep -v 'arduino-create-agent/gen/' | tr '\n' ' '`
66-
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"
99+
DEFAULT_GO_MODULE_PATH: ./
100+
DEFAULT_GO_PACKAGES:
101+
sh: |
102+
echo $(cd {{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}} && go list ./... | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
67103
# check-lint vars
68104
GOLINTBIN:
69105
sh: go list -f {{"{{"}}".Target{{"}}"}}" golang.org/x/lint/golint

‎main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func TestValidSignatureKey(t *testing.T) {
13-
testfile := filepath.Join("test", "testdata", "test.ini")
13+
testfile := filepath.Join("tests", "testdata", "test.ini")
1414
args, err := parseIni(testfile)
1515
require.NoError(t, err)
1616
require.NotNil(t, args)
File renamed without changes.

‎test/conftest.py renamed to ‎tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@pytest.fixture(scope="function")
1313
def agent(pytestconfig):
1414

15-
agent_cli = str(Path(pytestconfig.rootdir) / "arduino-create-agent")
15+
agent_cli = str(Path(pytestconfig.rootdir) / "arduino-create-agent_cli")
1616
env = {
1717
# "ARDUINO_DATA_DIR": data_dir,
1818
# "ARDUINO_DOWNLOADS_DIR": downloads_dir,
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎test/test_ws.py renamed to ‎tests/test_ws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_open_serial_timedraw(socketio, serial_port, baudrate, message):
4646
general_open_serial(socketio, serial_port, baudrate, message, "timedraw")
4747

4848

49-
# NOTE run the following tests with a board connected to the PC and with the sketch found in test/testdata/SerialEcho.ino on it be sure to change serial_address in conftest.py
49+
# NOTE run the following tests with a board connected to the PC and with the sketch found in tests/testdata/SerialEcho.ino on it be sure to change serial_address in conftest.py
5050
@pytest.mark.skipif(
5151
running_on_ci(),
5252
reason="VMs have no serial ports",
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.