mirror of
https://git.studyfor.work/actions/gitea-tool-cache.git
synced 2026-01-12 00:16:03 +08:00
更新错误处理
This commit is contained in:
parent
c847c25fe2
commit
b93c3b2ef3
@ -11,6 +11,7 @@ describe('gitea-tool-cache', () => {
|
||||
let inSpy: jest.SpyInstance;
|
||||
let platSpy: jest.SpyInstance;
|
||||
let archSpy: jest.SpyInstance;
|
||||
let logSpy: jest.SpyInstance;
|
||||
|
||||
beforeAll(() => {
|
||||
process.env['RUNNER_TOOL_CACHE'] = join(process.cwd(), './cache/toolcache');
|
||||
@ -30,6 +31,9 @@ describe('gitea-tool-cache', () => {
|
||||
platSpy.mockImplementation(() => os['platform']);
|
||||
archSpy = jest.spyOn(osm, 'arch');
|
||||
archSpy.mockImplementation(() => os['arch']);
|
||||
|
||||
// writes
|
||||
logSpy = jest.spyOn(core, 'info');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -59,9 +63,10 @@ describe('gitea-tool-cache', () => {
|
||||
// });
|
||||
|
||||
it('installs linux', async () => {
|
||||
rmSync('./cache', { recursive: true, force: true });
|
||||
os['platform'] = 'linux';
|
||||
os['arch'] = 'x64';
|
||||
inputs['node-version'] = '18 ';
|
||||
inputs['node-version'] = '18';
|
||||
await nodeInstall();
|
||||
// inputs['go-version'] = '1.21.1';
|
||||
// await goInstall();
|
||||
|
||||
150
dist/index.js
vendored
150
dist/index.js
vendored
@ -49480,30 +49480,28 @@ async function dotnetInstall() {
|
||||
const platform = (0, os_1.platform)();
|
||||
const dotnetVersion = (0, core_1.getInput)('dotnet-version');
|
||||
if (!dotnetVersion) {
|
||||
console.log('没有dotnet-version,跳过dotnet安装');
|
||||
(0, core_1.info)('没有dotnet-version,跳过dotnet安装');
|
||||
return;
|
||||
}
|
||||
if (process.env['RUNNER_TOOL_CACHE'] &&
|
||||
(0, fs_1.existsSync)((0, path_1.join)(process.env['RUNNER_TOOL_CACHE'], 'dotnet', dotnetVersion, (0, os_1.arch)()))) {
|
||||
console.log('dotnet已经安装过了');
|
||||
(0, core_1.info)('dotnet已经安装过了');
|
||||
return (0, core_1.setOutput)('dotnet-path', (0, path_1.join)(process.env['RUNNER_TOOL_CACHE'], 'dotnet', dotnetVersion, (0, os_1.arch)()));
|
||||
}
|
||||
const versionList = dotnetVersion.split('.');
|
||||
const channelVersion = `${versionList[0]}.${versionList[1]}`;
|
||||
const releasesUrl = `https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/${channelVersion}/releases.json`;
|
||||
const releases = await (0, axios_1.get)(releasesUrl).catch(err => {
|
||||
console.log(err);
|
||||
(0, core_1.error)(err);
|
||||
return null;
|
||||
});
|
||||
if (!releases || !releases.data) {
|
||||
console.log('获取dotnet版本失败');
|
||||
return false;
|
||||
return (0, core_1.setFailed)('获取dotnet版本失败');
|
||||
}
|
||||
const releasesList = releases.data.releases;
|
||||
const release = releasesList.find((item) => item.sdk.version === dotnetVersion);
|
||||
if (!release) {
|
||||
console.log('没有找到dotnet版本');
|
||||
return false;
|
||||
return (0, core_1.setFailed)('没有找到dotnet版本');
|
||||
}
|
||||
const list = release.sdk.files.find((item) => {
|
||||
if (platform === 'win32') {
|
||||
@ -49517,27 +49515,30 @@ async function dotnetInstall() {
|
||||
}
|
||||
});
|
||||
if (!list) {
|
||||
console.log('没有找到dotnet版本');
|
||||
return false;
|
||||
return (0, core_1.setFailed)('没有找到dotnet版本');
|
||||
}
|
||||
// console.log(list);
|
||||
console.log(list.url);
|
||||
const dotnetPath = await (0, tool_cache_1.downloadTool)(list.url);
|
||||
if (platform === 'win32') {
|
||||
(0, fs_1.renameSync)(dotnetPath, dotnetPath + '.zip');
|
||||
const dotnetExtractedFolder = await (0, tool_cache_1.extractZip)(dotnetPath + '.zip', './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);
|
||||
(0, core_1.info)(list.url);
|
||||
try {
|
||||
const dotnetPath = await (0, tool_cache_1.downloadTool)(list.url);
|
||||
if (platform === 'win32') {
|
||||
(0, fs_1.renameSync)(dotnetPath, dotnetPath + '.zip');
|
||||
const dotnetExtractedFolder = await (0, tool_cache_1.extractZip)(dotnetPath + '.zip', './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 if (platform === 'darwin') {
|
||||
(0, core_1.info)('没有mac,暂未测试');
|
||||
}
|
||||
else {
|
||||
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 if (platform === 'darwin') {
|
||||
console.log('没有mac,暂未测试');
|
||||
}
|
||||
else {
|
||||
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);
|
||||
catch (error) {
|
||||
(0, core_1.setFailed)(JSON.stringify(error));
|
||||
}
|
||||
}
|
||||
exports.dotnetInstall = dotnetInstall;
|
||||
@ -49562,31 +49563,36 @@ async function goInstall() {
|
||||
const platform = (0, os_1.platform)();
|
||||
const goVersion = (0, core_1.getInput)('go-version');
|
||||
if (!goVersion) {
|
||||
console.log('没有go-version,跳过go安装');
|
||||
(0, core_1.info)('没有go-version,跳过go安装');
|
||||
return;
|
||||
}
|
||||
if (process.env['RUNNER_TOOL_CACHE'] &&
|
||||
(0, fs_1.existsSync)((0, path_1.join)(process.env['RUNNER_TOOL_CACHE'], 'go', goVersion, (0, os_1.arch)()))) {
|
||||
console.log('go已经安装过了');
|
||||
(0, core_1.info)('go已经安装过了');
|
||||
return;
|
||||
}
|
||||
if (platform === 'win32') {
|
||||
console.log(`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, 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);
|
||||
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, 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,暂未测试');
|
||||
}
|
||||
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`);
|
||||
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 if (platform === 'darwin') {
|
||||
console.log('没有mac,暂未测试');
|
||||
}
|
||||
else {
|
||||
console.log(`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`);
|
||||
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);
|
||||
catch (error) {
|
||||
(0, core_1.setFailed)(JSON.stringify(error));
|
||||
}
|
||||
}
|
||||
exports.goInstall = goInstall;
|
||||
@ -49639,44 +49645,50 @@ async function nodeInstall() {
|
||||
const platform = (0, os_1.platform)();
|
||||
const nodeVersion = (0, core_1.getInput)('node-version');
|
||||
if (!nodeVersion) {
|
||||
console.log('没有node-version,跳过node安装');
|
||||
(0, core_1.info)('没有node-version,跳过node安装');
|
||||
return;
|
||||
}
|
||||
const version = await (0, gitea_tool_cache_version_alias_1.nodeVersionAlias)(nodeVersion, {
|
||||
mirror: 'https://npmmirror.com/mirrors/node'
|
||||
}).catch(err => err);
|
||||
if (version instanceof Error) {
|
||||
console.log('node版本错误', version);
|
||||
// console.error('node版本错误', version);
|
||||
(0, core_1.setFailed)('node版本错误: ' + version);
|
||||
return;
|
||||
}
|
||||
if (process.env['RUNNER_TOOL_CACHE'] &&
|
||||
(0, fs_1.existsSync)((0, path_1.join)(process.env['RUNNER_TOOL_CACHE'], 'node', version, (0, os_1.arch)()))) {
|
||||
console.log('node已经安装过了');
|
||||
(0, core_1.info)('node已经安装过了');
|
||||
return (0, core_1.setOutput)('node-version', version);
|
||||
}
|
||||
if (platform === 'win32') {
|
||||
console.log(`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-win-${(0, os_1.arch)()}.zip`);
|
||||
const nodePath = await (0, tool_cache_1.downloadTool)(`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-win-${(0, os_1.arch)()}.zip`);
|
||||
(0, fs_1.renameSync)(nodePath, nodePath + '.zip');
|
||||
const nodeExtractedFolder = await (0, tool_cache_1.extractZip)(nodePath + '.zip', './cache/node');
|
||||
const cachedPath = await (0, tool_cache_1.cacheDir)((0, path_1.join)(nodeExtractedFolder, `node-v${version}-win-${(0, os_1.arch)()}`), 'node', version);
|
||||
(0, core_1.addPath)(cachedPath);
|
||||
(0, core_1.setOutput)('node-version', version);
|
||||
try {
|
||||
if (platform === 'win32') {
|
||||
(0, core_1.info)(`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-win-${(0, os_1.arch)()}.zip`);
|
||||
const nodePath = await (0, tool_cache_1.downloadTool)(`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-win-${(0, os_1.arch)()}.zip`);
|
||||
(0, fs_1.renameSync)(nodePath, nodePath + '.zip');
|
||||
const nodeExtractedFolder = await (0, tool_cache_1.extractZip)(nodePath + '.zip', './cache/node');
|
||||
const cachedPath = await (0, tool_cache_1.cacheDir)((0, path_1.join)(nodeExtractedFolder, `node-v${version}-win-${(0, os_1.arch)()}`), 'node', version);
|
||||
(0, core_1.addPath)(cachedPath);
|
||||
(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');
|
||||
}
|
||||
else {
|
||||
(0, core_1.info)(`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-linux-${(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}-linux-${(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}-linux-${(0, os_1.arch)()}`), 'node', version);
|
||||
(0, core_1.addPath)(cachedPath);
|
||||
(0, core_1.setOutput)('node-version', version);
|
||||
}
|
||||
}
|
||||
else if (platform === 'darwin') {
|
||||
console.log('没有mac,暂未测试');
|
||||
// const nodePath = await downloadTool(
|
||||
// `https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}.pkg`
|
||||
// );
|
||||
// const nodeExtractedFolder = await extractXar(nodePath, './cache/node');
|
||||
}
|
||||
else {
|
||||
console.log(`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-linux-${(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}-linux-${(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}-linux-${(0, os_1.arch)()}`), 'node', version);
|
||||
(0, core_1.addPath)(cachedPath);
|
||||
(0, core_1.setOutput)('node-version', version);
|
||||
catch (error) {
|
||||
(0, core_1.setFailed)(JSON.stringify(error));
|
||||
}
|
||||
}
|
||||
exports.nodeInstall = nodeInstall;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { join } from 'path';
|
||||
import { downloadTool, extractZip, extractTar, extractXar, cacheDir } from '@actions/tool-cache';
|
||||
import { addPath, getInput, setOutput } from '@actions/core';
|
||||
import { addPath, getInput, setOutput, info, setFailed, error } from '@actions/core';
|
||||
import { arch, platform as Platform } from 'os';
|
||||
import { existsSync, renameSync } from 'fs';
|
||||
import { get } from 'axios';
|
||||
@ -10,7 +10,7 @@ export async function dotnetInstall() {
|
||||
const platform = Platform();
|
||||
const dotnetVersion = getInput('dotnet-version');
|
||||
if (!dotnetVersion) {
|
||||
console.log('没有dotnet-version,跳过dotnet安装');
|
||||
info('没有dotnet-version,跳过dotnet安装');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ export async function dotnetInstall() {
|
||||
process.env['RUNNER_TOOL_CACHE'] &&
|
||||
existsSync(join(process.env['RUNNER_TOOL_CACHE'], 'dotnet', dotnetVersion, arch()))
|
||||
) {
|
||||
console.log('dotnet已经安装过了');
|
||||
info('dotnet已经安装过了');
|
||||
return setOutput(
|
||||
'dotnet-path',
|
||||
join(process.env['RUNNER_TOOL_CACHE'], 'dotnet', dotnetVersion, arch())
|
||||
@ -28,21 +28,19 @@ export async function dotnetInstall() {
|
||||
const channelVersion = `${versionList[0]}.${versionList[1]}`;
|
||||
const releasesUrl = `https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/${channelVersion}/releases.json`;
|
||||
const releases = await get(releasesUrl).catch(err => {
|
||||
console.log(err);
|
||||
error(err);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!releases || !releases.data) {
|
||||
console.log('获取dotnet版本失败');
|
||||
return false;
|
||||
return setFailed('获取dotnet版本失败');
|
||||
}
|
||||
const releasesList = (releases.data as Record<string, any>).releases;
|
||||
const release = releasesList.find(
|
||||
(item: Record<string, any>) => item.sdk.version === dotnetVersion
|
||||
);
|
||||
if (!release) {
|
||||
console.log('没有找到dotnet版本');
|
||||
return false;
|
||||
return setFailed('没有找到dotnet版本');
|
||||
}
|
||||
|
||||
const list = release.sdk.files.find((item: Record<string, any>) => {
|
||||
@ -55,26 +53,28 @@ export async function dotnetInstall() {
|
||||
}
|
||||
});
|
||||
if (!list) {
|
||||
console.log('没有找到dotnet版本');
|
||||
return false;
|
||||
return setFailed('没有找到dotnet版本');
|
||||
}
|
||||
// console.log(list);
|
||||
|
||||
console.log(list.url);
|
||||
info(list.url);
|
||||
|
||||
const dotnetPath = await downloadTool(list.url);
|
||||
if (platform === 'win32') {
|
||||
renameSync(dotnetPath, dotnetPath + '.zip');
|
||||
const dotnetExtractedFolder = await extractZip(dotnetPath + '.zip', './cache/dotnet');
|
||||
const cachedPath = await cacheDir(dotnetExtractedFolder, 'dotnet', dotnetVersion);
|
||||
addPath(cachedPath);
|
||||
setOutput('dotnet-path', cachedPath);
|
||||
} else if (platform === 'darwin') {
|
||||
console.log('没有mac,暂未测试');
|
||||
} else {
|
||||
const dotnetExtractedFolder = await extractTar(dotnetPath, './cache/dotnet');
|
||||
const cachedPath = await cacheDir(dotnetExtractedFolder, 'dotnet', dotnetVersion);
|
||||
addPath(cachedPath);
|
||||
setOutput('dotnet-path', cachedPath);
|
||||
try {
|
||||
const dotnetPath = await downloadTool(list.url);
|
||||
if (platform === 'win32') {
|
||||
renameSync(dotnetPath, dotnetPath + '.zip');
|
||||
const dotnetExtractedFolder = await extractZip(dotnetPath + '.zip', './cache/dotnet');
|
||||
const cachedPath = await cacheDir(dotnetExtractedFolder, 'dotnet', dotnetVersion);
|
||||
addPath(cachedPath);
|
||||
setOutput('dotnet-path', cachedPath);
|
||||
} else if (platform === 'darwin') {
|
||||
info('没有mac,暂未测试');
|
||||
} else {
|
||||
const dotnetExtractedFolder = await extractTar(dotnetPath, './cache/dotnet');
|
||||
const cachedPath = await cacheDir(dotnetExtractedFolder, 'dotnet', dotnetVersion);
|
||||
addPath(cachedPath);
|
||||
setOutput('dotnet-path', cachedPath);
|
||||
}
|
||||
} catch (error) {
|
||||
setFailed(JSON.stringify(error));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { join } from 'path';
|
||||
import { downloadTool, extractZip, extractTar, extractXar, cacheDir } from '@actions/tool-cache';
|
||||
import { addPath, getInput } from '@actions/core';
|
||||
import { addPath, getInput, info, setFailed } from '@actions/core';
|
||||
import { arch, platform as Platform } from 'os';
|
||||
import { existsSync, renameSync } from 'fs';
|
||||
|
||||
@ -9,39 +9,43 @@ export async function goInstall() {
|
||||
const platform = Platform();
|
||||
const goVersion = getInput('go-version');
|
||||
if (!goVersion) {
|
||||
console.log('没有go-version,跳过go安装');
|
||||
info('没有go-version,跳过go安装');
|
||||
return;
|
||||
}
|
||||
if (
|
||||
process.env['RUNNER_TOOL_CACHE'] &&
|
||||
existsSync(join(process.env['RUNNER_TOOL_CACHE'], 'go', goVersion, arch()))
|
||||
) {
|
||||
console.log('go已经安装过了');
|
||||
info('go已经安装过了');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (platform === 'win32') {
|
||||
console.log(`https://golang.google.cn/dl/go${goVersion}.windows-amd64.zip`);
|
||||
try {
|
||||
if (platform === 'win32') {
|
||||
info(`https://golang.google.cn/dl/go${goVersion}.windows-amd64.zip`);
|
||||
|
||||
const goPath = await downloadTool(
|
||||
`https://golang.google.cn/dl/go${goVersion}.windows-amd64.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') {
|
||||
console.log('没有mac,暂未测试');
|
||||
} else {
|
||||
console.log(`https://golang.google.cn/dl/go${goVersion}.linux-amd64.tar.gz`);
|
||||
const goPath = await downloadTool(
|
||||
`https://golang.google.cn/dl/go${goVersion}.windows-amd64.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`);
|
||||
|
||||
const goPath = await downloadTool(
|
||||
`https://golang.google.cn/dl/go${goVersion}.linux-amd64.tar.gz`
|
||||
);
|
||||
const goExtractedFolder = await extractTar(goPath, './cache/go');
|
||||
const goPath = await downloadTool(
|
||||
`https://golang.google.cn/dl/go${goVersion}.linux-amd64.tar.gz`
|
||||
);
|
||||
const goExtractedFolder = await extractTar(goPath, './cache/go');
|
||||
|
||||
const cachedPath = await cacheDir(join(goExtractedFolder, 'go'), 'go', goVersion);
|
||||
addPath(cachedPath);
|
||||
const cachedPath = await cacheDir(join(goExtractedFolder, 'go'), 'go', goVersion);
|
||||
addPath(cachedPath);
|
||||
}
|
||||
} catch (error) {
|
||||
setFailed(JSON.stringify(error));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { join } from 'path';
|
||||
import { downloadTool, extractZip, extractTar, extractXar, cacheDir } from '@actions/tool-cache';
|
||||
import { addPath, getInput, setOutput } from '@actions/core';
|
||||
import { addPath, getInput, setOutput, setFailed, info } from '@actions/core';
|
||||
import { arch, platform as Platform } from 'os';
|
||||
import { existsSync, renameSync } from 'fs';
|
||||
import { nodeVersionAlias } from 'gitea-tool-cache-version-alias';
|
||||
@ -10,7 +10,7 @@ export async function nodeInstall() {
|
||||
const platform = Platform();
|
||||
const nodeVersion = getInput('node-version');
|
||||
if (!nodeVersion) {
|
||||
console.log('没有node-version,跳过node安装');
|
||||
info('没有node-version,跳过node安装');
|
||||
return;
|
||||
}
|
||||
const version = await nodeVersionAlias(nodeVersion, {
|
||||
@ -18,7 +18,8 @@ export async function nodeInstall() {
|
||||
}).catch(err => err);
|
||||
|
||||
if (version instanceof Error) {
|
||||
console.log('node版本错误', version);
|
||||
// console.error('node版本错误', version);
|
||||
setFailed('node版本错误: ' + version);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -26,53 +27,57 @@ export async function nodeInstall() {
|
||||
process.env['RUNNER_TOOL_CACHE'] &&
|
||||
existsSync(join(process.env['RUNNER_TOOL_CACHE'], 'node', version, arch()))
|
||||
) {
|
||||
console.log('node已经安装过了');
|
||||
info('node已经安装过了');
|
||||
|
||||
return setOutput('node-version', version);
|
||||
}
|
||||
|
||||
if (platform === 'win32') {
|
||||
console.log(
|
||||
`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-win-${arch()}.zip`
|
||||
);
|
||||
try {
|
||||
if (platform === 'win32') {
|
||||
info(
|
||||
`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-win-${arch()}.zip`
|
||||
);
|
||||
|
||||
const nodePath = await downloadTool(
|
||||
`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-win-${arch()}.zip`
|
||||
);
|
||||
const nodePath = await downloadTool(
|
||||
`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-win-${arch()}.zip`
|
||||
);
|
||||
|
||||
renameSync(nodePath, nodePath + '.zip');
|
||||
renameSync(nodePath, nodePath + '.zip');
|
||||
|
||||
const nodeExtractedFolder = await extractZip(nodePath + '.zip', './cache/node');
|
||||
const cachedPath = await cacheDir(
|
||||
join(nodeExtractedFolder, `node-v${version}-win-${arch()}`),
|
||||
'node',
|
||||
version
|
||||
);
|
||||
addPath(cachedPath);
|
||||
setOutput('node-version', version);
|
||||
} else if (platform === 'darwin') {
|
||||
console.log('没有mac,暂未测试');
|
||||
const nodeExtractedFolder = await extractZip(nodePath + '.zip', './cache/node');
|
||||
const cachedPath = await cacheDir(
|
||||
join(nodeExtractedFolder, `node-v${version}-win-${arch()}`),
|
||||
'node',
|
||||
version
|
||||
);
|
||||
addPath(cachedPath);
|
||||
setOutput('node-version', version);
|
||||
} else if (platform === 'darwin') {
|
||||
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');
|
||||
} else {
|
||||
console.log(
|
||||
`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-linux-${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');
|
||||
} else {
|
||||
info(
|
||||
`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-linux-${arch()}.tar.gz`
|
||||
);
|
||||
|
||||
const nodePath = await downloadTool(
|
||||
`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-linux-${arch()}.tar.gz`
|
||||
);
|
||||
const nodeExtractedFolder = await extractTar(nodePath, './cache/node');
|
||||
const nodePath = await downloadTool(
|
||||
`https://registry.npmmirror.com/-/binary/node/v${version}/node-v${version}-linux-${arch()}.tar.gz`
|
||||
);
|
||||
const nodeExtractedFolder = await extractTar(nodePath, './cache/node');
|
||||
|
||||
const cachedPath = await cacheDir(
|
||||
join(nodeExtractedFolder, `node-v${version}-linux-${arch()}`),
|
||||
'node',
|
||||
version
|
||||
);
|
||||
addPath(cachedPath);
|
||||
setOutput('node-version', version);
|
||||
const cachedPath = await cacheDir(
|
||||
join(nodeExtractedFolder, `node-v${version}-linux-${arch()}`),
|
||||
'node',
|
||||
version
|
||||
);
|
||||
addPath(cachedPath);
|
||||
setOutput('node-version', version);
|
||||
}
|
||||
} catch (error) {
|
||||
setFailed(JSON.stringify(error));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user