Skip to content

Commit

Permalink
Merge pull request #24 from simplebet/main
Browse files Browse the repository at this point in the history
Support static binary versions
  • Loading branch information
tim775 authored Jun 13, 2023
2 parents 7e820d3 + 16e9bc4 commit 6f182ee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
description: Version of Open Policy Agent CLI to install. Semver Ranges (https://www.npmjs.com/package/semver#ranges) are supported.
required: false
default: latest
static:
description: Set to true to use the static binary version. Defaults to false. Not available for Win32
required: false
default: 'false'
github-token:
description: 'The GitHub access token (e.g. secrets.GITHUB_TOKEN) used to get the list of OPA CLI versions. This defaults to {{ github.token }}.'
default: '${{ github.token }}'
Expand Down
8 changes: 7 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17003,6 +17003,12 @@ function mapOS(os) {
};
return mappings[os] || os;
}
// append static to the filename if requesting the static binary
// opa_linux_arm64_static
function maybeStatic(filename) {
const staticBinary = core.getInput('static');
return staticBinary === 'true' ? `${filename}_static` : filename;
}
function getDownloadObject(version) {
let vsn = `v${version}`;
let github = true;
Expand All @@ -17013,7 +17019,7 @@ function getDownloadObject(version) {
const platform = os.platform();
// opa_darwin_amd64
const filename = `opa_${mapOS(platform)}_${mapArch(os.arch())}`;
const binaryName = platform === 'win32' ? `${filename}.exe` : filename;
const binaryName = platform === 'win32' ? `${filename}.exe` : maybeStatic(filename);
let url;
if (github) {
url = `https://github.com/open-policy-agent/opa/releases/download/${vsn}/${binaryName}`;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ function mapOS(os: string): string {
return mappings[os] || os;
}

// append static to the filename if requesting the static binary
// opa_linux_arm64_static
function maybeStatic(filename: string): string {
const staticBinary = core.getInput('static')

return staticBinary === 'true' ? `${filename}_static` : filename;
}

function getDownloadObject(version: string): {
url: string;
binaryName: string;
Expand All @@ -37,9 +45,10 @@ function getDownloadObject(version: string): {
}

const platform = os.platform();

// opa_darwin_amd64
const filename = `opa_${mapOS(platform)}_${mapArch(os.arch())}`;
const binaryName = platform === 'win32' ? `${filename}.exe` : filename;
const binaryName = platform === 'win32' ? `${filename}.exe` : maybeStatic(filename);

let url: string;
if (github) {
Expand Down Expand Up @@ -122,6 +131,7 @@ async function setup(): Promise<void> {
// Download the specific version of the tool, e.g. as a tarball/zipball
const download = getDownloadObject(version);
const pathToCLI = fs.mkdtempSync(path.join(os.tmpdir(), 'tmp'));

await tc.downloadTool(
download.url,
path.join(pathToCLI, download.binaryName)
Expand Down

0 comments on commit 6f182ee

Please sign in to comment.