Skip to content

Commit

Permalink
fix: fix installing go 1.18
Browse files Browse the repository at this point in the history
go 1.18 reports its version as 1.18 and NOT as 1.18.0, which would fail the version check

fixes: #174
  • Loading branch information
josa42 committed Mar 27, 2022
1 parent 07aa840 commit 0f3ccc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/utils/versions.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import assert from 'assert'
import { compareVersions, isValidVersion, parseVersion, version } from './versions'

const v0: version = [0, 0, 0]
const v1: version = [1, 0, 0]
const v1_2: version = [1, 2, 0]
const v0_0_0: version = [0, 0, 0]
const v1_0_0: version = [1, 0, 0]
const v1_2_0: version = [1, 2, 0]
const v1_2_3: version = [1, 2, 3]

describe('isValidVersion()', () => {
Expand All @@ -19,16 +19,17 @@ describe('isValidVersion()', () => {
it('should recognise invalid versions', () => {
assert.ok(!isValidVersion('v 1.0.0'))
assert.ok(!isValidVersion('1'))
assert.ok(!isValidVersion('1.1'))
assert.ok(isValidVersion('1.1'))
})

})

describe("parseVersion()", () => {
it("should parse simple versions", () => {
assert.deepStrictEqual(parseVersion('v0.0.0'), v0)
assert.deepStrictEqual(parseVersion('v1.0.0'), v1)
assert.deepStrictEqual(parseVersion('v1.2.0'), v1_2)
assert.deepStrictEqual(parseVersion('v0.0.0'), v0_0_0)
assert.deepStrictEqual(parseVersion('v1.0.0'), v1_0_0)
assert.deepStrictEqual(parseVersion('v1.2.0'), v1_2_0)
assert.deepStrictEqual(parseVersion('v1.2'), v1_2_0)
assert.deepStrictEqual(parseVersion('v1.2.3'), v1_2_3)
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type version = [
number,
]

const versionExp = /^v?(\d+)\.(\d+).(\d+)$/
const versionExp = /^v?(\d+)\.(\d+)(\.(\d+))?$/

export function isValidVersion(version: string): boolean {
return Boolean(version.trim().match(versionExp))
Expand All @@ -30,7 +30,7 @@ export function parseVersion(v: string): version {
const match = v.trim().match(versionExp)

if (match) {
const [, major, minor, patch] = match
const [, major, minor,, patch = '0'] = match
ver = [parseInt(major), parseInt(minor), parseInt(patch)]
}

Expand Down

0 comments on commit 0f3ccc3

Please sign in to comment.