Skip to content

Commit

Permalink
remove more deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
svenwltr committed Jun 11, 2024
1 parent a7eb3d8 commit d51492b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 100 deletions.
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)
}
14 changes: 0 additions & 14 deletions cmd/buildutil/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"path"
"strings"

_ "github.com/goreleaser/nfpm/v2/deb" // blank import to register the format
_ "github.com/goreleaser/nfpm/v2/rpm" // blank import to register the format
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -55,19 +53,7 @@ func (r *Runner) Bind(cmd *cobra.Command) error {
cmd.PersistentFlags().StringSliceVarP(
&r.Parameters.TargetPackages, "package", "p", []string{},
"Packages to build.")
cmd.PersistentFlags().StringVar(
&r.Parameters.S3URL, "s3-url", "",
"S3 URL to upload compiled releases.")

cmd.PersistentFlags().BoolVar(
&r.Parameters.CreateCompressed, "compress", false,
"Creates .tgz artifacts for POSIX targets and .zip for windows.")
cmd.PersistentFlags().BoolVar(
&r.Parameters.CreateRPM, "rpm", false,
"Creates .rpm artifacts for linux targets.")
cmd.PersistentFlags().BoolVar(
&r.Parameters.CreateDEB, "deb", false,
"Creates .deb artifacts for linux targets.")
cmd.PersistentFlags().BoolVar(
&r.Parameters.CGO, "cgo", false,
"Enable CGO.")
Expand Down
29 changes: 0 additions & 29 deletions pkg/cmdutil/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ func SignalContext(ctx context.Context, signals ...os.Signal) context.Context {
type RunFunc func(cmd *cobra.Command, args []string)
type RunFuncWithContext func(ctx context.Context, cmd *cobra.Command, args []string)

func wrapRootConext(run RunFuncWithContext) RunFunc {
return func(cmd *cobra.Command, args []string) {
run(SignalRootContext(), cmd, args)
}

}

// ContextWithDelay delays the context cancel by the given delay. In the
// background it creates a new context with ContextWithValuesFrom and cancels
// it after the original one got canceled.
Expand All @@ -63,25 +56,3 @@ func ContextWithDelay(in context.Context, delay time.Duration) context.Context {
}()
return out
}

type compositeContext struct {
deadline context.Context
done context.Context
err context.Context
value context.Context
}

func (c compositeContext) Deadline() (deadline time.Time, ok bool) {
return c.deadline.Deadline()
}
func (c compositeContext) Done() <-chan struct{} {
return c.done.Done()
}

func (c compositeContext) Err() error {
return c.err.Err()
}

func (c compositeContext) Value(key any) any {
return c.value.Value(key)
}
5 changes: 3 additions & 2 deletions pkg/podutil/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"

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

Expand Down Expand Up @@ -48,7 +47,9 @@ func StartDevcontainer(ctx context.Context, conn *Connection, name string, image
// API.
TimeoutSeconds: 3600 * 8,
}, opts...)
cmdutil.Must(err)
if err != nil {
return nil, err
}

container, err = conn.InspectContainer(name)
if err != nil {
Expand Down

0 comments on commit d51492b

Please sign in to comment.