Skip to content

Commit 714ffce

Browse files
authored
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 250b17c commit 714ffce

16 files changed

+277
-153
lines changed

.github/workflows/release.yml

+5-21
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
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

+110
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

-115
This file was deleted.

README.md

+3
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
====================

0 commit comments

Comments
 (0)