Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Fix upgrade not showing when an RC is deployed (#513)
Browse files Browse the repository at this point in the history
* Fix upgrade not showing when an RC is deployed

* Fix lint

* Lint fix

* Move test file

* Update helm-release-helper.service.spec.ts

* Update helm-release-helper.service.ts
  • Loading branch information
nwmac committed Oct 5, 2020
1 parent a9d8639 commit 41737ca
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Version } from './helm-release-helper.service';

describe('HelmReleaseHelperService', () => {

describe('Version', () => {

const v10 = new Version('1.0.0');
const v11 = new Version('1.1.0');
const v11rc1 = new Version('1.0.0-rc.1');
const v11rc2 = new Version('1.0.0-rc.2');
const v201 = new Version('2.0.1');
const v101 = new Version('1.0.1');

it('version comparisons', () => {
expect(v11.isNewer(v10)).toBe(true);
expect(v11rc1.isNewer(v11)).toBe(false);
expect(v11rc2.isNewer(v11rc1)).toBe(true);
expect(v201.isNewer(v11)).toBe(true);
expect(v201.isNewer(v11rc1)).toBe(true);
expect(v10.isNewer(v11)).toBe(false);
expect(v101.isNewer(v11)).toBe(false);
expect(v101.isNewer(v10)).toBe(true);

expect(v11rc1.isNewer(v10)).toBe(false);

});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,26 @@ import {
import { workloadsEntityCatalog } from '../../workloads-entity-catalog';

// Simple class to represent MAJOR.MINOR.REVISION version
class Version {
export class Version {

public major: number;
public minor: number;
public revision: number;

public prerelease: string;

public valid: boolean;

constructor(v: string) {
this.valid = false;
if (typeof v === 'string') {
const parts = v.split('.');
let version = v;
const pre = v.split('-');
if (pre.length > 1) {
version = pre[0];
this.prerelease = pre[1];
}
const parts = version.split('.');
if (parts.length === 3) {
this.major = parseInt(parts[0], 10);
this.minor = parseInt(parts[1], 10);
Expand All @@ -55,6 +63,19 @@ class Version {
return true;
}
if (this.minor === other.minor) {
if (this.revision === other.revision) {
// Same version numbers
if (this.prerelease && !other.prerelease) {
return false;
}
if(!this.prerelease && other.prerelease) {
return true;
}
if (this.prerelease && other.prerelease) {
return this.prerelease > other.prerelease;
}
return false;
}
return this.revision > other.revision;
}
}
Expand Down

0 comments on commit 41737ca

Please sign in to comment.