Skip to content

Commit 9902b1d

Browse files
authored
fix(sidekick): bad version bump edits (#2613)
Sometimes we were introducing two version lines in `rust-version-bump`.
1 parent 3331c0b commit 9902b1d

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

internal/sidekick/internal/rust_release/update_sidekick_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func updateSidekickConfig(manifest, newVersion string) error {
4545
var result []string
4646
result = append(result, lines[:iCodec+1]...)
4747
tail := lines[iCodec+1:]
48-
iVersion := slices.IndexFunc(tail, func(a string) bool { return strings.HasPrefix(a, "version = ") })
48+
iVersion := slices.IndexFunc(tail, func(a string) bool { return strings.HasPrefix(a, "version ") && strings.Contains(a, " = ") })
4949
verLine := fmt.Sprintf(`version = '%s'`, newVersion)
5050
if iVersion == -1 {
5151
result = append(result, verLine)

internal/sidekick/internal/rust_release/update_sidekick_config_test.go

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,59 @@ import (
2424
)
2525

2626
func TestUpdateSidekickConfigSuccess(t *testing.T) {
27+
const contentsA = `# With version line
28+
[codec]
29+
a = 123
30+
version = "1.2.3"
31+
copyright-year = '2038'
32+
`
33+
const contentsB = `# With version line
34+
[codec]
35+
a = 123
36+
version = "1.2.3"
37+
copyright-year = '2038'
38+
`
39+
40+
for _, contents := range []string{contentsA, contentsB} {
41+
tmpDir := t.TempDir()
42+
manifest := path.Join(tmpDir, "Cargo.toml")
43+
sidekick := path.Join(tmpDir, ".sidekick.toml")
44+
const want = `# With version line
45+
[codec]
46+
a = 123
47+
version = '2.3.4'
48+
copyright-year = '2038'
49+
`
50+
if err := os.WriteFile(sidekick, []byte(contents), 0644); err != nil {
51+
t.Fatal(err)
52+
}
53+
if err := updateSidekickConfig(manifest, "2.3.4"); err != nil {
54+
t.Fatal(err)
55+
}
56+
got, err := os.ReadFile(sidekick)
57+
if err != nil {
58+
t.Fatal(err)
59+
}
60+
if diff := cmp.Diff(want, string(got)); diff != "" {
61+
t.Errorf("mismatch (-want +got):\n%s", diff)
62+
}
63+
}
64+
}
65+
66+
func TestUpdateSidekickConfigSuccessNoVersion(t *testing.T) {
2767
tmpDir := t.TempDir()
2868
manifest := path.Join(tmpDir, "Cargo.toml")
2969
sidekick := path.Join(tmpDir, ".sidekick.toml")
3070
const contents = `# With version line
3171
[codec]
32-
a = 123
33-
version = "1.2.3"
3472
copyright-year = '2038'
73+
c = 345
3574
`
3675
const want = `# With version line
3776
[codec]
38-
a = 123
3977
version = '2.3.4'
4078
copyright-year = '2038'
79+
c = 345
4180
`
4281
if err := os.WriteFile(sidekick, []byte(contents), 0644); err != nil {
4382
t.Fatal(err)
@@ -54,20 +93,18 @@ copyright-year = '2038'
5493
}
5594
}
5695

57-
func TestUpdateSidekickConfigSuccessNoVersion(t *testing.T) {
96+
func TestUpdateSidekickConfigSuccessEmptyCodec(t *testing.T) {
5897
tmpDir := t.TempDir()
5998
manifest := path.Join(tmpDir, "Cargo.toml")
6099
sidekick := path.Join(tmpDir, ".sidekick.toml")
61100
const contents = `# With version line
101+
62102
[codec]
63-
copyright-year = '2038'
64-
c = 345
65103
`
66104
const want = `# With version line
105+
67106
[codec]
68107
version = '2.3.4'
69-
copyright-year = '2038'
70-
c = 345
71108
`
72109
if err := os.WriteFile(sidekick, []byte(contents), 0644); err != nil {
73110
t.Fatal(err)
@@ -84,13 +121,14 @@ c = 345
84121
}
85122
}
86123

87-
func TestUpdateSidekickConfigSuccessEmptyCodec(t *testing.T) {
124+
func TestUpdateSidekickConfigSuccessOnlyVersion(t *testing.T) {
88125
tmpDir := t.TempDir()
89126
manifest := path.Join(tmpDir, "Cargo.toml")
90127
sidekick := path.Join(tmpDir, ".sidekick.toml")
91128
const contents = `# With version line
92129
93130
[codec]
131+
version = '1.2.3'
94132
`
95133
const want = `# With version line
96134

0 commit comments

Comments
 (0)