-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { MsiInstaller, Urls } from './installers'; | ||
|
||
// https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver16 | ||
const VERSIONS = new Map<string, Urls>([ | ||
['18', { | ||
x64: 'https://go.microsoft.com/fwlink/?linkid=2242886', | ||
x86: 'https://go.microsoft.com/fwlink/?linkid=2242980', | ||
}], | ||
['17', { | ||
x64: 'https://go.microsoft.com/fwlink/?linkid=2239168', | ||
x86: 'https://go.microsoft.com/fwlink/?linkid=2238791', | ||
}], | ||
]); | ||
|
||
export default async function installOdbc(version: string) { | ||
if (!VERSIONS.has(version)) { | ||
throw new TypeError(`Invalid ODBC version supplied ${version}. Must be one of ${Array.from(VERSIONS.keys()).join(', ')}.`); | ||
} | ||
const installer = new MsiInstaller({ | ||
name: 'msodbcsql', | ||
urls: VERSIONS.get(version)!, | ||
version, | ||
extraArgs: [ | ||
'IACCEPTMSODBCSQLLICENSETERMS=YES', | ||
], | ||
}); | ||
return installer.install(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { restore, SinonStubbedInstance, stub } from 'sinon'; | ||
import * as core from '@actions/core'; | ||
import * as tc from '@actions/tool-cache'; | ||
import * as exec from '@actions/exec'; | ||
import * as io from '@actions/io'; | ||
import installOdbc from '../src/install-odbc'; | ||
import { expect, use } from 'chai'; | ||
import sinonChai from 'sinon-chai'; | ||
use(sinonChai); | ||
|
||
describe('install-odbc', () => { | ||
// let coreStub: SinonStubbedInstance<typeof core>; | ||
let tcStub: SinonStubbedInstance<typeof tc>; | ||
let execStub: SinonStubbedInstance<typeof exec>; | ||
let ioStub: SinonStubbedInstance<typeof io>; | ||
let arch: PropertyDescriptor; | ||
beforeEach('stub deps', () => { | ||
stub(core); | ||
arch = Object.getOwnPropertyDescriptor(process, 'arch')!; | ||
tcStub = stub(tc); | ||
tcStub.find.returns(''); | ||
execStub = stub(exec); | ||
execStub.exec.resolves(); | ||
ioStub = stub(io); | ||
ioStub.mv.resolves(); | ||
}); | ||
afterEach('restore stubs', () => { | ||
Object.defineProperty(process, 'arch', arch); | ||
restore(); | ||
}); | ||
describe('.installOdbc()', () => { | ||
it('throws for bad version', async () => { | ||
try { | ||
await installOdbc('10'); | ||
} catch (e) { | ||
expect(e).to.have.property('message', 'Invalid ODBC version supplied 10. Must be one of 18, 17.'); | ||
return; | ||
} | ||
expect.fail('expected to throw'); | ||
}); | ||
it('installs from cache', async () => { | ||
tcStub.find.returns('C:/tmp/'); | ||
await installOdbc('18'); | ||
expect(tcStub.downloadTool).to.have.callCount(0); | ||
expect(execStub.exec).to.have.been.calledOnceWith('msiexec', [ | ||
'/passive', | ||
'/i', | ||
'C:/tmp/msodbcsql.msi', | ||
'IACCEPTMSODBCSQLLICENSETERMS=YES', | ||
], { | ||
windowsVerbatimArguments: true, | ||
}); | ||
}); | ||
it('installs from web (x64)', async () => { | ||
Object.defineProperty(process, 'arch', { | ||
value: 'x64', | ||
}); | ||
tcStub.cacheFile.resolves('C:/tmp/cache/'); | ||
tcStub.downloadTool.resolves('C:/tmp/downloads'); | ||
await installOdbc('17'); | ||
expect(tcStub.downloadTool).to.have.been.calledOnceWith('https://go.microsoft.com/fwlink/?linkid=2239168'); | ||
expect(tcStub.cacheFile).to.have.callCount(1); | ||
expect(execStub.exec).to.have.been.calledOnceWith('msiexec', [ | ||
'/passive', | ||
'/i', | ||
'C:/tmp/cache/msodbcsql.msi', | ||
'IACCEPTMSODBCSQLLICENSETERMS=YES', | ||
], { | ||
windowsVerbatimArguments: true, | ||
}); | ||
}); | ||
it('installs from web (x32)', async () => { | ||
Object.defineProperty(process, 'arch', { | ||
value: 'x32', | ||
}); | ||
tcStub.cacheFile.resolves('C:/tmp/cache/'); | ||
tcStub.downloadTool.resolves('C:/tmp/downloads'); | ||
await installOdbc('17'); | ||
expect(tcStub.downloadTool).to.have.been.calledOnceWith('https://go.microsoft.com/fwlink/?linkid=2238791'); | ||
expect(tcStub.cacheFile).to.have.callCount(1); | ||
expect(execStub.exec).to.have.been.calledOnceWith('msiexec', [ | ||
'/passive', | ||
'/i', | ||
'C:/tmp/cache/msodbcsql.msi', | ||
'IACCEPTMSODBCSQLLICENSETERMS=YES', | ||
], { | ||
windowsVerbatimArguments: true, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters