Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parserOptions": {
"ecmaVersion": 2019
}
}
120 changes: 57 additions & 63 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}

Expand All @@ -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}`);
}
}

Expand All @@ -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;
}
}
Expand All @@ -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();
Expand Down
120 changes: 56 additions & 64 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading