Skip to content

Commit

Permalink
Add support for more platform (crazy-max/ghaction-docker-buildx#223)
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Sep 5, 2020
1 parent 54edbcd commit 0fc9dc8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
36 changes: 30 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 31 additions & 6 deletions src/buildx.ts
Expand Up @@ -92,13 +92,12 @@ export async function install(inputVersion: string, dockerConfigHome: string): P
}

async function download(version: string): Promise<string> {
version = semver.clean(version) || '';
const platform: string = context.osPlat == 'win32' ? 'windows' : context.osPlat;
const ext: string = context.osPlat == 'win32' ? '.exe' : '';
const filename: string = util.format('buildx-v%s.%s-amd64%s', version, platform, ext);
const targetFile: string = context.osPlat == 'win32' ? 'docker-buildx.exe' : 'docker-buildx';

const downloadUrl = util.format('https://github.com/docker/buildx/releases/download/v%s/%s', version, filename);
const downloadUrl = util.format(
'https://github.com/docker/buildx/releases/download/v%s/%s',
version,
await filename(version)
);
let downloadPath: string;

try {
Expand All @@ -111,3 +110,29 @@ async function download(version: string): Promise<string> {

return await tc.cacheFile(downloadPath, targetFile, 'buildx', version);
}

async function filename(version: string): Promise<string> {
let arch: string;
switch (context.osArch) {
case 'x64': {
arch = 'amd64';
break;
}
case 'ppc64': {
arch = 'ppc64le';
break;
}
case 'arm': {
const arm_version = (process.config.variables as any).arm_version;
arch = arm_version ? 'arm-v' + arm_version : 'arm';
break;
}
default: {
arch = context.osArch;
break;
}
}
const platform: string = context.osPlat == 'win32' ? 'windows' : context.osPlat;
const ext: string = context.osPlat == 'win32' ? '.exe' : '';
return util.format('buildx-v%s.%s-%s%s', version, platform, arch, ext);
}
1 change: 1 addition & 0 deletions src/context.ts
Expand Up @@ -2,6 +2,7 @@ import * as os from 'os';
import * as core from '@actions/core';

export const osPlat: string = os.platform();
export const osArch: string = os.arch();

export interface Inputs {
version: string;
Expand Down

0 comments on commit 0fc9dc8

Please sign in to comment.