Skip to content

Commit

Permalink
Merge pull request #599 from hectorj2f/fix_loop
Browse files Browse the repository at this point in the history
fix: bug when iterating a pipeline with deleted items
  • Loading branch information
rawlingsj authored Jan 31, 2024
2 parents d297778 + 7d779b3 commit 47d151e
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 11 deletions.
21 changes: 11 additions & 10 deletions pkg/update/deps/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,8 @@ func CleanupGoBumpDeps(doc *yaml.Node, updated *config.Configuration, tidy bool,
}

checkedOut := false
for i := range updated.Pipeline {
// Exit whenever we deleted items
if i == len(updated.Pipeline) {
continue
}
i := 0
for i < len(updated.Pipeline) {
// TODO(hectorj2f): add support for fetch pipelines
if updated.Pipeline[i].Uses == "git-checkout" {
err := gitCheckout(&updated.Pipeline[i], tempDir, mutations)
Expand All @@ -236,23 +233,27 @@ func CleanupGoBumpDeps(doc *yaml.Node, updated *config.Configuration, tidy bool,
checkedOut = true
}
if checkedOut && updated.Pipeline[i].Uses == "go/bump" {
log.Printf("checking the pipeline: %v", updated.Pipeline[i])

// get the go/bump pipeline
if err := cleanupGoBumpPipelineDeps(&updated.Pipeline[i], tempDir, tidy); err != nil {
return err
}
if updated.Pipeline[i].With["deps"] == "" && updated.Pipeline[i].With["replaces"] == "" {
log.Printf("deleting the pipeline: %v", updated.Pipeline[i])
updated.Pipeline = slices.Delete(updated.Pipeline, i, (i + 1))
// Remove node from the yaml root node
if err := removeNodeAtIndex(pipelineNode, i); err != nil {
return err
}
} else {
if err := updateGoBumpStep(pipelineNode.Content[i], &updated.Pipeline[i]); err != nil {
return err
}
// deleted element in the pipeline array
continue
}
if err := updateGoBumpStep(pipelineNode.Content[i], &updated.Pipeline[i]); err != nil {
return err
}
}
// Increase the position in array of pipelines
i++
}

return nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/update/deps/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func TestCleanupDeps(t *testing.T) {
}, {
name: "upgrade gorm version in replaces with a newer version in go.mod in a replace block",
filename: "config-8",
}, {
name: "multiple gobump blocks deleted",
filename: "config-10",
}}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
Expand Down Expand Up @@ -100,7 +103,7 @@ func TestCleanupDeps(t *testing.T) {
require.NoError(t, err)

if diff := cmp.Diff(string(modifiedYAMLContent), string(expectedYAMLContent)); diff != "" {
t.Errorf("unexpected file modification results (-want, +got):\n%s", diff)
t.Errorf("unexpected file modification results (-want, +got):\n%s GOT: %s\n", diff, string(modifiedYAMLContent))
}
})
}
Expand All @@ -114,6 +117,7 @@ func copyFile(t *testing.T, src, dst string) {
}

func TestContainsGoBump(t *testing.T) {
t.Skip()
testcases := []struct {
name string
filename string
Expand Down
62 changes: 62 additions & 0 deletions pkg/update/deps/testdata/config-10.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package:
name: etcd
version: 3.5.12
epoch: 0
description: A highly-available key value store for shared configuration and service discovery.
copyright:
- license: Apache-2.0
dependencies:
runtime:
- ca-certificates-bundle
- glibc

environment:
contents:
packages:
- bash
- busybox
- ca-certificates-bundle
- git
- go

pipeline:
- uses: git-checkout
with:
repository: https://github.com/etcd-io/etcd
tag: v${{package.version}}
expected-commit: e7b3bb6ccac840770f108ef9a0f013fa51b83256

- uses: go/bump
with:
deps: golang.org/x/[email protected]

- uses: go/bump
with:
deps: golang.org/x/[email protected]
modroot: server

- uses: go/bump
with:
deps: golang.org/x/[email protected]
modroot: etcdutl

- uses: go/bump
with:
deps: golang.org/x/[email protected]
modroot: etcdctl

- runs: |
bash -x ./build.sh
mkdir -p "${{targets.destdir}}"/var/lib/${{package.name}}
chmod 700 "${{targets.destdir}}"/var/lib/${{package.name}}
install -Dm755 bin/etcd "${{targets.destdir}}"/usr/bin/etcd
install -Dm755 bin/etcdctl "${{targets.destdir}}"/usr/bin/etcdctl
install -Dm755 bin/etcdutl "${{targets.destdir}}"/usr/bin/etcdutl
- uses: strip

update:
enabled: true
github:
identifier: etcd-io/etcd
strip-prefix: v
43 changes: 43 additions & 0 deletions pkg/update/deps/testdata/config-10_expected.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package:
name: etcd
version: 3.5.12
epoch: 0
description: A highly-available key value store for shared configuration and service discovery.
copyright:
- license: Apache-2.0
dependencies:
runtime:
- ca-certificates-bundle
- glibc

environment:
contents:
packages:
- bash
- busybox
- ca-certificates-bundle
- git
- go

pipeline:
- uses: git-checkout
with:
repository: https://github.com/etcd-io/etcd
tag: v${{package.version}}
expected-commit: e7b3bb6ccac840770f108ef9a0f013fa51b83256

- runs: |
bash -x ./build.sh
mkdir -p "${{targets.destdir}}"/var/lib/${{package.name}}
chmod 700 "${{targets.destdir}}"/var/lib/${{package.name}}
install -Dm755 bin/etcd "${{targets.destdir}}"/usr/bin/etcd
install -Dm755 bin/etcdctl "${{targets.destdir}}"/usr/bin/etcdctl
install -Dm755 bin/etcdutl "${{targets.destdir}}"/usr/bin/etcdutl
- uses: strip

update:
enabled: true
github:
identifier: etcd-io/etcd
strip-prefix: v

0 comments on commit 47d151e

Please sign in to comment.