Skip to content

Commit

Permalink
fix(build): make git autodetection best effort
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Luhring <[email protected]>
  • Loading branch information
luhring committed Oct 21, 2024
1 parent 27a06f5 commit d87a8e1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pkg/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func buildCmd() *cobra.Command {
Args: cobra.MinimumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
log := clog.FromContext(ctx)

if traceFile != "" {
w, err := os.Create(traceFile)
Expand All @@ -110,7 +111,7 @@ func buildCmd() *cobra.Command {

defer func() {
if err := tp.Shutdown(context.WithoutCancel(ctx)); err != nil {
clog.FromContext(ctx).Errorf("shutting down trace provider: %v", err)
log.Errorf("shutting down trace provider: %v", err)
}
}()

Expand All @@ -126,18 +127,20 @@ func buildCmd() *cobra.Command {

// Favor explicit, user-provided information for the git provenance of the
// melange build definition. As a fallback, detect this from local git state.
// Git auto-detection should be "best effort" and not fail the build if it
// fails.
if configFileGitCommit == "" || configFileGitRepoURL == "" {
gs, err := detectGitState(ctx)
if err != nil {
return fmt.Errorf("detecting git state: %w", err)
}

if configFileGitCommit == "" {
configFileGitCommit = gs.commit
}
if configFileGitRepoURL == "" {
// To form e.g. "github.com/wolfi-dev/os"
configFileGitRepoURL = fmt.Sprintf("https://%s/%s/%s", gs.repoHost, gs.repoPathParent, gs.repoName)
log.Warnf("failed to auto-detect git information: %v", err)
} else {
if configFileGitCommit == "" {
configFileGitCommit = gs.commit
}
if configFileGitRepoURL == "" {
// To form e.g. "github.com/wolfi-dev/os"
configFileGitRepoURL = fmt.Sprintf("https://%s/%s/%s", gs.repoHost, gs.repoPathParent, gs.repoName)
}
}
}

Expand Down

0 comments on commit d87a8e1

Please sign in to comment.