Skip to content

Commit

Permalink
[skip-changelog] Extend code-coverage to integration test (#2103)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
cmaglie authored Mar 27, 2023
1 parent 2b0dfb0 commit 5a5ae94
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-easyjson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Check easyjson generated files

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

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-go-dependencies-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Check Go Dependencies

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

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-go-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Check Go

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

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-i18n-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Check Internationalization

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

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-markdown-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env:
# See: https://github.com/actions/setup-node/#readme
NODE_VERSION: 16.x
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
GO_VERSION: "1.19"
GO_VERSION: "1.20"

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-mkdocs-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Check Website

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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-protobuf-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Check Protocol Buffers

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

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-cobra-mkdocs-versioned-poetry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy Website

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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/i18n-weekly-pull.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: i18n-weekly-pull

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

on:
Expand Down
31 changes: 26 additions & 5 deletions .github/workflows/test-go-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test Go

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

# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
Expand Down Expand Up @@ -110,6 +110,15 @@ jobs:
run: |
export GO_TEST_PACKAGE="github.com/arduino/arduino-cli/internal/integrationtest/${{ matrix.tests }}"
task go:integration-test
mv coverage_integration.txt coverage_integration_${{ matrix.operating-system }}_${{ matrix.tests }}.txt
- name: Upload coverage data to workflow artifact
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: ${{ env.COVERAGE_ARTIFACT }}
path: |
./coverage_integration_*.txt
test:
needs: run-determination
Expand Down Expand Up @@ -162,20 +171,32 @@ jobs:
coverage-upload:
runs-on: ubuntu-latest
needs: test
needs:
- test
- test-integration
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Install gocovmerge
run: go install github.com/wadey/gocovmerge@b5bfa59

- name: Download coverage data artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.COVERAGE_ARTIFACT }}

- name: Merge all code coverage artifacts
run: gocovmerge coverage*.txt > coverage.txt

- name: Send unit tests coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: >
./coverage_unit.txt,
./coverage_legacy.txt
files: ./coverage.txt
flags: unit
fail_ci_if_error: ${{ github.repository == 'arduino/arduino-cli' }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/wiki
.idea
coverage_*.txt
coverage_data
__pycache__
venv
.pytest_cache
Expand Down
63 changes: 63 additions & 0 deletions .licenses/go/golang.org/x/crypto/curve25519.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: golang.org/x/crypto/curve25519
version: v0.7.0
type: go
summary: Package curve25519 provides an implementation of the X25519 function, which
performs scalar multiplication on the elliptic curve known as Curve25519.
homepage: https://pkg.go.dev/golang.org/x/crypto/curve25519
license: bsd-3-clause
licenses:
- sources: crypto@v0.7.0/LICENSE
text: |
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- sources: crypto@v0.7.0/PATENTS
text: |
Additional IP Rights Grant (Patents)
"This implementation" means the copyrightable works distributed by
Google as part of the Go project.
Google hereby grants to You a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as stated in this section)
patent license to make, have made, use, offer to sell, sell, import,
transfer and otherwise run, modify and propagate the contents of this
implementation of Go, where such license applies only to those patent
claims, both currently owned or controlled by Google and acquired in
the future, licensable by Google that are necessarily infringed by this
implementation of Go. This grant does not include claims that would be
infringed only as a consequence of further modification of this
implementation. If you or your agent or exclusive licensee institute or
order or agree to the institution of patent litigation against any
entity (including a cross-claim or counterclaim in a lawsuit) alleging
that this implementation of Go or any code incorporated within this
implementation of Go constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any patent
rights granted to you under this License for this implementation of Go
shall terminate as of the date such litigation is filed.
notices: []
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
name: golang.org/x/crypto/internal/alias
name: golang.org/x/crypto/curve25519/internal/field
version: v0.7.0
type: go
summary: Package alias implements memory aliasing tests.
homepage: https://pkg.go.dev/golang.org/x/crypto/internal/alias
summary: Package field implements fast arithmetic modulo 2^255-19.
homepage: https://pkg.go.dev/golang.org/x/crypto/curve25519/internal/field
license: bsd-3-clause
licenses:
- sources: crypto@v0.7.0/LICENSE
Expand Down
8 changes: 5 additions & 3 deletions DistTasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ version: "3"

vars:
CONTAINER: "docker.elastic.co/beats-dev/golang-crossbuild"
GO_VERSION: "1.19.3"
GO_VERSION: "1.20.1"

tasks:
Windows_32bit:
Expand Down Expand Up @@ -201,11 +201,12 @@ tasks:
desc: Builds Mac OS X 64 bit binaries
dir: "{{.DIST_DIR}}"
cmds:
# "git config safe.directory" is required until this is fixed https://github.com/elastic/golang-crossbuild/issues/232
- |
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
--build-cmd "git config --global --add safe.directory /home/build && {{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
Expand Down Expand Up @@ -235,11 +236,12 @@ tasks:
desc: Builds Mac OS X ARM64 binaries
dir: "{{.DIST_DIR}}"
cmds:
# "git config safe.directory" is required until this is fixed https://github.com/elastic/golang-crossbuild/issues/232
- |
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
--build-cmd "git config --global --add safe.directory /home/build && {{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
Expand Down
9 changes: 7 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tasks:
desc: Build the Go code
dir: '{{default "./" .GO_MODULE_PATH}}'
cmds:
- go build -v {{.LDFLAGS}}
- go build -v {{default "" .EXTRA_FLAGS}} {{.LDFLAGS}}

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/Taskfile.yml
go:cli-docs:
Expand Down Expand Up @@ -110,10 +110,14 @@ tasks:
desc: Run the Go-based integration tests
deps:
- task: go:build
vars:
EXTRA_FLAGS: "-covermode=atomic"
dir: '{{default "./" .GO_MODULE_PATH}}'
cmds:
- |
go test \
rm -fr coverage_data
mkdir coverage_data
INTEGRATION_GOCOVERDIR={{ .ROOT_DIR }}/coverage_data go test \
-v \
-short \
{{ .GO_TEST_PACKAGE }} \
Expand All @@ -122,6 +126,7 @@ tasks:
-coverprofile=coverage_unit.txt \
{{default .DEFAULT_INTEGRATIONTEST_GO_PACKAGES .GO_PACKAGES}} \
{{.TEST_LDFLAGS}}
go tool covdata textfmt -i=coverage_data -o coverage_integration.txt
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
go:vet:
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ submitting a PR:

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

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

If you want to run integration tests you will also need:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/arduino/arduino-cli

go 1.19
go 1.20

// We must use this fork until https://github.com/mailru/easyjson/pull/372 is merged
replace github.com/mailru/easyjson => github.com/cmaglie/easyjson v0.8.1
Expand Down
16 changes: 14 additions & 2 deletions internal/integrationtest/arduino-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type ArduinoCLI struct {
path *paths.Path
t *require.Assertions
proc *executils.Process
stdIn io.WriteCloser
cliEnvVars map[string]string
cliConfigPath *paths.Path
stagingDir *paths.Path
Expand Down Expand Up @@ -122,7 +123,12 @@ func NewArduinoCliWithinEnvironment(env *Environment, config *ArduinoCLIConfig)
func (cli *ArduinoCLI) CleanUp() {
if cli.proc != nil {
cli.daemonConn.Close()
cli.proc.Kill()
cli.stdIn.Close()
proc := cli.proc
go func() {
time.Sleep(time.Second)
proc.Kill()
}()
cli.proc.Wait()
}
}
Expand Down Expand Up @@ -185,6 +191,11 @@ func (cli *ArduinoCLI) convertEnvForExecutils(env map[string]string) []string {
for k, v := range env {
envVars = append(envVars, fmt.Sprintf("%s=%s", k, v))
}

// Proxy code-coverage related env vars
if gocoverdir := os.Getenv("INTEGRATION_GOCOVERDIR"); gocoverdir != "" {
envVars = append(envVars, "GOCOVERDIR="+gocoverdir)
}
return envVars
}

Expand Down Expand Up @@ -246,10 +257,11 @@ func (cli *ArduinoCLI) StartDaemon(verbose bool) string {
cli.t.NoError(err)
stderr, err := cliProc.StderrPipe()
cli.t.NoError(err)
_, err = cliProc.StdinPipe()
stdIn, err := cliProc.StdinPipe()
cli.t.NoError(err)

cli.t.NoError(cliProc.Start())
cli.stdIn = stdIn
cli.proc = cliProc
cli.daemonAddr = "127.0.0.1:50051"

Expand Down

0 comments on commit 5a5ae94

Please sign in to comment.