diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index e291309..ba74593 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -47,33 +47,33 @@ 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 linux', async () => { - rmSync('./cache', { recursive: true, force: true }); - os['platform'] = 'linux'; + 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(); - // inputs['dotnet-version'] = '5.0.401'; + // dotnet + // inputs['dotnet-version'] = '6.0.100'; // await dotnetInstall(); }); + // it('installs linux', async () => { + // // rmSync('./cache', { recursive: true, force: true }); + // os['platform'] = 'linux'; + // os['arch'] = 'x64'; + // inputs['node-version'] = '18'; + // await nodeInstall(); + // inputs['go-version'] = '1.21.1'; + // await goInstall(); + // inputs['dotnet-version'] = '5.0.401'; + // await dotnetInstall(); + // }); + // it('installs darwin', async () => { // os['platform'] = 'darwin'; // os['arch'] = 'x64'; diff --git a/src/lib/dotnet.ts b/src/lib/dotnet.ts index f39cd95..8f2dc4d 100644 --- a/src/lib/dotnet.ts +++ b/src/lib/dotnet.ts @@ -1,8 +1,14 @@ -import { join } from 'path'; -import { downloadTool, extractZip, extractTar, extractXar, cacheDir } from '@actions/tool-cache'; +import { + downloadTool, + extractZip, + extractTar, + extractXar, + cacheDir, + find +} from '@actions/tool-cache'; import { addPath, getInput, setOutput, info, setFailed, error } from '@actions/core'; import { arch, platform as Platform } from 'os'; -import { existsSync, renameSync } from 'fs'; +import { renameSync } from 'fs'; import { get } from 'axios'; // 安装dotnet @@ -14,15 +20,11 @@ export async function dotnetInstall() { return; } - if ( - process.env['RUNNER_TOOL_CACHE'] && - existsSync(join(process.env['RUNNER_TOOL_CACHE'], 'dotnet', dotnetVersion, arch())) - ) { + const dotnetPath = find('dotnet', dotnetVersion, arch()); + + if (dotnetPath) { info('dotnet已经安装过了'); - return setOutput( - 'dotnet-path', - join(process.env['RUNNER_TOOL_CACHE'], 'dotnet', dotnetVersion, arch()) - ); + return setOutput('dotnet-path', dotnetPath); } const versionList = dotnetVersion.split('.'); const channelVersion = `${versionList[0]}.${versionList[1]}`; diff --git a/src/lib/go.ts b/src/lib/go.ts index b527644..4fb2912 100644 --- a/src/lib/go.ts +++ b/src/lib/go.ts @@ -1,8 +1,15 @@ import { join } from 'path'; -import { downloadTool, extractZip, extractTar, extractXar, cacheDir } from '@actions/tool-cache'; +import { + downloadTool, + extractZip, + extractTar, + extractXar, + cacheDir, + find +} from '@actions/tool-cache'; import { addPath, getInput, info, setFailed } from '@actions/core'; import { arch, platform as Platform } from 'os'; -import { existsSync, renameSync } from 'fs'; +import { renameSync } from 'fs'; // 安装golang export async function goInstall() { @@ -12,12 +19,11 @@ export async function goInstall() { info('没有go-version,跳过go安装'); return; } - if ( - process.env['RUNNER_TOOL_CACHE'] && - existsSync(join(process.env['RUNNER_TOOL_CACHE'], 'go', goVersion, arch())) - ) { - info('go已经安装过了'); + const goPath = find('go', goVersion, arch()); + + if (goPath) { + info('go已经安装过了'); return; } diff --git a/src/lib/node.ts b/src/lib/node.ts index d2a91c9..efaa955 100644 --- a/src/lib/node.ts +++ b/src/lib/node.ts @@ -1,8 +1,15 @@ import { join } from 'path'; -import { downloadTool, extractZip, extractTar, extractXar, cacheDir } from '@actions/tool-cache'; +import { + downloadTool, + extractZip, + extractTar, + extractXar, + cacheDir, + find +} from '@actions/tool-cache'; import { addPath, getInput, setOutput, setFailed, info } from '@actions/core'; import { arch, platform as Platform } from 'os'; -import { existsSync, renameSync } from 'fs'; +import { renameSync } from 'fs'; import { nodeVersionAlias } from 'gitea-tool-cache-version-alias'; // 安装node @@ -22,11 +29,9 @@ export async function nodeInstall() { setFailed('node版本错误: ' + version); return; } + const NodePath = find('node', version, arch()); - if ( - process.env['RUNNER_TOOL_CACHE'] && - existsSync(join(process.env['RUNNER_TOOL_CACHE'], 'node', version, arch())) - ) { + if (NodePath) { info('node已经安装过了'); return setOutput('node-version', version);