Skip to content

Commit 23e3f52

Browse files
Gudahttdarkwing
andauthored
Update version parsing to allow rollback release (#14288)
* Update version parsing to allow rollback release When we want to rollback a release on Chrome, sometimes we use the fourth part of the version for the rollback release. This is because the Chrome web stores does not directly allow rolling back, but instead requires us to re-submit the release we want to roll back to with a higher version number. The manifest version parsing now allows for a fourth version part. The comments have also been updated to be more descriptive, and to fix a minor inaccuracy. * Fix typo in comment Co-authored-by: David Walsh <davidwalsh83@gmail.com> Co-authored-by: David Walsh <davidwalsh83@gmail.com>
1 parent 6bf87b8 commit 23e3f52

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

app/scripts/platforms/extension.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,17 @@ export default class ExtensionPlatform {
9090
if (versionParts.length < 4) {
9191
throw new Error(`Version missing build number: '${version}'`);
9292
}
93-
// On Chrome, a more descriptive representation of the version is stored
94-
// in the `version_name` field for display purposes.
93+
// On Chrome, a more descriptive representation of the version is stored in the
94+
// `version_name` field for display purposes. We use this field instead of the `version`
95+
// field on Chrome for non-main builds (i.e. Flask, Beta) because we want to show the
96+
// version in the SemVer-compliant format "v[major].[minor].[patch]-[build-type].[build-number]",
97+
// yet Chrome does not allow letters in the `version` field.
9598
return versionName;
96-
} else if (versionParts.length !== 3) {
99+
// A fourth version part is sometimes present for "rollback" Chrome builds
100+
} else if (![3, 4].includes(versionParts.length)) {
97101
throw new Error(`Invalid version: ${version}`);
98102
} else if (versionParts[2].match(/[^\d]/u)) {
99-
// On Firefox, the build type and build version are in the fourth part of the version.
103+
// On Firefox, the build type and build version are in the third part of the version.
100104
const [major, minor, patchAndPrerelease] = versionParts;
101105
const matches = patchAndPrerelease.match(/^(\d+)([A-Za-z]+)(\d)+$/u);
102106
if (matches === null) {
@@ -106,7 +110,7 @@ export default class ExtensionPlatform {
106110
return `${major}.${minor}.${patch}-${buildType}.${buildVersion}`;
107111
}
108112

109-
// If there is no `version_name` and there are only 3 version parts, then this is not a
113+
// If there is no `version_name` and there are only 3 or 4 version parts, then this is not a
110114
// prerelease and the version requires no modification.
111115
return version;
112116
}

app/scripts/platforms/extension.test.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ describe('extension platform', () => {
2525
expect(version).toBe('1.2.3');
2626
});
2727

28+
it('should return rollback version', () => {
29+
browser.runtime.getManifest.mockReturnValue({ version: '1.2.3.1' });
30+
const extensionPlatform = new ExtensionPlatform();
31+
32+
const version = extensionPlatform.getVersion();
33+
34+
expect(version).toBe('1.2.3.1');
35+
});
36+
2837
it('should return SemVer-formatted version for Chrome style manifest of prerelease', () => {
2938
browser.runtime.getManifest.mockReturnValue({
3039
version: '1.2.3.0',
@@ -60,24 +69,6 @@ describe('extension platform', () => {
6069
);
6170
});
6271

63-
it('should throw error if version name is missing from Chrome style prerelease manifest', () => {
64-
browser.runtime.getManifest.mockReturnValue({
65-
version: '1.2.3.0',
66-
});
67-
const extensionPlatform = new ExtensionPlatform();
68-
69-
expect(() => extensionPlatform.getVersion()).toThrow('Invalid version:');
70-
});
71-
72-
it('should throw error if version includes four parts in a Firefox style manifest', () => {
73-
browser.runtime.getManifest.mockReturnValue({
74-
version: '1.2.3.4',
75-
});
76-
const extensionPlatform = new ExtensionPlatform();
77-
78-
expect(() => extensionPlatform.getVersion()).toThrow('Invalid version:');
79-
});
80-
8172
it('should throw error if build version is missing from Firefox style prerelease manifest', () => {
8273
browser.runtime.getManifest.mockReturnValue({
8374
version: '1.2.3beta',

0 commit comments

Comments
 (0)