From 14fc30318175e9aa38fe2bbbff728b4c60451706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A9=BA=E5=B7=B7=E4=B8=80=E4=BA=BA?= <1530688385@qq.com> Date: Sat, 18 May 2024 14:16:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0mac=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +--- __tests__/index.test.ts | 51 ++++++++++++++++++++++++++--------------- dist/index.js | 33 ++++++++++++++++---------- src/lib/dotnet.ts | 16 +++++-------- src/lib/go.ts | 30 +++++++++++++----------- src/lib/node.ts | 29 ++++++++++++----------- 6 files changed, 92 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 773f297..18ee68e 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,7 @@ 1、go 和 dotnet 需要指定具体版本号 -2、因为我没有 mac,所以没有 mac 环境 - -3、如果你想让 go 和 dotnet 支持版本号别名,欢迎 [pr](https://github.com/kongxiangyiren/version-alias) +2、如果你想让 go 和 dotnet 支持版本号别名,欢迎 [pr](https://github.com/kongxiangyiren/version-alias) ## Usage diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index ba74593..10fdb47 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -47,20 +47,20 @@ describe('gitea-tool-cache', () => { }, 200000); // 测试时需要把别的注释掉 - it('installs windows', async () => { - // rmSync('./cache', { recursive: true, force: true }); - os['platform'] = 'win32'; - os['arch'] = 'x64'; - // node - inputs['node-version'] = '18'; - await nodeInstall(); - // // go - // inputs['go-version'] = '1.21.1'; - // await goInstall(); - // dotnet - // inputs['dotnet-version'] = '6.0.100'; - // await dotnetInstall(); - }); + // it('installs windows', async () => { + // // rmSync('./cache', { recursive: true, force: true }); + // os['platform'] = 'win32'; + // os['arch'] = 'x64'; + // // node + // inputs['node-version'] = '18'; + // await nodeInstall(); + // // // go + // // inputs['go-version'] = '1.21.1'; + // // await goInstall(); + // // dotnet + // // inputs['dotnet-version'] = '6.0.100'; + // // await dotnetInstall(); + // }); // it('installs linux', async () => { // // rmSync('./cache', { recursive: true, force: true }); @@ -74,14 +74,27 @@ describe('gitea-tool-cache', () => { // await dotnetInstall(); // }); - // it('installs darwin', async () => { + // it('installs darwin x64', async () => { + // // rmSync('./cache', { recursive: true, force: true }); // os['platform'] = 'darwin'; // os['arch'] = 'x64'; - // inputs['node-version'] = '18.18.0'; - // await nodeInstall(); - // inputs['go-version'] = '1.21.1'; - // await goInstall(); + // // inputs['node-version'] = '18.18.0'; + // // await nodeInstall(); + // // inputs['go-version'] = '1.21.1'; + // // await goInstall(); // inputs['dotnet-version'] = '5.0.401'; // await dotnetInstall(); // }); + + it('installs darwin arm64', async () => { + rmSync('./cache', { recursive: true, force: true }); + os['platform'] = 'darwin'; + os['arch'] = 'arm64'; + // inputs['node-version'] = '18.18.0'; + // await nodeInstall(); + // inputs['go-version'] = '1.21.1'; + // await goInstall(); + inputs['dotnet-version'] = '6.0.422'; + await dotnetInstall(); + }); }); diff --git a/dist/index.js b/dist/index.js index 50fbcbd..c93fea2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49507,7 +49507,7 @@ async function dotnetInstall() { return item.rid === 'win-' + (0, os_1.arch)() && item.url.endsWith('.zip'); } else if (platform === 'darwin') { - return item.rid === 'osx-' + (0, os_1.arch)() && item.url.endsWith('.pkg'); + return item.rid === 'osx-' + (0, os_1.arch)() && item.url.endsWith('.tar.gz'); } else { return item.rid === 'linux-' + (0, os_1.arch)() && item.url.endsWith('.tar.gz'); @@ -49527,7 +49527,10 @@ async function dotnetInstall() { (0, core_1.setOutput)('dotnet-path', cachedPath); } else if (platform === 'darwin') { - (0, core_1.info)('没有mac,暂未测试'); + const dotnetExtractedFolder = await (0, tool_cache_1.extractTar)(dotnetPath, './cache/dotnet'); + const cachedPath = await (0, tool_cache_1.cacheDir)(dotnetExtractedFolder, 'dotnet', dotnetVersion); + (0, core_1.addPath)(cachedPath); + (0, core_1.setOutput)('dotnet-path', cachedPath); } else { const dotnetExtractedFolder = await (0, tool_cache_1.extractTar)(dotnetPath, './cache/dotnet'); @@ -49570,21 +49573,26 @@ async function goInstall() { (0, core_1.info)('go已经安装过了'); return; } + const archD = (0, os_1.arch)() === 'x64' ? 'amd64' : (0, os_1.arch)(); try { if (platform === 'win32') { - (0, core_1.info)(`https://golang.google.cn/dl/go${goVersion}.windows-amd64.zip`); - const goPath = await (0, tool_cache_1.downloadTool)(`https://golang.google.cn/dl/go${goVersion}.windows-amd64.zip`); + (0, core_1.info)(`https://golang.google.cn/dl/go${goVersion}.windows-${archD}.zip`); + const goPath = await (0, tool_cache_1.downloadTool)(`https://golang.google.cn/dl/go${goVersion}.windows-${archD}.zip`); (0, fs_1.renameSync)(goPath, goPath + '.zip'); const goExtractedFolder = await (0, tool_cache_1.extractZip)(goPath + '.zip', './cache/go'); const cachedPath = await (0, tool_cache_1.cacheDir)((0, path_1.join)(goExtractedFolder, 'go'), 'go', goVersion); (0, core_1.addPath)(cachedPath); } else if (platform === 'darwin') { - (0, core_1.info)('没有mac,暂未测试'); + (0, core_1.info)(`https://golang.google.cn/dl/go${goVersion}.darwin-${archD}.tar.gz`); + const goPath = await (0, tool_cache_1.downloadTool)(`https://golang.google.cn/dl/go${goVersion}.darwin-${archD}.tar.gz`); + const goExtractedFolder = await (0, tool_cache_1.extractTar)(goPath, './cache/go'); + const cachedPath = await (0, tool_cache_1.cacheDir)((0, path_1.join)(goExtractedFolder, 'go'), 'go', goVersion); + (0, core_1.addPath)(cachedPath); } else { - (0, core_1.info)(`https://golang.google.cn/dl/go${goVersion}.linux-amd64.tar.gz`); - const goPath = await (0, tool_cache_1.downloadTool)(`https://golang.google.cn/dl/go${goVersion}.linux-amd64.tar.gz`); + (0, core_1.info)(`https://golang.google.cn/dl/go${goVersion}.linux-${archD}.tar.gz`); + const goPath = await (0, tool_cache_1.downloadTool)(`https://golang.google.cn/dl/go${goVersion}.linux-${archD}.tar.gz`); const goExtractedFolder = await (0, tool_cache_1.extractTar)(goPath, './cache/go'); const cachedPath = await (0, tool_cache_1.cacheDir)((0, path_1.join)(goExtractedFolder, 'go'), 'go', goVersion); (0, core_1.addPath)(cachedPath); @@ -49671,11 +49679,12 @@ async function nodeInstall() { (0, core_1.setOutput)('node-version', version); } else if (platform === 'darwin') { - (0, core_1.info)('没有mac,暂未测试'); - // const nodePath = await downloadTool( - // `https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}.pkg` - // ); - // const nodeExtractedFolder = await extractXar(nodePath, './cache/node'); + (0, core_1.info)(`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-darwin-${(0, os_1.arch)()}.tar.gz`); + const nodePath = await (0, tool_cache_1.downloadTool)(`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-darwin-${(0, os_1.arch)()}.tar.gz`); + const nodeExtractedFolder = await (0, tool_cache_1.extractTar)(nodePath, './cache/node'); + const cachedPath = await (0, tool_cache_1.cacheDir)((0, path_1.join)(nodeExtractedFolder, `node-v${version}-darwin-${(0, os_1.arch)()}`), 'node', version); + (0, core_1.addPath)(cachedPath); + (0, core_1.setOutput)('node-version', version); } else { (0, core_1.info)(`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-linux-${(0, os_1.arch)()}.tar.gz`); diff --git a/src/lib/dotnet.ts b/src/lib/dotnet.ts index 8f2dc4d..f235101 100644 --- a/src/lib/dotnet.ts +++ b/src/lib/dotnet.ts @@ -1,11 +1,4 @@ -import { - downloadTool, - extractZip, - extractTar, - extractXar, - cacheDir, - find -} from '@actions/tool-cache'; +import { downloadTool, extractZip, extractTar, cacheDir, find } from '@actions/tool-cache'; import { addPath, getInput, setOutput, info, setFailed, error } from '@actions/core'; import { arch, platform as Platform } from 'os'; import { renameSync } from 'fs'; @@ -49,7 +42,7 @@ export async function dotnetInstall() { if (platform === 'win32') { return item.rid === 'win-' + arch() && item.url.endsWith('.zip'); } else if (platform === 'darwin') { - return item.rid === 'osx-' + arch() && item.url.endsWith('.pkg'); + return item.rid === 'osx-' + arch() && item.url.endsWith('.tar.gz'); } else { return item.rid === 'linux-' + arch() && item.url.endsWith('.tar.gz'); } @@ -69,7 +62,10 @@ export async function dotnetInstall() { addPath(cachedPath); setOutput('dotnet-path', cachedPath); } else if (platform === 'darwin') { - info('没有mac,暂未测试'); + const dotnetExtractedFolder = await extractTar(dotnetPath, './cache/dotnet'); + const cachedPath = await cacheDir(dotnetExtractedFolder, 'dotnet', dotnetVersion); + addPath(cachedPath); + setOutput('dotnet-path', cachedPath); } else { const dotnetExtractedFolder = await extractTar(dotnetPath, './cache/dotnet'); const cachedPath = await cacheDir(dotnetExtractedFolder, 'dotnet', dotnetVersion); diff --git a/src/lib/go.ts b/src/lib/go.ts index 4fb2912..e6cd559 100644 --- a/src/lib/go.ts +++ b/src/lib/go.ts @@ -1,12 +1,5 @@ import { join } from 'path'; -import { - downloadTool, - extractZip, - extractTar, - extractXar, - cacheDir, - find -} from '@actions/tool-cache'; +import { downloadTool, extractZip, extractTar, cacheDir, find } from '@actions/tool-cache'; import { addPath, getInput, info, setFailed } from '@actions/core'; import { arch, platform as Platform } from 'os'; import { renameSync } from 'fs'; @@ -26,25 +19,34 @@ export async function goInstall() { info('go已经安装过了'); return; } + const archD = arch() === 'x64' ? 'amd64' : arch(); try { if (platform === 'win32') { - info(`https://golang.google.cn/dl/go${goVersion}.windows-amd64.zip`); + info(`https://golang.google.cn/dl/go${goVersion}.windows-${archD}.zip`); const goPath = await downloadTool( - `https://golang.google.cn/dl/go${goVersion}.windows-amd64.zip` + `https://golang.google.cn/dl/go${goVersion}.windows-${archD}.zip` ); renameSync(goPath, goPath + '.zip'); const goExtractedFolder = await extractZip(goPath + '.zip', './cache/go'); const cachedPath = await cacheDir(join(goExtractedFolder, 'go'), 'go', goVersion); addPath(cachedPath); } else if (platform === 'darwin') { - info('没有mac,暂未测试'); - } else { - info(`https://golang.google.cn/dl/go${goVersion}.linux-amd64.tar.gz`); + info(`https://golang.google.cn/dl/go${goVersion}.darwin-${archD}.tar.gz`); const goPath = await downloadTool( - `https://golang.google.cn/dl/go${goVersion}.linux-amd64.tar.gz` + `https://golang.google.cn/dl/go${goVersion}.darwin-${archD}.tar.gz` + ); + const goExtractedFolder = await extractTar(goPath, './cache/go'); + + const cachedPath = await cacheDir(join(goExtractedFolder, 'go'), 'go', goVersion); + addPath(cachedPath); + } else { + info(`https://golang.google.cn/dl/go${goVersion}.linux-${archD}.tar.gz`); + + const goPath = await downloadTool( + `https://golang.google.cn/dl/go${goVersion}.linux-${archD}.tar.gz` ); const goExtractedFolder = await extractTar(goPath, './cache/go'); diff --git a/src/lib/node.ts b/src/lib/node.ts index efaa955..528e52c 100644 --- a/src/lib/node.ts +++ b/src/lib/node.ts @@ -1,12 +1,5 @@ import { join } from 'path'; -import { - downloadTool, - extractZip, - extractTar, - extractXar, - cacheDir, - find -} from '@actions/tool-cache'; +import { downloadTool, extractZip, extractTar, cacheDir, find } from '@actions/tool-cache'; import { addPath, getInput, setOutput, setFailed, info } from '@actions/core'; import { arch, platform as Platform } from 'os'; import { renameSync } from 'fs'; @@ -58,12 +51,22 @@ export async function nodeInstall() { addPath(cachedPath); setOutput('node-version', version); } else if (platform === 'darwin') { - info('没有mac,暂未测试'); + info( + `https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-darwin-${arch()}.tar.gz` + ); - // const nodePath = await downloadTool( - // `https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}.pkg` - // ); - // const nodeExtractedFolder = await extractXar(nodePath, './cache/node'); + const nodePath = await downloadTool( + `https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-darwin-${arch()}.tar.gz` + ); + const nodeExtractedFolder = await extractTar(nodePath, './cache/node'); + + const cachedPath = await cacheDir( + join(nodeExtractedFolder, `node-v${version}-darwin-${arch()}`), + 'node', + version + ); + addPath(cachedPath); + setOutput('node-version', version); } else { info( `https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-linux-${arch()}.tar.gz`