|
1 | | -import * as core from '@actions/core'; |
2 | | -import * as tc from '@actions/tool-cache'; |
3 | | -import * as exec from '@actions/exec'; |
4 | | -import { downloadTool } from './utils'; |
5 | | -import { join as joinPaths } from 'path'; |
| 1 | +import { MsiInstaller, Urls } from './installers'; |
6 | 2 |
|
7 | | -const x64_URL = 'https://download.microsoft.com/download/B/E/D/BED73AAC-3C8A-43F5-AF4F-EB4FEA6C8F3A/ENU/x64/sqlncli.msi'; |
8 | | -const x86_URL = 'https://download.microsoft.com/download/B/E/D/BED73AAC-3C8A-43F5-AF4F-EB4FEA6C8F3A/ENU/x86/sqlncli.msi'; |
9 | | - |
10 | | -export default async function installNativeClient(version: number) { |
11 | | - if (version !== 11) { |
12 | | - throw new Error('Unsupported Native Client version, only 11 is valid.'); |
13 | | - } |
14 | | - const arch = process.arch === 'x64' ? 'x64' : 'x86'; |
15 | | - let path = tc.find('sqlncli', '11.0', arch); |
16 | | - if (!path) { |
17 | | - core.info(`Downloading client installer for ${arch}.`); |
18 | | - path = await downloadTool(arch === 'x64' ? x64_URL : x86_URL).then((tmp) => { |
19 | | - return tc.cacheFile(tmp, 'sqlncli.msi', 'sqlncli', '11.0', arch); |
20 | | - }); |
21 | | - } else { |
22 | | - core.info('Loaded client installer from cache.'); |
| 3 | +const VERSIONS = new Map<string, Urls>([ |
| 4 | + ['11', { |
| 5 | + x64: 'https://download.microsoft.com/download/B/E/D/BED73AAC-3C8A-43F5-AF4F-EB4FEA6C8F3A/ENU/x64/sqlncli.msi', |
| 6 | + x86: 'https://download.microsoft.com/download/B/E/D/BED73AAC-3C8A-43F5-AF4F-EB4FEA6C8F3A/ENU/x86/sqlncli.msi', |
| 7 | + }], |
| 8 | +]); |
| 9 | +export default async function installNativeClient(version: string) { |
| 10 | + if (!VERSIONS.has(version)) { |
| 11 | + throw new TypeError(`Invalid native client version supplied ${version}. Must be one of ${Array.from(VERSIONS.keys()).join(', ')}.`); |
23 | 12 | } |
24 | | - path = joinPaths(path, 'sqlncli.msi'); |
25 | | - core.info('Installing SQL Native Client 11.0'); |
26 | 13 | // see https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2012/ms131321(v=sql.110) |
27 | | - await exec.exec('msiexec', [ |
28 | | - '/passive', |
29 | | - '/i', |
30 | | - path, |
31 | | - 'APPGUID={0CC618CE-F36A-415E-84B4-FB1BFF6967E1}', |
32 | | - 'IACCEPTSQLNCLILICENSETERMS=YES', |
33 | | - ], { |
34 | | - windowsVerbatimArguments: true, |
| 14 | + const installer = new MsiInstaller({ |
| 15 | + name: 'sqlncli', |
| 16 | + urls: VERSIONS.get(version)!, |
| 17 | + appGuid: '0CC618CE-F36A-415E-84B4-FB1BFF6967E1', |
| 18 | + version, |
| 19 | + extraArgs: [ |
| 20 | + 'IACCEPTSQLNCLILICENSETERMS=YES', |
| 21 | + ], |
35 | 22 | }); |
| 23 | + return installer.install(); |
36 | 24 | } |
0 commit comments