Skip to content
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

Create action to store test coverage #227

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion acceptance/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inputs:
timeout:
description: 'Maximum suite execution time. Defaults to 1h'
required: false
default: 1h
default: 55m
create_issues:
description: 'Create issues in the repository for failed tests'
required: false
Expand Down
104 changes: 104 additions & 0 deletions acceptance/cmd/download-artifacts/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package main

import (
"archive/zip"
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"os"

"github.com/databricks/databricks-sdk-go/logger"
"github.com/databrickslabs/sandbox/acceptance/ecosystem"
"github.com/databrickslabs/sandbox/go-libs/github"
)

func main() {
logger.DefaultLogger = &logger.SimpleLogger{
Level: logger.LevelDebug,
}
d, err := New()
if err != nil {
panic(err)
}
err = d.run(context.Background())
if err != nil {
panic(err)
}
}

type downloader struct {
gh *github.GitHubClient
}

func New() (*downloader, error) {
return &downloader{gh: github.NewClient(&github.GitHubConfig{})}, nil
}

type testResult struct {
ecosystem.TestResult
Branch string `json:"branch"`
SHA string `json:"sha"`
}

func (d *downloader) run(ctx context.Context) error {
var results []testResult
it := d.gh.ListArtifacts(ctx, "databrickslabs", "ucx")
for it.HasNext(ctx) {
artifact, err := it.Next(ctx)
if err != nil {
return fmt.Errorf("next: %w", err)
}
if artifact.Expired {
continue
}
logger.Debugf(ctx, "Downloading %s", artifact.Name)
buf, err := d.gh.DownloadArtifact(ctx, "databrickslabs", "ucx", artifact.ID)
if err != nil {
return fmt.Errorf("download: %w", err)
}
zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), artifact.SizeInBytes)
if err != nil {
return fmt.Errorf("zip: read: %w", err)
}
reader, err := zr.Open("test-report.json")
if err != nil {
return fmt.Errorf("zip: test-report.json: %w", err)
}
defer reader.Close()
scanner := bufio.NewScanner(reader)
bufSize := 1024 * 1024 * 50
scanner.Buffer(make([]byte, bufSize), bufSize)
for scanner.Scan() {
var line testResult
err = json.Unmarshal(scanner.Bytes(), &line)
if err != nil {
return fmt.Errorf("zip: test-report.json: json: %w", err)
}
line.Branch = artifact.WorflowRun.HeadBranch
line.SHA = artifact.WorflowRun.HeadSHA
results = append(results, line)
}
if err := scanner.Err(); err != nil {
return fmt.Errorf("zip: test-report.json: scan: %w", err)
}
logger.Debugf(ctx, "num results %d", len(results))
}

file, err := os.OpenFile("/tmp/ucx-results.json", os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return err
}
defer file.Close()
enc := json.NewEncoder(file)
for _, v := range results {
err := enc.Encode(v)
if err != nil {
return fmt.Errorf("encode: %w", err)
}
}

logger.Debugf(ctx, "num results %d", len(results))
return nil
}
2 changes: 1 addition & 1 deletion acceptance/ecosystem/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (r pyTestRunner) prepare(ctx context.Context, redact redaction.Redaction, l
return nil, fmt.Errorf("prepend: %w", err)
}
ctx = tc.WithPath(ctx, testRoot)
if tc.AcceptancePath != "" {
if tc.AcceptancePath != "" { // TODO: make it scale for unit tests as well.
testRoot = filepath.Join(testRoot, tc.AcceptancePath)
}
logDir := env.Get(ctx, LogDirEnv)
Expand Down
25 changes: 25 additions & 0 deletions coverage/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
default: build

fmt: lint
@echo "✓ Formatting source code with goimports ..."
@goimports -w $(shell find . -type f -name '*.go' -not -path "./vendor/*")
@echo "✓ Formatting source code with gofmt ..."
@gofmt -w $(shell find . -type f -name '*.go' -not -path "./vendor/*")

lint: vendor
@echo "✓ Linting source code with https://staticcheck.io/ ..."
@staticcheck ./...

test:
@echo "✓ Running tests ..."
@gotestsum --format pkgname-and-test-fails --no-summary=skipped --raw-command go test -v -json -short -coverprofile=coverage.txt ./...

coverage: test
@echo "✓ Opening coverage for unit tests ..."
@go tool cover -html=coverage.txt

vendor:
@echo "✓ Filling vendor folder with library code ..."
@go mod vendor

.PHONY: build vendor coverage test lint fmt
10 changes: 10 additions & 0 deletions coverage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "GitHub Action for Code Coverage"
language: go
author: "Serge Smertin"
date: 2024-01-15

tags:
- github
- testing
---
20 changes: 20 additions & 0 deletions coverage/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: 'Databricks Labs Coverage Suite'
description: 'Run relevant coverage suite'
author: Serge Smertin
inputs:
project:
description: 'Project Name'
required: false
directory:
description: 'Working directory'
required: false
default: .
outputs:
sample:
description: 'Sample output'
value: ${{ steps.invoke.outputs.sample }}

runs:
using: node20
main: shim.js
60 changes: 60 additions & 0 deletions coverage/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module github.com/databrickslabs/sandbox/coverage

go 1.21.0

require (
github.com/databrickslabs/sandbox/acceptance v0.2.2 // Databricks License
github.com/databrickslabs/sandbox/go-libs v0.4.0 // Databricks License
github.com/sethvargo/go-githubactions v1.2.0 // Apache 2.0
github.com/stretchr/testify v1.9.0
)

require (
cloud.google.com/go/auth v0.7.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.12.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.9.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/azsecrets v0.12.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.3.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/databricks/databricks-sdk-go v0.40.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.188.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading