Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get download URL from versions.json #24

Merged
merged 14 commits into from
Nov 8, 2020
4,827 changes: 4,827 additions & 0 deletions __tests__/fixtures/versions.json

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// The testing setup has been derived from the actions/setup-go@bc6edb5 action.
// Check README.md for licence information.

import * as path from 'path'

import * as io from '@actions/io'

import nock = require('nock')
import * as semver from 'semver'

const testVersions = [
'0.1.2', '0.2.0', '0.2.1', '0.3.0',
'0.3.1', '0.3.10', '0.3.11', '0.3.12',
'0.3.2', '0.3.3', '0.3.4', '0.3.5',
'0.3.6', '0.3.7', '0.3.8', '0.3.9',
'0.4.0', '0.4.0-rc1', '0.4.0-rc2', '0.4.0-rc3',
'0.4.0-rc4', '0.4.1', '0.4.2', '0.4.3',
'0.4.4', '0.4.5', '0.4.6', '0.4.7',
'0.5.0', '0.5.0-rc0', '0.5.0-rc1', '0.5.0-rc2',
'0.5.0-rc3', '0.5.0-rc4', '0.5.1', '0.5.2',
'0.6.0', '0.6.0-pre.alpha', '0.6.0-pre.beta', '0.6.0-rc1',
'0.6.0-rc2', '0.6.0-rc3', '0.6.1', '0.6.2',
'0.6.3', '0.6.4', '0.7.0', '0.7.0-alpha',
'0.7.0-beta', '0.7.0-beta2', '0.7.0-rc1', '0.7.0-rc2',
'0.7.0-rc3', '1.0.0', '1.0.0-rc1', '1.0.1',
'1.0.2', '1.0.3', '1.0.4', '1.0.5',
'1.1.0', '1.1.0-rc1', '1.1.0-rc2', '1.1.1',
'1.2.0', '1.2.0-rc1', '1.2.0-rc2', '1.2.0-rc3',
'1.3.0-alpha', '1.3.0-rc1', '1.3.0-rc2', '1.3.0-rc3',
'1.3.0-rc4'
]

const toolDir = path.join(__dirname, 'runner', 'tools')
const tempDir = path.join(__dirname, 'runner', 'temp')
const fixtureDir = path.join(__dirname, 'fixtures')

process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir;

import * as installer from '../src/installer'

describe('version matching tests', () => {
describe('specific versions', () => {
it('Doesn\'t change the version when given a valid semver version', async () => {
expect(await installer.getJuliaVersion([], '1.0.5')).toEqual('1.0.5')
expect(await installer.getJuliaVersion(['v1.0.5', 'v1.0.6'], '1.0.5')).toEqual('1.0.5')
expect(await installer.getJuliaVersion(['v1.0.4', 'v1.0.5'], '1.0.5')).toEqual('1.0.5')
expect(await installer.getJuliaVersion(['v1.0.4'], '1.0.5')).toEqual('1.0.5')
expect(await installer.getJuliaVersion([], '1.3.0-alpha')).toEqual('1.3.0-alpha')
expect(await installer.getJuliaVersion(['v1.2.0', 'v1.3.0-alpha', 'v1.3.0-rc1', 'v1.3.0'], '1.3.0-alpha')).toEqual('1.3.0-alpha')
expect(await installer.getJuliaVersion([], '1.3.0-rc2')).toEqual('1.3.0-rc2')
})

it('Doesn\'t change the version when given `nightly`', async () => {
expect(await installer.getJuliaVersion([], 'nightly')).toEqual('nightly')
expect(await installer.getJuliaVersion(testVersions, 'nightly')).toEqual('nightly')
})
})

describe('version ranges', () => {
it('Chooses the highest available version that matches the input', async () => {
expect(await installer.getJuliaVersion(testVersions, '1')).toEqual('1.2.0')
expect(await installer.getJuliaVersion(testVersions, '1.0')).toEqual('1.0.5')
expect(await installer.getJuliaVersion(testVersions, '^1.3.0-rc1')).toEqual('1.3.0-rc4')
expect(await installer.getJuliaVersion(testVersions, '^1.2.0-rc1')).toEqual('1.2.0')
})
})

describe('node-semver behaviour', () => {
describe('Windows installer change', () => {
it('Correctly understands >1.4.0', () => {
expect(semver.gtr('1.4.0-rc1', '1.3', {includePrerelease: true})).toBeTruthy()
expect(semver.gtr('1.4.0-DEV', '1.3', {includePrerelease: true})).toBeTruthy()
expect(semver.gtr('1.3.1', '1.3', {includePrerelease: true})).toBeFalsy()
expect(semver.gtr('1.3.2-rc1', '1.3', {includePrerelease: true})).toBeFalsy()
})
})
})
})

describe('installer tests', () => {
beforeAll(async () => {
await io.rmRF(toolDir)
await io.rmRF(tempDir)
}, 100000)

afterAll(async () => {
try {
await io.rmRF(toolDir)
await io.rmRF(tempDir)
} catch {
console.log('Failed to remove test directories')
}
}, 100000)

describe('versions.json parsing', () => {
// Instead of downloading versions.json, use fixtures/versions.json
beforeEach(() => {
nock('https://julialang-s3.julialang.org')
.get('/bin/versions.json')
.replyWithFile(200, path.join(fixtureDir, 'versions.json'))
})

afterEach(() => {
nock.cleanAll()
nock.enableNetConnect()
})

it('Extracts the list of available versions', async () => {
expect(await (await installer.getJuliaVersions(await installer.getJuliaVersionInfo())).sort()).toEqual(testVersions.sort())
})
})
})
101 changes: 56 additions & 45 deletions lib/installer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions lib/setup-julia.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@zeit/ncc": "^0.22.0",
"jest": "^24.8.0",
"jest-circus": "^24.7.1",
"nock": "^11.7.2",
"prettier": "^1.17.1",
"ts-jest": "^26.0.0",
"typescript": "^3.5.1"
Expand Down
Loading