Skip to content

Commit

Permalink
Add support for additional architectures and os (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
doriable authored Sep 8, 2021
1 parent d9a911b commit b7c6f76
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
6 changes: 3 additions & 3 deletions dist/main.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/main.js.map

Large diffs are not rendered by default.

53 changes: 39 additions & 14 deletions src/buf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,33 @@ export async function getBuf(version: string): Promise<string|Error> {
return downloadURL
}

let cacheDir = "";
core.info(`Downloading buf version "${version}" from ${downloadURL}`);
const downloadPath = await tc.downloadTool(downloadURL);
core.info(`Successfully downloaded buf version "${version}" from ${downloadURL}`);
if (downloadURL.endsWith('.tar.gz')){
const downloadPath = await tc.downloadTool(downloadURL);
core.info(`Successfully downloaded buf version "${version}" from ${downloadURL}`);

core.info('Extracting buf...');
const extractPath = await tc.extractTar(downloadPath);
core.info(`Successfully extracted buf to ${extractPath}`);
core.info('Extracting buf...');
const extractPath = await tc.extractTar(downloadPath);
core.info(`Successfully extracted buf to ${extractPath}`);

core.info('Adding buf to the cache...');
const cacheDir = await tc.cacheDir(
path.join(extractPath, 'buf'),
'buf',
version,
os.arch()
);
core.info(`Successfully cached buf to ${cacheDir}`);
core.info('Adding buf to the cache...');
cacheDir = await tc.cacheDir(
path.join(extractPath, 'buf'),
'buf',
version,
os.arch()
);
} else {
// For Windows, we only download the .exe for `buf` CLI becasue we do not create `.tar.gz`
// bundles for Windows releases.
const downloadPath = await tc.downloadTool(downloadURL, 'C:\\Users\\runneradmin\\buf-download\\buf.exe');
core.info(`Successfully downloaded buf version "${version}" from ${downloadURL} to ${downloadPath}`);

core.info('Adding buf to the cache...');
cacheDir = await tc.cacheDir(path.dirname(downloadPath), 'buf', version, os.arch());
}
core.info(`Successfully cached buf to ${cacheDir}`);
return cacheDir;
}

Expand All @@ -66,6 +76,9 @@ async function getDownloadURL(version: string): Promise<string|Error> {
case 'x64':
architecture = 'x86_64';
break;
case 'arm64':
architecture = 'arm64';
break;
default:
return {
message: `The "${os.arch()}" architecture is not supported with a Buf release.`
Expand All @@ -78,14 +91,26 @@ async function getDownloadURL(version: string): Promise<string|Error> {
case 'linux':
platform = 'Linux';
break;
case 'darwin':
platform = 'Darwin';
break;
case 'win32':
platform = 'Windows';
break;
default:
return {
message: `The "${os.platform()}" platform is not supported with a Buf release.`
};
}
// The asset name is determined by the buf release structure found at:
// https://github.com/bufbuild/buf/blob/8255257bd94c9f1b5faa27242211c5caad05be79/make/buf/scripts/release.bash#L102
const assetName = `buf-${platform}-${architecture}.tar.gz`
let assetName = '';
// For Windows, we only download the .exe for `buf` CLI
if (platform === 'Windows') {
assetName = `buf-${platform}-${architecture}.exe`
} else {
assetName = `buf-${platform}-${architecture}.tar.gz`
}
const octokit = new Octokit();
const {data: releases} = await octokit.request(
'GET /repos/{owner}/{repo}/releases',
Expand Down
10 changes: 8 additions & 2 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import cp from 'child_process';
import * as os from 'os';
import * as path from 'path';
import * as core from '@actions/core';
import * as io from '@actions/io';
Expand Down Expand Up @@ -54,8 +55,13 @@ async function runSetup(): Promise<null|Error> {
}

core.info('Adding buf binary to PATH');
core.addPath(path.join(installDir, 'bin'));
const binaryPath = await io.which('buf', true);
let binaryPath = '';
if (os.platform() === 'win32') {
core.addPath(installDir);
} else {
core.addPath(path.join(installDir, 'bin'));
}
binaryPath = await io.which('buf', true);
if (binaryPath === '') {
return {
message: 'buf was not found on PATH'
Expand Down

0 comments on commit b7c6f76

Please sign in to comment.