Skip to content

Commit

Permalink
feat(backstage): add coverage reporting tool
Browse files Browse the repository at this point in the history
  • Loading branch information
maxekman committed Dec 19, 2023
1 parent d590dc2 commit fd3f5b4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tools/sgbackstagecoverage/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package sgbackstagecoverage

import (
"context"
"fmt"
"net/http"
"os"

"go.einride.tech/sage/sg"
"go.einride.tech/sage/tools/sggcov2lcov"
)

func PostCoverage(ctx context.Context, entity string) error {
sg.Deps(ctx, sggcov2lcov.Command)
url := fmt.Sprintf("https://api.roadie.so/api/code-coverage/report?entity=%s&coverageType=lcov", entity)
coverFile := sg.FromBuildDir("go", "coverage", "go-test.lcov")
f, err := os.Open(coverFile)
if err != nil {
return fmt.Errorf("opening coverage file: %w", err)
}
req, err := http.NewRequestWithContext(ctx, "POST", url, f)

Check failure on line 21 in tools/sgbackstagecoverage/tools.go

View workflow job for this annotation

GitHub Actions / build

"POST" can be replaced by http.MethodPost (usestdlibvars)
if err != nil {
return fmt.Errorf("creating coverage POST request: %w", err)
}
req.Header.Set("Content-Type", "text/plain")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", os.Getenv("ROADIE_AUTH_TOKEN")))
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("posting coverage data: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
return fmt.Errorf("coverage post status not OK: %s", http.StatusText(resp.StatusCode))
}
return nil
}

0 comments on commit fd3f5b4

Please sign in to comment.