From be69e2303ef9c8072a3f3590cc6487ba63e513a2 Mon Sep 17 00:00:00 2001 From: priyagupta108 Date: Tue, 25 Aug 2026 17:55:30 +0530 Subject: [PATCH] refactor: enhance logging and group setup for Go version installation --- dist/setup/index.js | 48 ++++++++++++++++++++--------------- src/main.ts | 62 +++++++++++++++++++++++++-------------------- 2 files changed, 61 insertions(+), 49 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index a131a9a..9f0db9c 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -100576,32 +100576,38 @@ async function run() { const versionSpec = resolveVersionInput(); setGoToolchain(); const cache = getBooleanInput('cache'); - core_info(`Setup go version spec ${versionSpec}`); let arch = getInput('architecture'); if (!arch) { arch = external_os_default().arch(); } if (versionSpec) { - const token = getInput('token'); - const auth = !token ? undefined : `token ${token}`; - const checkLatest = getBooleanInput('check-latest'); - const goDownloadBaseUrl = getInput('go-download-base-url') || - process.env['GO_DOWNLOAD_BASE_URL'] || - undefined; - if (goDownloadBaseUrl) { - core_info(`Using custom Go download base URL: ${goDownloadBaseUrl}`); - } - const installDir = await getGo(versionSpec, checkLatest, auth, arch, goDownloadBaseUrl); - const installDirVersion = external_path_default().basename(external_path_default().dirname(installDir)); - addPath(external_path_default().join(installDir, 'bin')); - core_info('Added go to the path'); - const version = makeSemver(installDirVersion); - // Go versions less than 1.9 require GOROOT to be set - if (node_modules_semver.lt(version, '1.9.0')) { - core_info('Setting GOROOT for Go version < 1.9'); - exportVariable('GOROOT', installDir); - } - core_info(`Successfully set up Go version ${versionSpec}`); + startGroup(`Setup Go ${versionSpec}`); + try { + core_info(`Setup go version spec ${versionSpec}`); + const token = getInput('token'); + const auth = !token ? undefined : `token ${token}`; + const checkLatest = getBooleanInput('check-latest'); + const goDownloadBaseUrl = getInput('go-download-base-url') || + process.env['GO_DOWNLOAD_BASE_URL'] || + undefined; + if (goDownloadBaseUrl) { + core_info(`Using custom Go download base URL: ${goDownloadBaseUrl}`); + } + const installDir = await getGo(versionSpec, checkLatest, auth, arch, goDownloadBaseUrl); + const installDirVersion = external_path_default().basename(external_path_default().dirname(installDir)); + addPath(external_path_default().join(installDir, 'bin')); + core_info('Added go to the path'); + const version = makeSemver(installDirVersion); + // Go versions less than 1.9 require GOROOT to be set + if (node_modules_semver.lt(version, '1.9.0')) { + core_info('Setting GOROOT for Go version < 1.9'); + exportVariable('GOROOT', installDir); + } + core_info(`Successfully set up Go version ${versionSpec}`); + } + finally { + endGroup(); + } } else { core_info('[warning]go-version input was not specified. The action will try to use pre-installed version.'); diff --git a/src/main.ts b/src/main.ts index 98aee1c..fb17d05 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,6 @@ export async function run() { setGoToolchain(); const cache = core.getBooleanInput('cache'); - core.info(`Setup go version spec ${versionSpec}`); let arch = core.getInput('architecture') as Architecture; @@ -30,41 +29,48 @@ export async function run() { } if (versionSpec) { - const token = core.getInput('token'); - const auth = !token ? undefined : `token ${token}`; + core.startGroup(`Setup Go ${versionSpec}`); + try { + core.info(`Setup go version spec ${versionSpec}`); - const checkLatest = core.getBooleanInput('check-latest'); + const token = core.getInput('token'); + const auth = !token ? undefined : `token ${token}`; - const goDownloadBaseUrl = - core.getInput('go-download-base-url') || - process.env['GO_DOWNLOAD_BASE_URL'] || - undefined; + const checkLatest = core.getBooleanInput('check-latest'); - if (goDownloadBaseUrl) { - core.info(`Using custom Go download base URL: ${goDownloadBaseUrl}`); - } + const goDownloadBaseUrl = + core.getInput('go-download-base-url') || + process.env['GO_DOWNLOAD_BASE_URL'] || + undefined; - const installDir = await installer.getGo( - versionSpec, - checkLatest, - auth, - arch, - goDownloadBaseUrl - ); + if (goDownloadBaseUrl) { + core.info(`Using custom Go download base URL: ${goDownloadBaseUrl}`); + } - const installDirVersion = path.basename(path.dirname(installDir)); + const installDir = await installer.getGo( + versionSpec, + checkLatest, + auth, + arch, + goDownloadBaseUrl + ); - core.addPath(path.join(installDir, 'bin')); - core.info('Added go to the path'); + const installDirVersion = path.basename(path.dirname(installDir)); - const version = installer.makeSemver(installDirVersion); - // Go versions less than 1.9 require GOROOT to be set - if (semver.lt(version, '1.9.0')) { - core.info('Setting GOROOT for Go version < 1.9'); - core.exportVariable('GOROOT', installDir); - } + core.addPath(path.join(installDir, 'bin')); + core.info('Added go to the path'); + + const version = installer.makeSemver(installDirVersion); + // Go versions less than 1.9 require GOROOT to be set + if (semver.lt(version, '1.9.0')) { + core.info('Setting GOROOT for Go version < 1.9'); + core.exportVariable('GOROOT', installDir); + } - core.info(`Successfully set up Go version ${versionSpec}`); + core.info(`Successfully set up Go version ${versionSpec}`); + } finally { + core.endGroup(); + } } else { core.info( '[warning]go-version input was not specified. The action will try to use pre-installed version.'