Skip to content

Commit

Permalink
Support non-amd64 architechtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething committed Aug 23, 2023
1 parent 5462b7c commit 96b2d84
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 22 deletions.
54 changes: 43 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17455,25 +17455,57 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
const os = __nccwpck_require__(2037);
const core = __nccwpck_require__(2186);
const exec = __nccwpck_require__(1514);
const tc = __nccwpck_require__(7784);
const { Octokit } = __nccwpck_require__(5375);

const baseDownloadURL = "https://github.com/digitalocean/doctl/releases/download"
const fallbackVersion = "1.84.0"
const baseDownloadURL = "https://github.com/digitalocean/doctl/releases/download";
const fallbackVersion = "1.98.1";
const octokit = new Octokit();

async function downloadDoctl(version) {
if (process.platform === 'win32') {
const doctlDownload = await tc.downloadTool(`${baseDownloadURL}/v${version}/doctl-${version}-windows-amd64.zip`);
return tc.extractZip(doctlDownload);
async function downloadDoctl(version, osType, osMachine) {
var platform = 'linux';
var arch = 'amd64';
var extension = 'tar.gz';

switch (osType) {
case 'Darwin':
platform = 'darwin';
break;
case 'Windows_NT':
platform = 'windows';
extension = 'zip'
break;
case 'Linux':
platform = 'linux';
break;
default:
core.warning(`unknown platform: ${osType}; defaulting to ${platform}`);
break;
}
if (process.platform === 'darwin') {
const doctlDownload = await tc.downloadTool(`${baseDownloadURL}/v${version}/doctl-${version}-darwin-amd64.tar.gz`);
return tc.extractTar(doctlDownload);

switch (osMachine) {
case 'arm64':
arch = 'arm64';
break;
case 'x86_64':
arch = 'amd64';
break;
case 'i386':
case 'i686':
arch = '386';
break;
default:
core.warning(`unknown architecture: ${osMachine}; defaulting to ${arch}`);
break;
}
const doctlDownload = await tc.downloadTool(`${baseDownloadURL}/v${version}/doctl-${version}-linux-amd64.tar.gz`);

const downloadURL = `${baseDownloadURL}/v${version}/doctl-${version}-${platform}-${arch}.${extension}`;
core.debug(`doctl download url: ${downloadURL}`);
const doctlDownload = await tc.downloadTool(downloadURL);

return tc.extractTar(doctlDownload);
}

Expand Down Expand Up @@ -17502,7 +17534,7 @@ Failed to retrieve latest version; falling back to: ${fallbackVersion}`);

var path = tc.find("doctl", version);
if (!path) {
const installPath = await downloadDoctl(version);
const installPath = await downloadDoctl(version, os.type(), os.machine());
path = await tc.cacheDir(installPath, 'doctl', version);
}
core.addPath(path);
Expand Down
54 changes: 43 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
const os = require('os');
const core = require('@actions/core');
const exec = require('@actions/exec');
const tc = require('@actions/tool-cache');
const { Octokit } = require("@octokit/rest");

const baseDownloadURL = "https://github.com/digitalocean/doctl/releases/download"
const fallbackVersion = "1.84.0"
const baseDownloadURL = "https://github.com/digitalocean/doctl/releases/download";
const fallbackVersion = "1.98.1";
const octokit = new Octokit();

async function downloadDoctl(version) {
if (process.platform === 'win32') {
const doctlDownload = await tc.downloadTool(`${baseDownloadURL}/v${version}/doctl-${version}-windows-amd64.zip`);
return tc.extractZip(doctlDownload);
async function downloadDoctl(version, osType, osMachine) {
var platform = 'linux';
var arch = 'amd64';
var extension = 'tar.gz';

switch (osType) {
case 'Darwin':
platform = 'darwin';
break;
case 'Windows_NT':
platform = 'windows';
extension = 'zip'
break;
case 'Linux':
platform = 'linux';
break;
default:
core.warning(`unknown platform: ${osType}; defaulting to ${platform}`);
break;
}
if (process.platform === 'darwin') {
const doctlDownload = await tc.downloadTool(`${baseDownloadURL}/v${version}/doctl-${version}-darwin-amd64.tar.gz`);
return tc.extractTar(doctlDownload);

switch (osMachine) {
case 'arm64':
arch = 'arm64';
break;
case 'x86_64':
arch = 'amd64';
break;
case 'i386':
case 'i686':
arch = '386';
break;
default:
core.warning(`unknown architecture: ${osMachine}; defaulting to ${arch}`);
break;
}
const doctlDownload = await tc.downloadTool(`${baseDownloadURL}/v${version}/doctl-${version}-linux-amd64.tar.gz`);

const downloadURL = `${baseDownloadURL}/v${version}/doctl-${version}-${platform}-${arch}.${extension}`;
core.debug(`doctl download url: ${downloadURL}`);
const doctlDownload = await tc.downloadTool(downloadURL);

return tc.extractTar(doctlDownload);
}

Expand Down Expand Up @@ -45,7 +77,7 @@ Failed to retrieve latest version; falling back to: ${fallbackVersion}`);

var path = tc.find("doctl", version);
if (!path) {
const installPath = await downloadDoctl(version);
const installPath = await downloadDoctl(version, os.type(), os.machine());
path = await tc.cacheDir(installPath, 'doctl', version);
}
core.addPath(path);
Expand Down

0 comments on commit 96b2d84

Please sign in to comment.