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

Fix handling of default build create path #309

Merged
merged 1 commit into from
Jan 24, 2025
Merged
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
39 changes: 23 additions & 16 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,15 @@ func NewBuild(ctx context.Context, req *cliv1.CreateBuildRequest, token string)
return Build{}, err
}

build, err := FromExistingBuild(ctx, res.Msg.BuildId, res.Msg.BuildToken)
build, err := FromExistingBuild(ctx, res.Msg.BuildId, res.Msg.BuildToken, res)
if err != nil {
return Build{}, err
}

build.Response = res
build.BuildURL = res.Msg.BuildUrl

return build, nil
}

func FromExistingBuild(ctx context.Context, buildID, token string) (Build, error) {
func FromExistingBuild(ctx context.Context, buildID, token string, buildRes *connect.Response[cliv1.CreateBuildResponse]) (Build, error) {
client := depotapi.NewBuildClient()

finish := func(buildErr error) {
Expand All @@ -135,19 +132,29 @@ func FromExistingBuild(ctx context.Context, buildID, token string) (Build, error
}
}

req := cliv1.GetBuildRequest{BuildId: buildID}
res, err := client.GetBuild(ctx, depotapi.WithAuthentication(connect.NewRequest(&req), token))
if err != nil {
return Build{}, err
if buildRes == nil {
req := cliv1.GetBuildRequest{BuildId: buildID}
res, err := client.GetBuild(ctx, depotapi.WithAuthentication(connect.NewRequest(&req), token))
if err != nil {
return Build{}, err
}
return Build{
ID: buildID,
Token: token,
Finish: finish,
BuildURL: res.Msg.BuildUrl,
projectID: res.Msg.ProjectId,
}, nil
} else {
return Build{
ID: buildID,
Token: token,
Finish: finish,
BuildURL: buildRes.Msg.BuildUrl,
Response: buildRes,
}, nil
}

return Build{
ID: buildID,
Token: token,
Finish: finish,
BuildURL: res.Msg.BuildUrl,
projectID: res.Msg.ProjectId,
}, nil
}

type authProvider struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/helpers/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func BeginBuild(ctx context.Context, req *cliv1.CreateBuildRequest, token string
var build depotbuild.Build
var err error
if id := os.Getenv("DEPOT_BUILD_ID"); id != "" {
build, err = depotbuild.FromExistingBuild(ctx, id, token)
build, err = depotbuild.FromExistingBuild(ctx, id, token, nil)
} else {
build, err = depotbuild.NewBuild(ctx, req, token)
}
Expand Down
Loading