|
1 | 1 | import * as core from '@actions/core' |
2 | 2 | import * as tc from '@actions/tool-cache' |
3 | 3 |
|
| 4 | +function downloadUrl(version: string): string { |
| 5 | + let plat = '' |
| 6 | + let arch = '' |
| 7 | + |
| 8 | + switch (process.platform) { |
| 9 | + case 'win32': { |
| 10 | + plat = 'windows' |
| 11 | + break |
| 12 | + } |
| 13 | + case 'darwin': { |
| 14 | + plat = 'darwin' |
| 15 | + break |
| 16 | + } |
| 17 | + case 'linux': { |
| 18 | + plat = 'linux' |
| 19 | + break |
| 20 | + } |
| 21 | + default: { |
| 22 | + core.setFailed(`Unsupported platform: ${process.platform}`) |
| 23 | + return '' |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + switch (process.arch) { |
| 28 | + case 'x64': { |
| 29 | + arch = 'amd64' |
| 30 | + break |
| 31 | + } |
| 32 | + case 'arm64': { |
| 33 | + arch = 'arm64' |
| 34 | + break |
| 35 | + } |
| 36 | + default: { |
| 37 | + core.setFailed(`Unsupported architecture: ${process.arch}`) |
| 38 | + return '' |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + return `https://downloads.sqlc.dev/sqlc_${version}_${plat}_${arch}.zip` |
| 43 | +} |
| 44 | + |
4 | 45 | async function run(): Promise<void> { |
5 | 46 | try { |
6 | 47 | const version = core.getInput('sqlc-version') |
7 | 48 | if (!version) { |
8 | 49 | core.setFailed(`sqlc-version not set`) |
9 | 50 | return |
10 | 51 | } |
11 | | - const toolDir = tc.find('sqlc', version, 'x64') |
| 52 | + const toolDir = tc.find('sqlc', version, process.arch) |
12 | 53 | if (toolDir !== '') { |
13 | 54 | core.addPath(toolDir) |
14 | 55 | return |
15 | 56 | } |
16 | 57 |
|
17 | | - switch (process.platform) { |
18 | | - case 'win32': { |
19 | | - const toolUrl = `https://downloads.sqlc.dev/sqlc_${version}_windows_amd64.zip` |
20 | | - const downloadPath = await tc.downloadTool(toolUrl) |
21 | | - const extPath = await tc.extractZip(downloadPath) |
22 | | - const cachedPath = await tc.cacheDir(extPath, 'sqlc', version) |
23 | | - core.addPath(cachedPath) |
24 | | - break |
25 | | - } |
26 | | - |
27 | | - case 'darwin': { |
28 | | - const toolUrl = `https://downloads.sqlc.dev/sqlc_${version}_darwin_amd64.zip` |
29 | | - const downloadPath = await tc.downloadTool(toolUrl) |
30 | | - const extPath = await tc.extractZip(downloadPath) |
31 | | - const cachedPath = await tc.cacheDir(extPath, 'sqlc', version) |
32 | | - core.addPath(cachedPath) |
33 | | - break |
34 | | - } |
35 | | - |
36 | | - case 'linux': { |
37 | | - const toolUrl = `https://downloads.sqlc.dev/sqlc_${version}_linux_amd64.zip` |
38 | | - const downloadPath = await tc.downloadTool(toolUrl) |
39 | | - const extPath = await tc.extractZip(downloadPath) |
40 | | - const cachedPath = await tc.cacheDir(extPath, 'sqlc', version) |
41 | | - core.addPath(cachedPath) |
42 | | - break |
43 | | - } |
44 | | - |
45 | | - default: { |
46 | | - core.setFailed(`Unsupported platform: ${process.platform}`) |
47 | | - } |
| 58 | + const toolUrl = downloadUrl(version) |
| 59 | + if (toolUrl === '') { |
| 60 | + return |
48 | 61 | } |
| 62 | + |
| 63 | + const downloadPath = await tc.downloadTool(toolUrl) |
| 64 | + const extPath = await tc.extractZip(downloadPath) |
| 65 | + const cachedPath = await tc.cacheDir(extPath, 'sqlc', version) |
| 66 | + core.addPath(cachedPath) |
49 | 67 | } catch (error) { |
50 | 68 | if (error instanceof Error) core.setFailed(error.message) |
51 | 69 | } |
|
0 commit comments