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

ci(dagger): trim new lines from git info #250

Merged
merged 1 commit into from
Jul 22, 2024
Merged
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
26 changes: 24 additions & 2 deletions build/ci/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func (g *Git) GetLastCommitShortSHA(ctx context.Context) (string, error) {
if err != nil {
return "", err
}

// Remove potential new line
res = strings.TrimSuffix(res, "\n")

// Set the cache value
g.lastCommit.shortSHA = res

return g.lastCommit.shortSHA, nil
Expand All @@ -67,6 +72,11 @@ func (g *Git) GetActualBranch(ctx context.Context) (string, error) {
if err != nil {
return "", err
}

// Remove potential new line
res = strings.TrimSuffix(res, "\n")

// Set the cache value
g.actualBranch = res

return g.actualBranch, nil
Expand All @@ -84,6 +94,11 @@ func (g *Git) GetLastCommitTitle(ctx context.Context) (string, error) {
if err != nil {
return "", err
}

// Remove potential new line
res = strings.TrimSuffix(res, "\n")

// Set the cache value
g.lastCommit.title = res

return g.lastCommit.title, nil
Expand All @@ -101,6 +116,11 @@ func (g *Git) GetLastTag(ctx context.Context) (string, error) {
if err != nil {
return "", err
}

// Remove potential new line
res = strings.TrimSuffix(res, "\n")

// Set the cache value
g.lastTag = res

return g.lastTag, nil
Expand All @@ -115,7 +135,6 @@ func (g *Git) GetLastSemanticVersionedTag(ctx context.Context) (major, minor, pa

// Remove wrong characters
tag = strings.TrimPrefix(tag, "v")
tag = strings.TrimSuffix(tag, "\n")

// Split tag into parts
parts := strings.Split(tag, ".")
Expand Down Expand Up @@ -173,7 +192,10 @@ func (g *Git) GetNewSemVerIfNeeded(ctx context.Context) (string, error) {
return "", nil
}

return fmt.Sprintf("v%d.%d.%d", major, minor, patch), nil
// Set the new semver cached value
g.newSemVer = fmt.Sprintf("v%d.%d.%d", major, minor, patch)

return g.newSemVer, nil
}

func (g *Git) PushNewSemVerIfNeeded(ctx context.Context) error {
Expand Down