From 7b3158236da03b41d827bcaf7251657027bbb8d7 Mon Sep 17 00:00:00 2001 From: Ayush Date: Thu, 9 Oct 2025 12:33:59 +0530 Subject: [PATCH] fix: resolve unused error variables and update build --- .eslintrc.json | 5 +++ dist/index.js | 120 +++++++++++++++++++++++-------------------------- main.js | 120 +++++++++++++++++++++++-------------------------- package.json | 7 ++- 4 files changed, 124 insertions(+), 128 deletions(-) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..3e5a151 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "parserOptions": { + "ecmaVersion": 2019 + } +} diff --git a/dist/index.js b/dist/index.js index bfb623a..3863e70 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10942,8 +10942,8 @@ async function downloadDoctl(version, type, architecture) { const doctlDownload = await tc.downloadTool(downloadURL); return tc.extractTar(doctlDownload); } catch (error) { - core.warning(`Failed to download doctl v${version}: ${error.message}`); - throw new Error(`Download failed for version ${version}: ${error.message}`); + core.warning(`Failed to download doctl v${version}: ${error}`); + throw new Error(`Download failed for version ${version}: ${error}`); } } @@ -10954,7 +10954,7 @@ async function downloadDoctlWithFallback(requestedVersion, type, architecture) { core.info(`Attempting to download doctl v${requestedVersion}`); return await downloadDoctl(requestedVersion, type, architecture); } catch (error) { - core.warning(`Failed to download requested version v${requestedVersion}, will try recent versions`); + core.warning(`Failed to download requested version v${requestedVersion}, will try recent versions. Details: ${error}`); } } @@ -10968,7 +10968,7 @@ async function downloadDoctlWithFallback(requestedVersion, type, architecture) { core.info(`Successfully downloaded doctl v${version}`); return { installPath, version }; } catch (error) { - core.warning(`Failed to download doctl v${version}, trying next version`); + core.warning(`Failed to download doctl v${version}, trying next version. Details: ${error}`); continue; } } @@ -10978,68 +10978,62 @@ async function downloadDoctlWithFallback(requestedVersion, type, architecture) { } async function run() { - try { - var version = core.getInput('version'); - var requestedVersion = version; - - if ((!version) || (version.toLowerCase() === 'latest')) { - version = await octokit.repos.getLatestRelease({ - owner: 'digitalocean', - repo: 'doctl' - }).then(result => { - return result.data.name; - }).catch(error => { - // GitHub rate-limits are by IP address and runners can share IPs. - // This mostly effects macOS where the pool of runners seems limited. - // Fallback to a known version if API access is rate limited. - core.warning(`${error.message} - -Failed to retrieve latest version; falling back to: ${fallbackVersion}`); - return fallbackVersion; - }); - requestedVersion = 'latest'; - } - if (version.charAt(0) === 'v') { - version = version.substr(1); - } + try { + var version = core.getInput('version'); + var requestedVersion = version; + + if ((!version) || (version.toLowerCase() === 'latest')) { + version = await octokit.repos.getLatestRelease({ + owner: 'digitalocean', + repo: 'doctl' + }).then(result => { + return result.data.name; + }).catch(error => { + core.warning(`${error.message}\nFailed to retrieve latest version; falling back to: ${fallbackVersion}`); + return fallbackVersion; + }); + requestedVersion = 'latest'; + } + if (version.charAt(0) === 'v') { + version = version.substr(1); + } - var path = tc.find("doctl", version); - var actualVersion = version; - - if (!path) { - try { - // Try the requested/latest version first - const installPath = await downloadDoctl(version, process.platform, process.arch); - path = await tc.cacheDir(installPath, 'doctl', version); - actualVersion = version; - } catch (error) { - // If the download fails (e.g., missing artifacts), try fallback versions - core.warning(`Failed to download doctl v${version}, trying fallback versions`); - const result = await downloadDoctlWithFallback(requestedVersion, process.platform, process.arch); - path = await tc.cacheDir(result.installPath, 'doctl', result.version); - actualVersion = result.version; + var path = tc.find("doctl", version); + var actualVersion = version; + + if (!path) { + try { + // Try the requested/latest version first + const installPath = await downloadDoctl(version, process.platform, process.arch); + path = await tc.cacheDir(installPath, 'doctl', version); + actualVersion = version; + } catch (error) { + // If the download fails (e.g., missing artifacts), try fallback versions + core.warning(`Failed to download doctl v${version}, trying fallback versions. Details: ${error}`); + const result = await downloadDoctlWithFallback(requestedVersion, process.platform, process.arch); + path = await tc.cacheDir(result.installPath, 'doctl', result.version); + actualVersion = result.version; + } } - } - - core.addPath(path); - core.info(`>>> doctl version v${actualVersion} installed to ${path}`); - - // Skip authentication if requested - // for workflows where auth isn't necessary (e.g. doctl app spec validate --schema-only) - var no_auth = core.getInput('no_auth'); - if (no_auth.toLowerCase() === 'true') { - core.info('>>> Skipping doctl auth'); - return; - } + + core.addPath(path); + core.info(`>>> doctl version v${actualVersion} installed to ${path}`); - var token = core.getInput('token', { required: true }); - core.setSecret(token); - await exec.exec('doctl auth init -t', [token]); - core.info('>>> Successfully logged into doctl'); - } - catch (error) { - core.setFailed(error.message); - } + // Skip authentication if requested + // for workflows where auth isn't necessary (e.g. doctl app spec validate --schema-only) + var no_auth = core.getInput('no_auth'); + if (no_auth.toLowerCase() === 'true') { + core.info('>>> Skipping doctl auth'); + return; + } + + var token = core.getInput('token', { required: true }); + core.setSecret(token); + await exec.exec('doctl auth init -t', [token]); + core.info('>>> Successfully logged into doctl'); + } catch (error) { + core.setFailed(error.message); + } } run(); diff --git a/main.js b/main.js index 2511e20..99ad970 100644 --- a/main.js +++ b/main.js @@ -64,23 +64,23 @@ async function downloadDoctl(version, type, architecture) { const doctlDownload = await tc.downloadTool(downloadURL); return tc.extractTar(doctlDownload); } catch (error) { - core.warning(`Failed to download doctl v${version}: ${error.message}`); - throw new Error(`Download failed for version ${version}: ${error.message}`); + core.warning(`Failed to download doctl v${version}: ${error}`); + throw new Error(`Download failed for version ${version}: ${error}`); } } async function downloadDoctlWithFallback(requestedVersion, type, architecture) { - // If a specific version was requested, try it first + if (requestedVersion !== 'latest') { try { core.info(`Attempting to download doctl v${requestedVersion}`); return await downloadDoctl(requestedVersion, type, architecture); } catch (error) { - core.warning(`Failed to download requested version v${requestedVersion}, will try recent versions`); + core.warning(`Failed to download requested version v${requestedVersion}, will try recent versions. Details: ${error}`); } } - // Get recent releases and try them in order + const recentReleases = await getRecentReleases(5); for (const version of recentReleases) { @@ -90,78 +90,70 @@ async function downloadDoctlWithFallback(requestedVersion, type, architecture) { core.info(`Successfully downloaded doctl v${version}`); return { installPath, version }; } catch (error) { - core.warning(`Failed to download doctl v${version}, trying next version`); + core.warning(`Failed to download doctl v${version}, trying next version. Details: ${error}`); continue; } } - // If all recent versions fail, throw an error + throw new Error(`Failed to download doctl. Tried versions: ${recentReleases.join(', ')}`); } async function run() { - try { - var version = core.getInput('version'); - var requestedVersion = version; - - if ((!version) || (version.toLowerCase() === 'latest')) { - version = await octokit.repos.getLatestRelease({ - owner: 'digitalocean', - repo: 'doctl' - }).then(result => { - return result.data.name; - }).catch(error => { - // GitHub rate-limits are by IP address and runners can share IPs. - // This mostly effects macOS where the pool of runners seems limited. - // Fallback to a known version if API access is rate limited. - core.warning(`${error.message} + try { + var version = core.getInput('version'); + var requestedVersion = version; + + if ((!version) || (version.toLowerCase() === 'latest')) { + version = await octokit.repos.getLatestRelease({ + owner: 'digitalocean', + repo: 'doctl' + }).then(result => { + return result.data.name; + }).catch(error => { + core.warning(`${error.message}\nFailed to retrieve latest version; falling back to: ${fallbackVersion}`); + return fallbackVersion; + }); + requestedVersion = 'latest'; + } + if (version.charAt(0) === 'v') { + version = version.substr(1); + } -Failed to retrieve latest version; falling back to: ${fallbackVersion}`); - return fallbackVersion; - }); - requestedVersion = 'latest'; - } - if (version.charAt(0) === 'v') { - version = version.substr(1); - } + var path = tc.find("doctl", version); + var actualVersion = version; + + if (!path) { + try { + + const installPath = await downloadDoctl(version, process.platform, process.arch); + path = await tc.cacheDir(installPath, 'doctl', version); + actualVersion = version; + } catch (error) { + + core.warning(`Failed to download doctl v${version}, trying fallback versions. Details: ${error}`); + const result = await downloadDoctlWithFallback(requestedVersion, process.platform, process.arch); + path = await tc.cacheDir(result.installPath, 'doctl', result.version); + actualVersion = result.version; + } + } + + core.addPath(path); + core.info(`>>> doctl version v${actualVersion} installed to ${path}`); - var path = tc.find("doctl", version); - var actualVersion = version; - - if (!path) { - try { - // Try the requested/latest version first - const installPath = await downloadDoctl(version, process.platform, process.arch); - path = await tc.cacheDir(installPath, 'doctl', version); - actualVersion = version; - } catch (error) { - // If the download fails (e.g., missing artifacts), try fallback versions - core.warning(`Failed to download doctl v${version}, trying fallback versions`); - const result = await downloadDoctlWithFallback(requestedVersion, process.platform, process.arch); - path = await tc.cacheDir(result.installPath, 'doctl', result.version); - actualVersion = result.version; + var no_auth = core.getInput('no_auth'); + if (no_auth.toLowerCase() === 'true') { + core.info('>>> Skipping doctl auth'); + return; } - } - - core.addPath(path); - core.info(`>>> doctl version v${actualVersion} installed to ${path}`); - // Skip authentication if requested - // for workflows where auth isn't necessary (e.g. doctl app spec validate --schema-only) - var no_auth = core.getInput('no_auth'); - if (no_auth.toLowerCase() === 'true') { - core.info('>>> Skipping doctl auth'); - return; + var token = core.getInput('token', { required: true }); + core.setSecret(token); + await exec.exec('doctl auth init -t', [token]); + core.info('>>> Successfully logged into doctl'); + } catch (error) { + core.setFailed(error.message); } - - var token = core.getInput('token', { required: true }); - core.setSecret(token); - await exec.exec('doctl auth init -t', [token]); - core.info('>>> Successfully logged into doctl'); - } - catch (error) { - core.setFailed(error.message); - } } run(); diff --git a/package.json b/package.json index 91be1f2..57a46c0 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,18 @@ }, "devDependencies": { "@vercel/ncc": "^0.36.1", - "eslint": "^9.15.0" + "eslint": "^9.37.0" }, "scripts": { "lint": "eslint main.js", "test": "npm install; npm run lint", "package": "ncc build main.js -o dist" }, + "eslintConfig": { + "parserOptions": { + "ecmaVersion": 2019 + } + }, "repository": { "type": "git", "url": "git+https://github.com/digitalocean/action-doctl.git"