Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support static binary versions #24

Merged
merged 1 commit into from
Jun 13, 2023
Merged
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
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