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 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
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',
],
};
31 changes: 26 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,28 @@ export default class ComponentDetection {
}

private static async getLatestReleaseURL(): Promise<string> {
const githubToken = core.getInput('token') || process.env.GITHUB_TOKEN || "";
const octokit = github.getOctokit(githubToken);
let githubToken = core.getInput('token') || process.env.GITHUB_TOKEN || "";

const githubAPIURL = 'https://api.github.com'

let ghesMode = github.context.apiUrl != githubAPIURL;
// If the we're running in GHES, then use an empty string as the token
if (ghesMode) {
githubToken = "";
}
const octokit = new Octokit({ auth: githubToken, baseUrl: githubAPIURL, 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 " + githubAPIURL);

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 +173,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