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

Add mirror support to OPA download #31

Merged
merged 1 commit into from
Mar 25, 2024
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 @@ -13,6 +13,10 @@ inputs:
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 }}'
required: false
mirror:
description: Set to the URL of the mirror you should download from. Defaults to https://github.com. Not available for latest or edge versions.
default: https://github.com
required: false
runs:
using: node20
main: dist/index.js
10 changes: 7 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17009,10 +17009,13 @@ function maybeStatic(filename) {
const staticBinary = core.getInput('static');
return staticBinary === 'true' ? `${filename}_static` : filename;
}
function getDownloadObject(version) {
function getDownloadObject(version, mirror) {
let vsn = `v${version}`;
let github = true;
if (version === 'latest' || version === 'edge') {
if (mirror !== 'https://github.com') {
core.warning("Latest or edge versions not supported when mirror is set");
}
vsn = version;
github = false;
}
Expand All @@ -17022,7 +17025,7 @@ function getDownloadObject(version) {
const binaryName = platform === 'win32' ? `${filename}.exe` : maybeStatic(filename);
let url;
if (github) {
url = `https://github.com/open-policy-agent/opa/releases/download/${vsn}/${binaryName}`;
url = `${mirror}/open-policy-agent/opa/releases/download/${vsn}/${binaryName}`;
}
else {
url = `https://www.openpolicyagent.org/downloads/${vsn}/${binaryName}`;
Expand Down Expand Up @@ -17100,8 +17103,9 @@ function setup() {
try {
// Get version of tool to be installed
const version = yield getVersion();
const mirror = core.getInput('mirror');
// Download the specific version of the tool, e.g. as a tarball/zipball
const download = getDownloadObject(version);
const download = getDownloadObject(version, mirror);
const pathToCLI = fs.mkdtempSync(path.join(os.tmpdir(), 'tmp'));
yield tc.downloadTool(download.url, path.join(pathToCLI, download.binaryName));
// Make the downloaded file executable
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ function maybeStatic(filename: string): string {
return staticBinary === 'true' ? `${filename}_static` : filename;
}

function getDownloadObject(version: string): {
function getDownloadObject(version: string, mirror: string): {
url: string;
binaryName: string;
} {
let vsn = `v${version}`;
let github = true;
if (version === 'latest' || version === 'edge') {
if (mirror !== 'https://github.com') {
core.warning("Latest or edge versions not supported when mirror is set")
}
vsn = version;
github = false;
}
Expand All @@ -52,7 +55,7 @@ function getDownloadObject(version: string): {

let url: string;
if (github) {
url = `https://github.com/open-policy-agent/opa/releases/download/${vsn}/${binaryName}`;
url = `${mirror}/open-policy-agent/opa/releases/download/${vsn}/${binaryName}`;
} else {
url = `https://www.openpolicyagent.org/downloads/${vsn}/${binaryName}`;
}
Expand Down Expand Up @@ -128,8 +131,9 @@ async function setup(): Promise<void> {
try {
// Get version of tool to be installed
const version = await getVersion();
const mirror = core.getInput('mirror')
// Download the specific version of the tool, e.g. as a tarball/zipball
const download = getDownloadObject(version);
const download = getDownloadObject(version, mirror);
const pathToCLI = fs.mkdtempSync(path.join(os.tmpdir(), 'tmp'));

await tc.downloadTool(
Expand Down