Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 15 additions & 1 deletion __snapshots__/version-go.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports['version.go updateContent updates version in version.go 1'] = `
exports['basic-update'] = `
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,3 +17,17 @@ package api
const Version = "0.59.0"
`

exports['double-digit-patch'] = `
package api
const Version = "0.58.12-rc02"
`

exports['prerelease-dots-dashes'] = `
package api
const Version = "0.58.0-rc.2"
`
2 changes: 1 addition & 1 deletion src/updaters/go/version-go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {DefaultUpdater} from '../default';
export class VersionGo extends DefaultUpdater {
updateContent(content: string): string {
return content.replace(
/const Version = "[0-9]+\.[0-9]+\.[0-9](-\w+)?"/,
/const Version = "[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-.]+)??"/,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the second question mark at the end required?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the ??.

Also, the suffix is would allow values like 0.58.0-rc..1, which maybe is just fine as we have some level of trust? If that is the case though maybe just make it even more permissive of a grouping for the suffix, [^"]*. If we truly want detailed regexs we should likely reference the spec: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string (that is a wild regex)

`const Version = "${this.version.toString()}"`
);
}
Expand Down
20 changes: 19 additions & 1 deletion test/updaters/version-go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,25 @@ describe('version.go', () => {
version: Version.parse('0.59.0'),
});
const newContent = version.updateContent(oldContent);
snapshot(newContent);
snapshot('basic-update', newContent);
});

it('updates prerelease version with dots and dashes in version.go', async () => {
const oldContent = 'package api\n\nconst Version = "0.58.0-rc.1"\n';
const version = new VersionGo({
version: Version.parse('0.58.0-rc.2'),
});
const newContent = version.updateContent(oldContent);
snapshot('prerelease-dots-dashes', newContent);
});

it('updates double digit patch versions in version.go', async () => {
const oldContent = 'package api\n\nconst Version = "0.58.12-rc01"\n';
const version = new VersionGo({
version: Version.parse('0.58.12-rc02'),
});
const newContent = version.updateContent(oldContent);
snapshot('double-digit-patch', newContent);
});
});
});
Loading