Skip to content

Extend code-coverage to integration test #2103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/workflows/test-go-task.yml
Original file line number Diff line number Diff line change
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,7 +171,9 @@ jobs:

coverage-upload:
runs-on: ubuntu-latest
needs: test
needs:
- test
- test-integration
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -176,6 +187,7 @@ jobs:
with:
files: >
./coverage_unit.txt,
./coverage_legacy.txt
./coverage_legacy.txt,
./coverage_integration_*.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
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
5 changes: 5 additions & 0 deletions internal/integrationtest/arduino-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,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