Skip to content

Commit 23cddad

Browse files
committed
fix: fix an issue with release please not updating full version of go dependency
Signed-off-by: Jonas Kalderstam <[email protected]>
1 parent e83e833 commit 23cddad

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

__snapshots__/go-mod.js

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
exports['go.mod updateContent updates a commit dependency 1'] = `
2+
module example.com/hello/world
3+
4+
go 1.23.0
5+
6+
replace example.com/foo/bar/v2 => ../../foo/bar
7+
8+
require (
9+
\texample.com/foo/bar/v2 v2.1.0
10+
\texample.com/foo/baz v1.2.3
11+
\texample.com/car/dar v0.1.2 // indirect
12+
)
13+
14+
`
15+
116
exports['go.mod updateContent updates dependencies 1'] = `
217
module example.com/hello/world
318
@@ -8,6 +23,7 @@ replace example.com/foo/bar/v2 => ../../foo/bar
823
require (
924
\texample.com/foo/bar/v2 v2.1.3
1025
\texample.com/foo/baz v1.2.3
26+
\texample.com/car/dar v0.1.1-0.20250203122516-4c838e530ecb // indirect
1127
)
1228
1329
`

src/updaters/go/go-mod.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export class GoMod extends DefaultUpdater {
3232
}
3333

3434
for (const [pkgName, pkgVersion] of this.versionsMap) {
35-
const regex = new RegExp(`${pkgName} v\\d+\\.\\d+\\.\\d+`, 'g');
35+
// Easy version is v1.2.3
36+
// But if depending on a commit it could be v0.1.1-0.20250203122516-4c838e530ecb
37+
const regex = new RegExp(`${pkgName} v\\d+\\.\\d+\\.\\d+[^\\s]*`, 'g');
3638
// Is the dep in the go.mod file?
3739
const deps = regex.exec(payload);
3840

src/updaters/go/version-go.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {DefaultUpdater} from '../default';
1717
export class VersionGo extends DefaultUpdater {
1818
updateContent(content: string): string {
1919
return content.replace(
20-
/const Version = "[0-9]+\.[0-9]+\.[0-9](-\w+)?"/,
20+
/const Version = "\d+\.\d+\.\d[^\s]*"/,
2121
`const Version = "${this.version.toString()}"`
2222
);
2323
}

test/updaters/fixtures/go/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ replace example.com/foo/bar/v2 => ../../foo/bar
77
require (
88
example.com/foo/bar/v2 v2.1.0
99
example.com/foo/baz v1.2.3
10+
example.com/car/dar v0.1.1-0.20250203122516-4c838e530ecb // indirect
1011
)

test/updaters/go-mod.ts

+16
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,21 @@ describe('go.mod', () => {
5555
const newContent = updater.updateContent(oldContent);
5656
snapshot(newContent);
5757
});
58+
it('updates a commit dependency', async () => {
59+
const oldContent = readFileSync(
60+
resolve(fixturesPath, './go.mod'),
61+
'utf8'
62+
).replace(/\r\n/g, '\n');
63+
const updatedVersions = new Map();
64+
updatedVersions.set('example.com/car/dar', Version.parse('v0.1.2'));
65+
66+
const updater = new GoMod({
67+
version: Version.parse('v2.3.4'),
68+
versionsMap: updatedVersions,
69+
});
70+
const newContent = updater.updateContent(oldContent);
71+
snapshot(newContent);
72+
expect(newContent).to.include('example.com/car/dar v0.1.2 // indirect');
73+
});
5874
});
5975
});

0 commit comments

Comments
 (0)