From ae0d4f61aa37e708638255f025a4f8887b3b5663 Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Fri, 15 Sep 2023 18:14:52 +0100 Subject: [PATCH 1/9] display operation duration and enhance log (#6) --- cloud/aws/apigateway.go | 2 +- cloud/aws/logs.go | 2 +- internal/log/log.go | 15 ++++++++--- jerm.go | 56 ++++++++++++++++++++++++++++------------- 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/cloud/aws/apigateway.go b/cloud/aws/apigateway.go index 5d437a7..5483202 100644 --- a/cloud/aws/apigateway.go +++ b/cloud/aws/apigateway.go @@ -64,7 +64,7 @@ func (a *ApiGateway) setup(functionArn *string) error { return err } - log.PrintInfo(fmt.Sprintf("Project %s is now live at %s", a.config.Name, apiUrl)) + fmt.Printf("%s %s", log.Magenta("url:"), log.Green(apiUrl)) return nil } diff --git a/cloud/aws/logs.go b/cloud/aws/logs.go index cb160a0..637c847 100644 --- a/cloud/aws/logs.go +++ b/cloud/aws/logs.go @@ -64,7 +64,7 @@ func (c *CloudWatch) printLogs(logs []cwTypes.FilteredLogEvent) { strings.Contains(*message, "END RequestId") { continue } - log.PrintInfo(fmt.Sprintf("[%s] %s\n", time, strings.TrimSpace(*message))) + log.PrintfInfo("[%s] %s\n", time, strings.TrimSpace(*message)) } } diff --git a/internal/log/log.go b/internal/log/log.go index 72b2da7..e49c7c1 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -7,9 +7,18 @@ import ( ) var ( - PrintError = color.New(color.FgRed).PrintlnFunc() - PrintWarn = color.New(color.FgYellow).PrintlnFunc() - PrintInfo = color.New(color.FgCyan).PrintlnFunc() + PrintError = color.New(color.FgRed).PrintlnFunc() + PrintfError = color.New(color.FgRed).PrintfFunc() + PrintWarn = color.New(color.FgYellow).PrintlnFunc() + PrintfWarn = color.New(color.FgYellow).PrintfFunc() + PrintInfo = color.New(color.FgCyan).PrintlnFunc() + PrintfInfo = color.New(color.FgCyan).PrintfFunc() + Yellow = color.New(color.FgYellow).SprintFunc() + Red = color.New(color.FgRed).SprintFunc() + Blue = color.New(color.FgBlue).SprintFunc() + Green = color.New(color.FgGreen).SprintFunc() + White = color.New(color.FgWhite).SprintFunc() + Magenta = color.New(color.FgMagenta).SprintFunc() ) func Info(msg string, v ...interface{}) { diff --git a/jerm.go b/jerm.go index d7dc3dd..2135e52 100644 --- a/jerm.go +++ b/jerm.go @@ -9,6 +9,7 @@ import ( "path" "path/filepath" "strings" + "time" "github.com/spatocode/jerm/config" "github.com/spatocode/jerm/internal/log" @@ -53,14 +54,25 @@ func (p *Project) SetPlatform(cloud CloudPlatform) { // Deploy deploys the project to the cloud func (p *Project) Deploy() { - log.PrintInfo(fmt.Sprintf("Deploying project %s...", p.config.Name)) - file, err := p.packageProject() + log.PrintfInfo("Deploying project %s...", p.config.Name) + + start := time.Now() + + deployInfo := func(size int64, start time.Time, buildDuration time.Duration) { + deployDuration := time.Since(start) + fmt.Printf("%s %s %v %s, (%s)\n", log.Magenta("build:"), log.Green("completed"), log.White(size/2048), log.Blue("MB"), log.White(buildDuration.Round(time.Second))) + fmt.Printf("%s %s (%s)\n", log.Magenta("deploy:"), log.Green("completed"), log.White(deployDuration.Round(time.Second))) + } + + file, size, err := p.packageProject() if err != nil { log.PrintError(err.Error()) return } defer os.RemoveAll(*file) + buildDuration := time.Since(start) + alreadyDeployed, err := p.cloud.Deploy(*file) if err != nil { log.PrintError(err.Error()) @@ -68,16 +80,17 @@ func (p *Project) Deploy() { } if alreadyDeployed { - log.PrintInfo("Project already deployed. Updating...") + log.Debug("project already deployed. updating...") err = p.Update(file) if err != nil { log.PrintError(err.Error()) return } + deployInfo(size, start, buildDuration) return } - log.PrintInfo("Done!") + deployInfo(size, start, buildDuration) } // Update updates the deployed project @@ -87,7 +100,7 @@ func (p *Project) Update(zipPath *string) error { file := zipPath if zipPath == nil { - file, err = p.packageProject() + file, _, err = p.packageProject() if err != nil { return err } @@ -99,50 +112,57 @@ func (p *Project) Update(zipPath *string) error { } defer os.RemoveAll(*file) - log.PrintInfo("Done!") return nil } // Undeploy terminates a deployment func (p *Project) Undeploy() { - log.PrintInfo(fmt.Sprintf("Undeploying project %s...", p.config.Name)) + log.PrintInfo("Undeploying project...") + + start := time.Now() err := p.cloud.Undeploy() if err != nil { log.PrintError(err.Error()) return } - log.PrintInfo("Done!") + + duration := time.Since(start) + fmt.Printf("%s %s (%s)\n", log.Magenta("undeploy:"), log.Green("completed"), log.White(duration.Round(time.Second))) } // Rollback rolls back a deployment to previous versions func (p *Project) Rollback(steps int) { log.PrintInfo("Rolling back deployment...") + + start := time.Now() err := p.cloud.Rollback(steps) if err != nil { log.PrintError(err.Error()) } - log.PrintInfo("Done!") + + duration := time.Since(start) + fmt.Printf("%s %s (%s)\n", log.Magenta("rollback:"), log.Green("completed"), log.White(duration.Round(time.Second))) } // packageProject packages a project for deployment -func (p *Project) packageProject() (*string, error) { +func (p *Project) packageProject() (*string, int64, error) { log.Debug("packaging project...") dir, err := p.cloud.Build() if err != nil { - return nil, err + return nil, 0, err } archivePath := path.Join(p.config.Dir, ArchiveFile) - err = p.archivePackage(archivePath, dir) - return &archivePath, err + size, err := p.archivePackage(archivePath, dir) + return &archivePath, size, err } // archivePackage creates an archive file from a project -func (p *Project) archivePackage(archivePath, dir string) error { +func (p *Project) archivePackage(archivePath, dir string) (int64, error) { log.Debug("archiving package...") archive, err := os.Create(archivePath) if err != nil { - return err + return 0, err } defer archive.Close() @@ -177,8 +197,10 @@ func (p *Project) archivePackage(archivePath, dir string) error { } err = filepath.WalkDir(dir, walker) if err != nil { - return err + return 0, err } - return nil + info, err := archive.Stat() + + return info.Size(), err } From d124c7cc5a630056d148be1a30549ec8b5d38128 Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Sat, 16 Sep 2023 08:53:03 +0100 Subject: [PATCH 2/9] optimizations by leveraging go concurrency (#5) * initial optimization * code optimizations --- cloud/aws/lambda.go | 18 +++-- config/python.go | 159 +++++++++++++++++++++++++++----------------- go.mod | 1 + go.sum | 2 + jerm.go | 3 + 5 files changed, 118 insertions(+), 65 deletions(-) diff --git a/cloud/aws/lambda.go b/cloud/aws/lambda.go index 9a77292..df9dc98 100644 --- a/cloud/aws/lambda.go +++ b/cloud/aws/lambda.go @@ -72,10 +72,12 @@ func NewLambda(cfg *config.Config) (*Lambda, error) { l.access = NewIAM(cfg, *awsConfig) l.apigateway = NewApiGateway(cfg, *awsConfig) - err = l.config.ToJson(jerm.DefaultConfigFile) - if err != nil { - return nil, err - } + go func() { + err := l.config.ToJson(jerm.DefaultConfigFile) + if err != nil { + log.PrintWarn(err) + } + }() err = l.access.checkPermissions() if err != nil { @@ -88,11 +90,19 @@ func NewLambda(cfg *config.Config) (*Lambda, error) { // Build builds the deployment package for lambda func (l *Lambda) Build() (string, error) { log.Debug("building Jerm project for Lambda...") + p := config.NewPythonConfig() if l.config.Entry == "" { l.config.Entry = p.Entry() } + go func() { + err := l.config.ToJson(jerm.DefaultConfigFile) + if err != nil { + log.PrintWarn(err) + } + }() + handler, err := p.Build(l.config) dir := filepath.Dir(handler) if err != nil { diff --git a/config/python.go b/config/python.go index 69492e3..5757ac4 100644 --- a/config/python.go +++ b/config/python.go @@ -12,6 +12,8 @@ import ( "runtime" "strings" + "golang.org/x/sync/errgroup" + "github.com/otiai10/copy" "github.com/spatocode/jerm/internal/log" "github.com/spatocode/jerm/internal/utils" @@ -86,8 +88,8 @@ func (p *Python) Build(config *Config) (string, error) { venv, err := p.getVirtualEnvironment() if err != nil { - err = p.installRequirements(tempDir) - return handlerPath, err + //TODO: installs requirements listed in requirements.txt file + return "", fmt.Errorf("cannot find a virtual env. Please ensure you're running in a virtual env") } version := strings.Split(DetectRuntime().Version, ".") @@ -96,14 +98,35 @@ func (p *Python) Build(config *Config) (string, error) { sitePackages = path.Join(venv, "Lib", "site-packages") } - p.installNecessaryDependencies(tempDir, sitePackages) - p.copyNecessaryFilesToTempDir(config.Dir, tempDir) - p.copyNecessaryFilesToTempDir(sitePackages, tempDir) - log.Debug(fmt.Sprintf("build Python deployment package at %s", tempDir)) - return handlerPath, nil + dependencies := map[string]string{ + "lambda-wsgi-adapter": "0.1.1", + } + if !utils.FileExists(filepath.Join(sitePackages, "werkzeug")) { + dependencies["werkzeug"] = "0.16.1" + } + + err = p.installNecessaryDependencies(tempDir, sitePackages, dependencies) + if err != nil { + return "", err + } + + err = p.copyNecessaryFilesToTempDir(config.Dir, tempDir) + if err != nil { + return "", err + } + + err = p.copyNecessaryFilesToTempDir(sitePackages, tempDir) + if err != nil { + return "", err + } + + log.Debug(fmt.Sprintf("built Python deployment package at %s", tempDir)) + + return handlerPath, err } func (p *Python) copyNecessaryFilesToTempDir(src, dest string) error { + log.Debug("copying necessary Python files...") opt := copy.Options{ Skip: func(srcinfo os.FileInfo, src, dest string) (bool, error) { for _, glob := range defaultIgnoredGlobs { @@ -125,49 +148,54 @@ func (p *Python) copyNecessaryFilesToTempDir(src, dest string) error { } // installRequirements installs requirements listed in requirements.txt file -func (p *Python) installRequirements(dir string) error { - return nil -} +// func (p *Python) installRequirements(dir string) error { +// return nil +// } // installNecessaryDependencies installs dependencies needed to run serverless Python -func (p *Python) installNecessaryDependencies(dir, sitePackages string) error { +func (p *Python) installNecessaryDependencies(dir, sitePackages string, dependencies map[string]string) error { log.Debug("installing necessary Python dependencies...") - - dependencies := map[string]string{ - "lambda-wsgi-adapter": "0.1.1", - } - if !utils.FileExists(filepath.Join(sitePackages, "werkzeug")) { - dependencies["werkzeug"] = "0.16.1" - } + var eg errgroup.Group for project, version := range dependencies { - url := fmt.Sprintf("https://pypi.org/pypi/%s/json", project) - res, err := utils.Request(url) - if err != nil { - return err - } - defer res.Body.Close() - b, err := io.ReadAll(res.Body) - if err != nil { - return err - } - data := make(map[string]interface{}) - err = json.Unmarshal(b, &data) - if err != nil { - return err - } + func (dep, ver string) { + eg.Go(func () error { + url := fmt.Sprintf("https://pypi.org/pypi/%s/json", dep) + res, err := utils.Request(url) + if err != nil { + return err + } + defer res.Body.Close() + b, err := io.ReadAll(res.Body) + if err != nil { + return err + } + data := make(map[string]interface{}) + err = json.Unmarshal(b, &data) + if err != nil { + return err + } - r := data["releases"] - releases, _ := r.(map[string]interface{}) - for _, v := range releases[version].([]interface{}) { - url := v.(map[string]interface{})["url"].(string) - filename := v.(map[string]interface{})["filename"].(string) - if filepath.Ext(filename) == ".whl" { - p.downloadDependencies(url, filename, dir) - } - } + r := data["releases"] + releases, _ := r.(map[string]interface{}) + for _, v := range releases[ver].([]interface{}) { + url := v.(map[string]interface{})["url"].(string) + filename := v.(map[string]interface{})["filename"].(string) + if filepath.Ext(filename) == ".whl" { + err := p.downloadDependencies(url, filename, dir) + if err != nil { + return err + } + } + } + return nil + }) + }(project, version) } - return nil + + err := eg.Wait() + + return err } // downloadDependencies downloads dependencies from pypi @@ -206,6 +234,8 @@ func (p *Python) downloadDependencies(url, filename, dir string) error { func (p *Python) extractWheel(wheelPath, outputDir string) error { log.Debug("extracting python wheel...") + var eg errgroup.Group + reader, err := zip.OpenReader(wheelPath) if err != nil { return err @@ -213,29 +243,36 @@ func (p *Python) extractWheel(wheelPath, outputDir string) error { defer reader.Close() for _, file := range reader.File { - os.MkdirAll(filepath.Join(outputDir, filepath.Dir(file.Name)), 0755) - if err != nil { - return err - } + func (file *zip.File) { + eg.Go(func () error { + os.MkdirAll(filepath.Join(outputDir, filepath.Dir(file.Name)), 0755) + if err != nil { + return err + } - extractedFile, err := os.Create(filepath.Join(outputDir, file.Name)) - if err != nil { - return err - } - defer extractedFile.Close() + extractedFile, err := os.Create(filepath.Join(outputDir, file.Name)) + if err != nil { + return err + } + defer extractedFile.Close() - zippedFile, err := file.Open() - if err != nil { - return err - } - defer zippedFile.Close() + zippedFile, err := file.Open() + if err != nil { + return err + } + defer zippedFile.Close() - if _, err = io.Copy(extractedFile, zippedFile); err != nil { - return err - } + if _, err = io.Copy(extractedFile, zippedFile); err != nil { + return err + } + return nil + }) + }(file) } - return nil + err = eg.Wait() + + return err } func (p *Python) IsDjango() bool { diff --git a/go.mod b/go.mod index a2acc90..fa63c48 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/otiai10/copy v1.12.0 github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.4 + golang.org/x/sync v0.3.0 ) require ( diff --git a/go.sum b/go.sum index 5b5a40f..6a7c6cf 100644 --- a/go.sum +++ b/go.sum @@ -93,6 +93,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/jerm.go b/jerm.go index 2135e52..eef9c1b 100644 --- a/jerm.go +++ b/jerm.go @@ -147,6 +147,7 @@ func (p *Project) Rollback(steps int) { // packageProject packages a project for deployment func (p *Project) packageProject() (*string, int64, error) { log.Debug("packaging project...") + dir, err := p.cloud.Build() if err != nil { return nil, 0, err @@ -160,6 +161,7 @@ func (p *Project) packageProject() (*string, int64, error) { // archivePackage creates an archive file from a project func (p *Project) archivePackage(archivePath, dir string) (int64, error) { log.Debug("archiving package...") + archive, err := os.Create(archivePath) if err != nil { return 0, err @@ -195,6 +197,7 @@ func (p *Project) archivePackage(archivePath, dir string) (int64, error) { } return nil } + err = filepath.WalkDir(dir, walker) if err != nil { return 0, err From 5185b9b26669f8fbb53761bf8a402e4d2286768c Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Sat, 16 Sep 2023 11:36:12 +0100 Subject: [PATCH 3/9] fix: build size miscalculation #6 --- jerm.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jerm.go b/jerm.go index eef9c1b..9d831fa 100644 --- a/jerm.go +++ b/jerm.go @@ -54,13 +54,13 @@ func (p *Project) SetPlatform(cloud CloudPlatform) { // Deploy deploys the project to the cloud func (p *Project) Deploy() { - log.PrintfInfo("Deploying project %s...", p.config.Name) + log.PrintfInfo("Deploying project %s...\n", p.config.Name) start := time.Now() deployInfo := func(size int64, start time.Time, buildDuration time.Duration) { deployDuration := time.Since(start) - fmt.Printf("%s %s %v %s, (%s)\n", log.Magenta("build:"), log.Green("completed"), log.White(size/2048), log.Blue("MB"), log.White(buildDuration.Round(time.Second))) + fmt.Printf("%s %s %v %s, (%s)\n", log.Magenta("build:"), log.Green("completed"), log.White(size/1000000), log.White("MB"), log.White(buildDuration.Round(time.Second))) fmt.Printf("%s %s (%s)\n", log.Magenta("deploy:"), log.Green("completed"), log.White(deployDuration.Round(time.Second))) } From 04a84742c1c57eb3de5dfcec479e76df04f2c028 Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Sat, 16 Sep 2023 12:24:02 +0100 Subject: [PATCH 4/9] static_analysis workflow --- .github/workflows/static_analysis.yml | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/static_analysis.yml diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml new file mode 100644 index 0000000..d4df2ae --- /dev/null +++ b/.github/workflows/static_analysis.yml @@ -0,0 +1,43 @@ +name: Static Analysis +on: [pull_request] +permissions: + content: read + +jobs: + static_analysis: + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + - uses: WillAbides/setup-go-faster@1.7.0 + with: + go-version: '1.19.x' + + - name: Install dependencies + run: | + sudo apt-get update && sudo apt-get install gcc libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libx11-dev xorg-dev + + - name: Install analysis tools + run: | + go install golang.org/x/tools/cmd/goimports@latest + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest + go install honnef.co/go/tools/cmd/staticcheck@v0.4.0 + + - name: Vet + run: go vet -tags ci ./... + + - name: Format + run: gofmt -w ./... + + - name: Goimports + run: test -z "$(goimports -e -d . | tee /dev/stderr)" + + - name: Gocyclo + run: gocyclo -over 30 . + + - name: Staticcheck + run: staticcheck ./... \ No newline at end of file From fe7f881f9b6d784d2063b5ea13e85d755413cab0 Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Sat, 16 Sep 2023 15:28:56 +0100 Subject: [PATCH 5/9] setup workflow --- .github/workflows/static_analysis.yml | 12 +++++------ .github/workflows/tests.yml | 31 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml index d4df2ae..9ce435a 100644 --- a/.github/workflows/static_analysis.yml +++ b/.github/workflows/static_analysis.yml @@ -1,7 +1,7 @@ name: Static Analysis on: [pull_request] permissions: - content: read + contents: read jobs: static_analysis: @@ -13,9 +13,10 @@ jobs: - uses: actions/checkout@v2 with: persist-credentials: false - - uses: WillAbides/setup-go-faster@1.7.0 + + - uses: WillAbides/setup-go-faster@v1.8.0 with: - go-version: '1.19.x' + go-version: '1.21.x' - name: Install dependencies run: | @@ -30,9 +31,6 @@ jobs: - name: Vet run: go vet -tags ci ./... - - name: Format - run: gofmt -w ./... - - name: Goimports run: test -z "$(goimports -e -d . | tee /dev/stderr)" @@ -40,4 +38,4 @@ jobs: run: gocyclo -over 30 . - name: Staticcheck - run: staticcheck ./... \ No newline at end of file + run: staticcheck ./... diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..1a2252e --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,31 @@ +name: Tests +on: [pull_request] +permissions: + contents: read + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + + - uses: WillAbides/setup-go-faster@v1.8.0 + with: + go-version: '1.21.x' + + - name: Install dependencies + run: | + sudo apt-get update && sudo apt-get install gcc libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libx11-dev xorg-dev + + - name: Tests + run: go test -v -coverprofile=profile.cov -vet=off ./... + + - name: Code coverage + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: profile.cov From c5dcd2d6c344ceb329472d36d483caf596dc9192 Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Sat, 16 Sep 2023 16:00:04 +0100 Subject: [PATCH 6/9] use script to set minimum coverage percentage --- .github/workflows/tests.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1a2252e..3d4eb4c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,9 +23,13 @@ jobs: sudo apt-get update && sudo apt-get install gcc libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libx11-dev xorg-dev - name: Tests - run: go test -v -coverprofile=profile.cov -vet=off ./... + run: | + set -e + go test -v -coverprofile=coverage.out -vet=off ./... + coverage=`go tool cover -func coverage.out | grep total | tr -s '\t' | cut -f 3 | grep -o '[^%]*'` + if (( $(echo "$coveraage < 63" | bc) )); then echo "Test coverage lowered"; exit 1; fi - name: Code coverage uses: shogo82148/actions-goveralls@v1 with: - path-to-profile: profile.cov + path-to-profile: coverage.out From 8c6472636e56334e7b7a169d23059cb9a90d1537 Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Sat, 16 Sep 2023 16:07:27 +0100 Subject: [PATCH 7/9] fix typo --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3d4eb4c..8a85f4b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,7 +27,7 @@ jobs: set -e go test -v -coverprofile=coverage.out -vet=off ./... coverage=`go tool cover -func coverage.out | grep total | tr -s '\t' | cut -f 3 | grep -o '[^%]*'` - if (( $(echo "$coveraage < 63" | bc) )); then echo "Test coverage lowered"; exit 1; fi + if (( $(echo "$coverage < 63" | bc) )); then echo "Test coverage lowered"; exit 1; fi - name: Code coverage uses: shogo82148/actions-goveralls@v1 From df6685a36a25dd915a985a15582c0d4943382a14 Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Sat, 16 Sep 2023 16:35:35 +0100 Subject: [PATCH 8/9] move coverage job to static analysis workflow --- .github/workflows/static_analysis.yml | 12 ++++++++++++ .github/workflows/tests.yml | 11 +---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml index 9ce435a..ca27a38 100644 --- a/.github/workflows/static_analysis.yml +++ b/.github/workflows/static_analysis.yml @@ -39,3 +39,15 @@ jobs: - name: Staticcheck run: staticcheck ./... + + - name: Coverage + run: | + set -e + go test -covermode=atomic -coverprofile=coverage.out -vet=off ./... + coverage=`go tool cover -func coverage.out | grep total | tr -s '\t' | cut -f 3 | grep -o '[^%]*'` + if (( $(echo "$coverage < 63" | bc) )); then echo "Test coverage lowered"; exit 1; fi + + - name: PR coverage + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: coverage.out \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8a85f4b..510329b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,13 +23,4 @@ jobs: sudo apt-get update && sudo apt-get install gcc libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libx11-dev xorg-dev - name: Tests - run: | - set -e - go test -v -coverprofile=coverage.out -vet=off ./... - coverage=`go tool cover -func coverage.out | grep total | tr -s '\t' | cut -f 3 | grep -o '[^%]*'` - if (( $(echo "$coverage < 63" | bc) )); then echo "Test coverage lowered"; exit 1; fi - - - name: Code coverage - uses: shogo82148/actions-goveralls@v1 - with: - path-to-profile: coverage.out + run: go test -v -vet=off ./... From 0089d73fcf9b38dfd7b694fff6817d80ae4b8619 Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Sat, 16 Sep 2023 17:20:37 +0100 Subject: [PATCH 9/9] style: enforce go code formatting --- config/python.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/python.go b/config/python.go index 5757ac4..6e53cd7 100644 --- a/config/python.go +++ b/config/python.go @@ -158,8 +158,8 @@ func (p *Python) installNecessaryDependencies(dir, sitePackages string, dependen var eg errgroup.Group for project, version := range dependencies { - func (dep, ver string) { - eg.Go(func () error { + func(dep, ver string) { + eg.Go(func() error { url := fmt.Sprintf("https://pypi.org/pypi/%s/json", dep) res, err := utils.Request(url) if err != nil { @@ -243,8 +243,8 @@ func (p *Python) extractWheel(wheelPath, outputDir string) error { defer reader.Close() for _, file := range reader.File { - func (file *zip.File) { - eg.Go(func () error { + func(file *zip.File) { + eg.Go(func() error { os.MkdirAll(filepath.Join(outputDir, filepath.Dir(file.Name)), 0755) if err != nil { return err