添加日志
All checks were successful
Continuous Integration / GitHub Actions Test (push) Successful in 14s

This commit is contained in:
soul-walker 2024-03-13 16:08:44 +08:00
parent c4f6ea909f
commit fb7131260b

View File

@ -13,10 +13,11 @@ import { getGoFileName, getGoRootPath, getInstalledGoPath } from './install'
*/
export async function run(): Promise<void> {
try {
// 获取输入的go-version
const version: string = resolveVersionInput()
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
core.debug(`The input go version is: ${version}`)
// 获取输入的architecture
let arch = core.getInput('architecture')
if (!arch) {
arch = os.arch()
@ -24,28 +25,31 @@ export async function run(): Promise<void> {
if (arch === 'x64') {
arch = 'amd64'
}
// 构建go文件名
const dlgfName = getGoFileName(version, arch)
let installedPath = getGoRootPath()
// 尝试从缓存中恢复
const rcr = await cache.restoreCache([getGoRootPath()], dlgfName)
if (!rcr) {
core.info(`Cache not found for input key: ${dlgfName}`)
// 缓存中没有找到,下载解压安装
installedPath = await getInstalledGoPath(dlgfName)
core.info(`Success Installed go to ${installedPath}`)
// 保存到缓存
await cache.saveCache([installedPath], dlgfName)
}
// 将go的bin目录添加到PATH
const binPath = path.join(installedPath, 'bin')
getFiles(binPath)
core.addPath(binPath)
// 测试输出go的版本
const goPath = await io.which('go')
const goVersion = (cp.execSync(`${goPath} version`) || '').toString()
core.info(`go version cmd result is: ${goVersion}`)
// 设置输出参数
core.setOutput('go-version', goVersion)
// Set outputs for other workflow steps to use
// core.setOutput('go-version', version)
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)