Skip to content

Commit 5a5ae94

Browse files
authored
[skip-changelog] Extend code-coverage to integration test (#2103)
* Upgrade minimum go version to 1.20 * Updated license cache * Implemented code coverage in integration tests * Use gocovmerge to merge all coverage artifacts * Fixed build error on macOS dist The error was due to an increased git security constraints ... go: downloading github.com/xanzy/ssh-agent v0.2.1 go: downloading gopkg.in/warnings.v0 v0.1.2 error obtaining VCS status: exit status 128 Use -buildvcs=false to disable VCS stamping. Error: failed building for darwin/amd64: exit status 1 failed building for darwin/amd64: exit status 1 task: Failed to run task "dist:macOS_64bit": exit status 1 To fix this I followed the suggestion here elastic/golang-crossbuild#232 * Before killing the daemon, try a graceful shutdown Otherwise the process will not outut the coverage data.
1 parent 2b0dfb0 commit 5a5ae94

18 files changed

+130
-26
lines changed

Diff for: .github/workflows/check-easyjson.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Check easyjson generated files
22

33
env:
44
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
5-
GO_VERSION: "1.19"
5+
GO_VERSION: "1.20"
66

77
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
88
on:

Diff for: .github/workflows/check-go-dependencies-task.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Check Go Dependencies
33

44
env:
55
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
6-
GO_VERSION: "1.19"
6+
GO_VERSION: "1.20"
77

88
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
99
on:

Diff for: .github/workflows/check-go-task.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Check Go
33

44
env:
55
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
6-
GO_VERSION: "1.19"
6+
GO_VERSION: "1.20"
77

88
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
99
on:

Diff for: .github/workflows/check-i18n-task.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Check Internationalization
22

33
env:
44
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
5-
GO_VERSION: "1.19"
5+
GO_VERSION: "1.20"
66

77
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
88
on:

Diff for: .github/workflows/check-markdown-task.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ env:
55
# See: https://github.com/actions/setup-node/#readme
66
NODE_VERSION: 16.x
77
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
8-
GO_VERSION: "1.19"
8+
GO_VERSION: "1.20"
99

1010
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
1111
on:

Diff for: .github/workflows/check-mkdocs-task.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Check Website
33

44
env:
55
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
6-
GO_VERSION: "1.19"
6+
GO_VERSION: "1.20"
77
# See: https://github.com/actions/setup-python/tree/main#available-versions-of-python
88
PYTHON_VERSION: "3.9"
99

Diff for: .github/workflows/check-protobuf-task.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Check Protocol Buffers
22

33
env:
44
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
5-
GO_VERSION: "1.19"
5+
GO_VERSION: "1.20"
66

77
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
88
on:

Diff for: .github/workflows/deploy-cobra-mkdocs-versioned-poetry.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Deploy Website
33

44
env:
55
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
6-
GO_VERSION: "1.19"
6+
GO_VERSION: "1.20"
77
# See: https://github.com/actions/setup-python/tree/main#available-versions-of-python
88
PYTHON_VERSION: "3.9"
99

Diff for: .github/workflows/i18n-weekly-pull.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: i18n-weekly-pull
22

33
env:
44
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
5-
GO_VERSION: "1.19"
5+
GO_VERSION: "1.20"
66
COVERAGE_ARTIFACT: coverage-data
77

88
on:

Diff for: .github/workflows/test-go-task.yml

+26-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Test Go
33

44
env:
55
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
6-
GO_VERSION: "1.19"
6+
GO_VERSION: "1.20"
77
COVERAGE_ARTIFACT: coverage-data
88

99
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
@@ -110,6 +110,15 @@ jobs:
110110
run: |
111111
export GO_TEST_PACKAGE="github.com/arduino/arduino-cli/internal/integrationtest/${{ matrix.tests }}"
112112
task go:integration-test
113+
mv coverage_integration.txt coverage_integration_${{ matrix.operating-system }}_${{ matrix.tests }}.txt
114+
115+
- name: Upload coverage data to workflow artifact
116+
uses: actions/upload-artifact@v3
117+
with:
118+
if-no-files-found: error
119+
name: ${{ env.COVERAGE_ARTIFACT }}
120+
path: |
121+
./coverage_integration_*.txt
113122
114123
test:
115124
needs: run-determination
@@ -162,20 +171,32 @@ jobs:
162171
163172
coverage-upload:
164173
runs-on: ubuntu-latest
165-
needs: test
174+
needs:
175+
- test
176+
- test-integration
166177
steps:
167178
- name: Checkout repository
168179
uses: actions/checkout@v3
180+
181+
- name: Install Go
182+
uses: actions/setup-go@v3
183+
with:
184+
go-version: ${{ env.GO_VERSION }}
185+
186+
- name: Install gocovmerge
187+
run: go install github.com/wadey/gocovmerge@b5bfa59
188+
169189
- name: Download coverage data artifact
170190
uses: actions/download-artifact@v3
171191
with:
172192
name: ${{ env.COVERAGE_ARTIFACT }}
173193

194+
- name: Merge all code coverage artifacts
195+
run: gocovmerge coverage*.txt > coverage.txt
196+
174197
- name: Send unit tests coverage to Codecov
175198
uses: codecov/codecov-action@v3
176199
with:
177-
files: >
178-
./coverage_unit.txt,
179-
./coverage_legacy.txt
200+
files: ./coverage.txt
180201
flags: unit
181202
fail_ci_if_error: ${{ github.repository == 'arduino/arduino-cli' }}

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/wiki
88
.idea
99
coverage_*.txt
10+
coverage_data
1011
__pycache__
1112
venv
1213
.pytest_cache

Diff for: .licenses/go/golang.org/x/crypto/curve25519.dep.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: golang.org/x/crypto/curve25519
3+
version: v0.7.0
4+
type: go
5+
summary: Package curve25519 provides an implementation of the X25519 function, which
6+
performs scalar multiplication on the elliptic curve known as Curve25519.
7+
homepage: https://pkg.go.dev/golang.org/x/crypto/curve25519
8+
license: bsd-3-clause
9+
licenses:
10+
- sources: [email protected]/LICENSE
11+
text: |
12+
Copyright (c) 2009 The Go Authors. All rights reserved.
13+
14+
Redistribution and use in source and binary forms, with or without
15+
modification, are permitted provided that the following conditions are
16+
met:
17+
18+
* Redistributions of source code must retain the above copyright
19+
notice, this list of conditions and the following disclaimer.
20+
* Redistributions in binary form must reproduce the above
21+
copyright notice, this list of conditions and the following disclaimer
22+
in the documentation and/or other materials provided with the
23+
distribution.
24+
* Neither the name of Google Inc. nor the names of its
25+
contributors may be used to endorse or promote products derived from
26+
this software without specific prior written permission.
27+
28+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39+
- sources: [email protected]/PATENTS
40+
text: |
41+
Additional IP Rights Grant (Patents)
42+
43+
"This implementation" means the copyrightable works distributed by
44+
Google as part of the Go project.
45+
46+
Google hereby grants to You a perpetual, worldwide, non-exclusive,
47+
no-charge, royalty-free, irrevocable (except as stated in this section)
48+
patent license to make, have made, use, offer to sell, sell, import,
49+
transfer and otherwise run, modify and propagate the contents of this
50+
implementation of Go, where such license applies only to those patent
51+
claims, both currently owned or controlled by Google and acquired in
52+
the future, licensable by Google that are necessarily infringed by this
53+
implementation of Go. This grant does not include claims that would be
54+
infringed only as a consequence of further modification of this
55+
implementation. If you or your agent or exclusive licensee institute or
56+
order or agree to the institution of patent litigation against any
57+
entity (including a cross-claim or counterclaim in a lawsuit) alleging
58+
that this implementation of Go or any code incorporated within this
59+
implementation of Go constitutes direct or contributory patent
60+
infringement, or inducement of patent infringement, then any patent
61+
rights granted to you under this License for this implementation of Go
62+
shall terminate as of the date such litigation is filed.
63+
notices: []

Diff for: .licenses/go/golang.org/x/crypto/internal/alias.dep.yml renamed to .licenses/go/golang.org/x/crypto/curve25519/internal/field.dep.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
name: golang.org/x/crypto/internal/alias
2+
name: golang.org/x/crypto/curve25519/internal/field
33
version: v0.7.0
44
type: go
5-
summary: Package alias implements memory aliasing tests.
6-
homepage: https://pkg.go.dev/golang.org/x/crypto/internal/alias
5+
summary: Package field implements fast arithmetic modulo 2^255-19.
6+
homepage: https://pkg.go.dev/golang.org/x/crypto/curve25519/internal/field
77
license: bsd-3-clause
88
licenses:
99
- sources: [email protected]/LICENSE

Diff for: DistTasks.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ version: "3"
1919

2020
vars:
2121
CONTAINER: "docker.elastic.co/beats-dev/golang-crossbuild"
22-
GO_VERSION: "1.19.3"
22+
GO_VERSION: "1.20.1"
2323

2424
tasks:
2525
Windows_32bit:
@@ -201,11 +201,12 @@ tasks:
201201
desc: Builds Mac OS X 64 bit binaries
202202
dir: "{{.DIST_DIR}}"
203203
cmds:
204+
# "git config safe.directory" is required until this is fixed https://github.com/elastic/golang-crossbuild/issues/232
204205
- |
205206
docker run -v `pwd`/..:/home/build -w /home/build \
206207
-e CGO_ENABLED=1 \
207208
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
208-
--build-cmd "{{.BUILD_COMMAND}}" \
209+
--build-cmd "git config --global --add safe.directory /home/build && {{.BUILD_COMMAND}}" \
209210
-p "{{.BUILD_PLATFORM}}"
210211
211212
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
@@ -235,11 +236,12 @@ tasks:
235236
desc: Builds Mac OS X ARM64 binaries
236237
dir: "{{.DIST_DIR}}"
237238
cmds:
239+
# "git config safe.directory" is required until this is fixed https://github.com/elastic/golang-crossbuild/issues/232
238240
- |
239241
docker run -v `pwd`/..:/home/build -w /home/build \
240242
-e CGO_ENABLED=1 \
241243
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
242-
--build-cmd "{{.BUILD_COMMAND}}" \
244+
--build-cmd "git config --global --add safe.directory /home/build && {{.BUILD_COMMAND}}" \
243245
-p "{{.BUILD_PLATFORM}}"
244246
245247
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}

Diff for: Taskfile.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tasks:
4848
desc: Build the Go code
4949
dir: '{{default "./" .GO_MODULE_PATH}}'
5050
cmds:
51-
- go build -v {{.LDFLAGS}}
51+
- go build -v {{default "" .EXTRA_FLAGS}} {{.LDFLAGS}}
5252

5353
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/Taskfile.yml
5454
go:cli-docs:
@@ -110,10 +110,14 @@ tasks:
110110
desc: Run the Go-based integration tests
111111
deps:
112112
- task: go:build
113+
vars:
114+
EXTRA_FLAGS: "-covermode=atomic"
113115
dir: '{{default "./" .GO_MODULE_PATH}}'
114116
cmds:
115117
- |
116-
go test \
118+
rm -fr coverage_data
119+
mkdir coverage_data
120+
INTEGRATION_GOCOVERDIR={{ .ROOT_DIR }}/coverage_data go test \
117121
-v \
118122
-short \
119123
{{ .GO_TEST_PACKAGE }} \
@@ -122,6 +126,7 @@ tasks:
122126
-coverprofile=coverage_unit.txt \
123127
{{default .DEFAULT_INTEGRATIONTEST_GO_PACKAGES .GO_PACKAGES}} \
124128
{{.TEST_LDFLAGS}}
129+
go tool covdata textfmt -i=coverage_data -o coverage_integration.txt
125130
126131
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
127132
go:vet:

Diff for: docs/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ submitting a PR:
7070

7171
To build the Arduino CLI from sources you need the following tools to be available in your local environment:
7272

73-
- [Go][1] version 1.19 or later
73+
- [Go][1] version 1.20 or later
7474
- [Taskfile][2] to help you run the most common tasks from the command line
7575

7676
If you want to run integration tests you will also need:

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/arduino/arduino-cli
22

3-
go 1.19
3+
go 1.20
44

55
// We must use this fork until https://github.com/mailru/easyjson/pull/372 is merged
66
replace github.com/mailru/easyjson => github.com/cmaglie/easyjson v0.8.1

Diff for: internal/integrationtest/arduino-cli.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type ArduinoCLI struct {
7070
path *paths.Path
7171
t *require.Assertions
7272
proc *executils.Process
73+
stdIn io.WriteCloser
7374
cliEnvVars map[string]string
7475
cliConfigPath *paths.Path
7576
stagingDir *paths.Path
@@ -122,7 +123,12 @@ func NewArduinoCliWithinEnvironment(env *Environment, config *ArduinoCLIConfig)
122123
func (cli *ArduinoCLI) CleanUp() {
123124
if cli.proc != nil {
124125
cli.daemonConn.Close()
125-
cli.proc.Kill()
126+
cli.stdIn.Close()
127+
proc := cli.proc
128+
go func() {
129+
time.Sleep(time.Second)
130+
proc.Kill()
131+
}()
126132
cli.proc.Wait()
127133
}
128134
}
@@ -185,6 +191,11 @@ func (cli *ArduinoCLI) convertEnvForExecutils(env map[string]string) []string {
185191
for k, v := range env {
186192
envVars = append(envVars, fmt.Sprintf("%s=%s", k, v))
187193
}
194+
195+
// Proxy code-coverage related env vars
196+
if gocoverdir := os.Getenv("INTEGRATION_GOCOVERDIR"); gocoverdir != "" {
197+
envVars = append(envVars, "GOCOVERDIR="+gocoverdir)
198+
}
188199
return envVars
189200
}
190201

@@ -246,10 +257,11 @@ func (cli *ArduinoCLI) StartDaemon(verbose bool) string {
246257
cli.t.NoError(err)
247258
stderr, err := cliProc.StderrPipe()
248259
cli.t.NoError(err)
249-
_, err = cliProc.StdinPipe()
260+
stdIn, err := cliProc.StdinPipe()
250261
cli.t.NoError(err)
251262

252263
cli.t.NoError(cliProc.Start())
264+
cli.stdIn = stdIn
253265
cli.proc = cliProc
254266
cli.daemonAddr = "127.0.0.1:50051"
255267

0 commit comments

Comments
 (0)