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

remove deprecated code #202

Draft
wants to merge 7 commits 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
59 changes: 4 additions & 55 deletions cmd/buildutil/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"net/url"
"os"
"path"
"regexp"
"strconv"
"strings"
"time"

"github.com/pkg/errors"
"github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil"
"github.com/sirupsen/logrus"
"golang.org/x/mod/modfile"
Expand Down Expand Up @@ -173,11 +171,10 @@ type BuildInfo struct {
}

type ArtifactInfo struct {
Kind string
Filename string
S3Location *S3URL `json:",omitempty"`
Aliases []string `json:",omitempty"`
System SystemInfo
Kind string
Filename string
Aliases []string `json:",omitempty"`
System SystemInfo
}

func (i *BuildInfo) NewArtifactInfo(kind string, name string, system SystemInfo, ext string) ArtifactInfo {
Expand Down Expand Up @@ -395,53 +392,5 @@ func CollectBuildInformation(ctx context.Context, p BuildParameters) (BuildInfo,
}
}

if p.S3URL != "" {
base, err := ParseS3URL(p.S3URL)
if err != nil {
return info, errors.WithStack(err)
}

for i, a := range info.Artifacts {
u := base.Subpath(a.Filename)
info.Artifacts[i].S3Location = &u
}
}

return info, nil
}

type S3URL struct {
Bucket string
Key string
}

func ParseS3URL(raw string) (*S3URL, error) {
u, err := url.Parse(raw)
if err != nil {
return nil, errors.Wrap(err, "failed to parse S3 URL")
}

if u.Scheme != "s3" && u.Scheme != "" {
return nil, errors.Errorf("Unknown scheme %s for the S3 URL", u.Scheme)
}

return &S3URL{
Bucket: u.Host,
Key: strings.TrimPrefix(path.Clean(u.Path), "/"),
}, nil
}

func (u S3URL) Subpath(p ...string) S3URL {
p = append([]string{u.Key}, p...)
u.Key = path.Join(p...)
return u // This is actually a copy, since we do not use pointers.
}

func (u S3URL) String() string {
return fmt.Sprintf("s3://%s/%s", u.Bucket, u.Key)
}

func (u S3URL) MarshalJSON() ([]byte, error) {
s := u.String()
return json.Marshal(s)
}
9 changes: 6 additions & 3 deletions cmd/buildutil/logutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import (
"fmt"
"os"

"github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil"
"github.com/tidwall/pretty"
)

func dumpJSON(data interface{}) {
func dumpJSON(data interface{}) error {
b, err := json.MarshalIndent(data, "", " ")
cmdutil.Must(err)
if err != nil {
return err
}

b = pretty.Color(b, pretty.TerminalStyle)
fmt.Fprintln(os.Stderr, string(b))

return nil
}
51 changes: 1 addition & 50 deletions cmd/buildutil/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"context"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand All @@ -17,59 +15,12 @@ func main() {
}

func NewRootCommand() *cobra.Command {
runner := new(Runner)

return cmdutil.New(
"buildutil", "Build tool for Go projects as part of the rebuy-go-sdk",
cmdutil.WithLogVerboseFlag(),
cmdutil.WithVersionCommand(),
cmdutil.WithVersionLog(logrus.DebugLevel),

runner.Bind,
cmdutil.WithRun(runner.RunAll),

cmdutil.WithSubCommand(cmdutil.New(
"info", "Show project info",
// Info output is already done by the prerun, therefore we do not
// need to actually do anything.
cmdutil.WithRun(func(ctx context.Context, cmd *cobra.Command, args []string) {}),
)),

cmdutil.WithSubCommand(cmdutil.New(
"vendor", "Update vendor directory",
cmdutil.WithRun(runner.RunVendor),
)),
cmdutil.WithSubCommand(cmdutil.New(
"test", "Run unit tests",
cmdutil.WithRun(runner.RunTest),
cmdutil.WithSubCommand(cmdutil.New(
"fmt", "Tests file formatting",
cmdutil.WithRun(runner.RunTestFormat),
)),
cmdutil.WithSubCommand(cmdutil.New(
"vet", "Tests for suspicious constructs",
cmdutil.WithRun(runner.RunTestVet),
)),
cmdutil.WithSubCommand(cmdutil.New(
"packages", "Tests Packages",
cmdutil.WithRun(runner.RunTestPackages),
)),
)),
cmdutil.WithSubCommand(cmdutil.New(
"build", "Build binaries",
cmdutil.WithRun(runner.RunBuild),
)),
cmdutil.WithSubCommand(cmdutil.New(
"artifacts", "Create artifacts",
cmdutil.WithRun(runner.RunArtifacts),
)),
cmdutil.WithSubCommand(cmdutil.New(
"upload", "Upload artifacts to S3",
cmdutil.WithRun(runner.RunUpload),
)),
cmdutil.WithSubCommand(cmdutil.New(
"clean", "Clean workspace",
cmdutil.WithRun(runner.RunClean),
)),
cmdutil.WithRunner(new(Runner)),
)
}
Loading
Loading