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 support for releaseServerUrl #70

Merged
merged 19 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 18 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
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ inputs:
detectorsFilter:
description: 'A comma separated list with the identifiers of the specific detectors to be used. This is meant to be used for testing purposes only.'
required: false
releaseServerUrl:
description: 'The baseUrl of the release server to use. If you set this, it should be set to `https://api.github.com`'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description is a bit confusing to me: Does it mean that https://api.github.com is the default value, in which case we should change the wording. I don't think it does now that I looked at the code.

Otherwise, if it means that https://api.github.com is the only possible valid value, then we should probably hardcode the url and use a boolean instead to trigger that option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is confusing. Let me figure that out and update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see what the original intent was and I rewrote it so that it should work without setting any configuration options. I'm going to try to test this in a real GHES instance to make sure.

required: false
runs:
using: 'node16'
main: 'dist/index.js'
Expand Down
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
};
29 changes: 24 additions & 5 deletions componentDetection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as github from '@actions/github'
import * as core from '@actions/core'
import { Octokit, App } from "octokit"
import {
PackageCache,
BuildTarget,
Expand Down Expand Up @@ -140,14 +141,26 @@ export default class ComponentDetection {
}

private static async getLatestReleaseURL(): Promise<string> {
const githubToken = core.getInput('token') || process.env.GITHUB_TOKEN || "";
const octokit = github.getOctokit(githubToken);
var githubToken = core.getInput('token') || process.env.GITHUB_TOKEN || "";
juxtin marked this conversation as resolved.
Show resolved Hide resolved

// If the releaseServerUrl is set, then use an empty string as the token
if (core.getInput('releaseServerUrl') != null) {
githubToken = "";
}
const serverUrl = core.getInput('releaseServerUrl') || github.context.apiUrl;
const octokit = new Octokit({ auth: githubToken, baseUrl: serverUrl, request: { fetch: fetch}, log: {
debug: core.debug,
info: core.info,
warn: core.warning,
error: core.error
}, });

const owner = "microsoft";
const repo = "component-detection";
core.debug("Attempting to download latest release from " + serverUrl);

const latestRelease = await octokit.rest.repos.getLatestRelease({
owner, repo
});
try {
const latestRelease = await octokit.request("GET /repos/{owner}/{repo}/releases/latest", {owner, repo});

var downloadURL: string = "";
const assetName = process.platform === "win32" ? "component-detection-win-x64.exe" : "component-detection-linux-x64";
Expand All @@ -158,6 +171,12 @@ export default class ComponentDetection {
});

return downloadURL;
} catch (error: any) {
core.error(error);
core.debug(error.message);
core.debug(error.stack);
throw new Error("Failed to download latest release");
}
}
}

Expand Down
Loading
Loading