Skip to content

Commit

Permalink
Merge pull request #975 from rawlingsj/bump_single_node
Browse files Browse the repository at this point in the history
melange bump: only update expected commit shas for the main git-checkout
  • Loading branch information
luhring authored Feb 2, 2024
2 parents ec7c71b + b1fa180 commit 9e4bb5b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/renovate/bump/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"strconv"
"strings"

"github.com/chainguard-dev/clog"
"github.com/dprotaso/go-yit"
Expand Down Expand Up @@ -211,6 +212,17 @@ func updateGitCheckout(ctx context.Context, node *yaml.Node, expectedGitSha stri
return err
}

// If the tag does not contain a version substitution then we assume it is not the main checkout so we skip updating the expected-commit sha.
tag, err := renovate.NodeFromMapping(withNode, "tag")
if err != nil {
log.Infof("git-checkout node does not contain a tag, assume we need to update the expected-commit sha")
} else {
if !strings.Contains(tag.Value, "${{package.version}}") {
log.Infof("Skipping git-checkout node as it does not contain a version substitution so assuming it is not the main checkout")
return nil
}
}

log.Infof("processing git-checkout node")

if expectedGitSha != "" {
Expand Down
31 changes: 31 additions & 0 deletions pkg/renovate/bump/bump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ func TestBump_withExpectedCommit(t *testing.T) {
})
}
}

func TestBump_withMultipleCheckouts(t *testing.T) {
dir := t.TempDir()
filename := "multiple_checkouts.yaml"

data, err := os.ReadFile(filepath.Join("testdata", filename))
assert.NoError(t, err)

// write the modified melange config to our working temp folder
err = os.WriteFile(filepath.Join(dir, filename), data, 0755)
assert.NoError(t, err)

rctx, err := renovate.New(renovate.WithConfig(filepath.Join(dir, filename)))
assert.NoError(t, err)

ctx := context.Background()

bumpRenovator := New(ctx,
WithTargetVersion("6.8"),
WithExpectedCommit("1234abcd"),
)

err = rctx.Renovate(context.Background(), bumpRenovator)
assert.NoError(t, err)

rs, err := config.ParseConfiguration(ctx, filepath.Join(dir, filename))
require.NoError(t, err)
assert.Equal(t, rs.Pipeline[0].With["expected-commit"], "1234abcd")
assert.Equal(t, rs.Pipeline[1].With["expected-commit"], "bar")
}

func setupTestServer(t *testing.T) (error, *httptest.Server) {
packageData, err := os.ReadFile(filepath.Join("testdata", "cheese-7.0.1.tar.gz"))
assert.NoError(t, err)
Expand Down
17 changes: 17 additions & 0 deletions pkg/renovate/bump/testdata/multiple_checkouts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package:
name: cheese
version: 6.8
epoch: 2
description: "a cheesy library"

pipeline:
- uses: git-checkout
with:
repository: cheese/crisps
expected-commit: foo
tag: v${{package.version}}
- uses: git-checkout
with:
repository: cheese/cheese
expected-commit: bar
tag: crackers

0 comments on commit 9e4bb5b

Please sign in to comment.