1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

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>
This commit is contained in:
Mark Stacey 2022-05-03 14:18:36 -02:30 committed by GitHub
parent 6bf87b83a6
commit 23e3f52a04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 23 deletions

View File

@ -90,13 +90,17 @@ export default class ExtensionPlatform {
if (versionParts.length < 4) {
throw new Error(`Version missing build number: '${version}'`);
}
// On Chrome, a more descriptive representation of the version is stored
// in the `version_name` field for display purposes.
// On Chrome, a more descriptive representation of the version is stored in the
// `version_name` field for display purposes. We use this field instead of the `version`
// field on Chrome for non-main builds (i.e. Flask, Beta) because we want to show the
// version in the SemVer-compliant format "v[major].[minor].[patch]-[build-type].[build-number]",
// yet Chrome does not allow letters in the `version` field.
return versionName;
} else if (versionParts.length !== 3) {
// A fourth version part is sometimes present for "rollback" Chrome builds
} else if (![3, 4].includes(versionParts.length)) {
throw new Error(`Invalid version: ${version}`);
} else if (versionParts[2].match(/[^\d]/u)) {
// On Firefox, the build type and build version are in the fourth part of the version.
// On Firefox, the build type and build version are in the third part of the version.
const [major, minor, patchAndPrerelease] = versionParts;
const matches = patchAndPrerelease.match(/^(\d+)([A-Za-z]+)(\d)+$/u);
if (matches === null) {
@ -106,7 +110,7 @@ export default class ExtensionPlatform {
return `${major}.${minor}.${patch}-${buildType}.${buildVersion}`;
}
// If there is no `version_name` and there are only 3 version parts, then this is not a
// If there is no `version_name` and there are only 3 or 4 version parts, then this is not a
// prerelease and the version requires no modification.
return version;
}

View File

@ -25,6 +25,15 @@ describe('extension platform', () => {
expect(version).toBe('1.2.3');
});
it('should return rollback version', () => {
browser.runtime.getManifest.mockReturnValue({ version: '1.2.3.1' });
const extensionPlatform = new ExtensionPlatform();
const version = extensionPlatform.getVersion();
expect(version).toBe('1.2.3.1');
});
it('should return SemVer-formatted version for Chrome style manifest of prerelease', () => {
browser.runtime.getManifest.mockReturnValue({
version: '1.2.3.0',
@ -60,24 +69,6 @@ describe('extension platform', () => {
);
});
it('should throw error if version name is missing from Chrome style prerelease manifest', () => {
browser.runtime.getManifest.mockReturnValue({
version: '1.2.3.0',
});
const extensionPlatform = new ExtensionPlatform();
expect(() => extensionPlatform.getVersion()).toThrow('Invalid version:');
});
it('should throw error if version includes four parts in a Firefox style manifest', () => {
browser.runtime.getManifest.mockReturnValue({
version: '1.2.3.4',
});
const extensionPlatform = new ExtensionPlatform();
expect(() => extensionPlatform.getVersion()).toThrow('Invalid version:');
});
it('should throw error if build version is missing from Firefox style prerelease manifest', () => {
browser.runtime.getManifest.mockReturnValue({
version: '1.2.3beta',