diff --git a/README.md b/README.md index 07bca54..6382b1c 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ steps: - uses: actions/setup-java@v4 - uses: antoniovazquezblanco/setup-ghidra@master with: + auth_token: ${{ secrets.GITHUB_TOKEN }} version: ${{ matrix.ghidra }} - name: Build something with Ghidra ${{ matrix.version }} @@ -68,4 +69,7 @@ For a full reference of action parameters see [action.yml](action.yml) # Version spec to use. Please use SemVer notation. It also accepts the # 'latest' alias to download the latest version available. version: 'latest' + + # Github authentication token to avoid API limiting. + version: ${{ secrets.GITHUB_TOKEN }} ``` diff --git a/action.yml b/action.yml index 007638c..4a4df38 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,9 @@ inputs: version: description: 'Ghidra version.' default: 'latest' + auth_token: + description: 'GitHub token for authentication.' + default: '' runs: using: 'node20' diff --git a/dist/index.js b/dist/index.js index c568ce9..495e0cb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1729,6 +1729,259 @@ class ExecState extends events.EventEmitter { /***/ }), +/***/ 4087: +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Context = void 0; +const fs_1 = __nccwpck_require__(7147); +const os_1 = __nccwpck_require__(2037); +class Context { + /** + * Hydrate the context from the environment + */ + constructor() { + var _a, _b, _c; + this.payload = {}; + if (process.env.GITHUB_EVENT_PATH) { + if ((0, fs_1.existsSync)(process.env.GITHUB_EVENT_PATH)) { + this.payload = JSON.parse((0, fs_1.readFileSync)(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' })); + } + else { + const path = process.env.GITHUB_EVENT_PATH; + process.stdout.write(`GITHUB_EVENT_PATH ${path} does not exist${os_1.EOL}`); + } + } + this.eventName = process.env.GITHUB_EVENT_NAME; + this.sha = process.env.GITHUB_SHA; + this.ref = process.env.GITHUB_REF; + this.workflow = process.env.GITHUB_WORKFLOW; + this.action = process.env.GITHUB_ACTION; + this.actor = process.env.GITHUB_ACTOR; + this.job = process.env.GITHUB_JOB; + this.runNumber = parseInt(process.env.GITHUB_RUN_NUMBER, 10); + this.runId = parseInt(process.env.GITHUB_RUN_ID, 10); + this.apiUrl = (_a = process.env.GITHUB_API_URL) !== null && _a !== void 0 ? _a : `https://api.github.com`; + this.serverUrl = (_b = process.env.GITHUB_SERVER_URL) !== null && _b !== void 0 ? _b : `https://github.com`; + this.graphqlUrl = + (_c = process.env.GITHUB_GRAPHQL_URL) !== null && _c !== void 0 ? _c : `https://api.github.com/graphql`; + } + get issue() { + const payload = this.payload; + return Object.assign(Object.assign({}, this.repo), { number: (payload.issue || payload.pull_request || payload).number }); + } + get repo() { + if (process.env.GITHUB_REPOSITORY) { + const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); + return { owner, repo }; + } + if (this.payload.repository) { + return { + owner: this.payload.repository.owner.login, + repo: this.payload.repository.name + }; + } + throw new Error("context.repo requires a GITHUB_REPOSITORY environment variable like 'owner/repo'"); + } +} +exports.Context = Context; +//# sourceMappingURL=context.js.map + +/***/ }), + +/***/ 5438: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getOctokit = exports.context = void 0; +const Context = __importStar(__nccwpck_require__(4087)); +const utils_1 = __nccwpck_require__(3030); +exports.context = new Context.Context(); +/** + * Returns a hydrated octokit ready to use for GitHub Actions + * + * @param token the repo PAT or GITHUB_TOKEN + * @param options other options to set + */ +function getOctokit(token, options, ...additionalPlugins) { + const GitHubWithPlugins = utils_1.GitHub.plugin(...additionalPlugins); + return new GitHubWithPlugins((0, utils_1.getOctokitOptions)(token, options)); +} +exports.getOctokit = getOctokit; +//# sourceMappingURL=github.js.map + +/***/ }), + +/***/ 7914: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getApiBaseUrl = exports.getProxyFetch = exports.getProxyAgentDispatcher = exports.getProxyAgent = exports.getAuthString = void 0; +const httpClient = __importStar(__nccwpck_require__(6255)); +const undici_1 = __nccwpck_require__(1773); +function getAuthString(token, options) { + if (!token && !options.auth) { + throw new Error('Parameter token or opts.auth is required'); + } + else if (token && options.auth) { + throw new Error('Parameters token and opts.auth may not both be specified'); + } + return typeof options.auth === 'string' ? options.auth : `token ${token}`; +} +exports.getAuthString = getAuthString; +function getProxyAgent(destinationUrl) { + const hc = new httpClient.HttpClient(); + return hc.getAgent(destinationUrl); +} +exports.getProxyAgent = getProxyAgent; +function getProxyAgentDispatcher(destinationUrl) { + const hc = new httpClient.HttpClient(); + return hc.getAgentDispatcher(destinationUrl); +} +exports.getProxyAgentDispatcher = getProxyAgentDispatcher; +function getProxyFetch(destinationUrl) { + const httpDispatcher = getProxyAgentDispatcher(destinationUrl); + const proxyFetch = (url, opts) => __awaiter(this, void 0, void 0, function* () { + return (0, undici_1.fetch)(url, Object.assign(Object.assign({}, opts), { dispatcher: httpDispatcher })); + }); + return proxyFetch; +} +exports.getProxyFetch = getProxyFetch; +function getApiBaseUrl() { + return process.env['GITHUB_API_URL'] || 'https://api.github.com'; +} +exports.getApiBaseUrl = getApiBaseUrl; +//# sourceMappingURL=utils.js.map + +/***/ }), + +/***/ 3030: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getOctokitOptions = exports.GitHub = exports.defaults = exports.context = void 0; +const Context = __importStar(__nccwpck_require__(4087)); +const Utils = __importStar(__nccwpck_require__(7914)); +// octokit + plugins +const core_1 = __nccwpck_require__(6762); +const plugin_rest_endpoint_methods_1 = __nccwpck_require__(3044); +const plugin_paginate_rest_1 = __nccwpck_require__(4193); +exports.context = new Context.Context(); +const baseUrl = Utils.getApiBaseUrl(); +exports.defaults = { + baseUrl, + request: { + agent: Utils.getProxyAgent(baseUrl), + fetch: Utils.getProxyFetch(baseUrl) + } +}; +exports.GitHub = core_1.Octokit.plugin(plugin_rest_endpoint_methods_1.restEndpointMethods, plugin_paginate_rest_1.paginateRest).defaults(exports.defaults); +/** + * Convience function to correctly format Octokit Options to pass into the constructor. + * + * @param token the repo PAT or GITHUB_TOKEN + * @param options other options to set + */ +function getOctokitOptions(token, options) { + const opts = Object.assign({}, options || {}); // Shallow clone - don't mutate the object provided by the caller + // Auth + const auth = Utils.getAuthString(token, opts); + if (auth) { + opts.auth = auth; + } + return opts; +} +exports.getOctokitOptions = getOctokitOptions; +//# sourceMappingURL=utils.js.map + +/***/ }), + /***/ 5526: /***/ (function(__unused_webpack_module, exports) { @@ -5239,66 +5492,6 @@ paginateRest.VERSION = VERSION; 0 && (0); -/***/ }), - -/***/ 8883: -/***/ ((module) => { - -"use strict"; - -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// pkg/dist-src/index.js -var dist_src_exports = {}; -__export(dist_src_exports, { - requestLog: () => requestLog -}); -module.exports = __toCommonJS(dist_src_exports); - -// pkg/dist-src/version.js -var VERSION = "4.0.0"; - -// pkg/dist-src/index.js -function requestLog(octokit) { - octokit.hook.wrap("request", (request, options) => { - octokit.log.debug("request", options); - const start = Date.now(); - const requestOptions = octokit.request.endpoint.parse(options); - const path = requestOptions.url.replace(options.baseUrl, ""); - return request(options).then((response) => { - octokit.log.info( - `${requestOptions.method} ${path} - ${response.status} in ${Date.now() - start}ms` - ); - return response; - }).catch((error) => { - octokit.log.info( - `${requestOptions.method} ${path} - ${error.status} in ${Date.now() - start}ms` - ); - throw error; - }); - }); -} -requestLog.VERSION = VERSION; -// Annotate the CommonJS export names for ESM import in node: -0 && (0); - - /***/ }), /***/ 3044: @@ -7731,57 +7924,6 @@ var request = withDefaults(import_endpoint.endpoint, { 0 && (0); -/***/ }), - -/***/ 5375: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -"use strict"; - -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// pkg/dist-src/index.js -var dist_src_exports = {}; -__export(dist_src_exports, { - Octokit: () => Octokit -}); -module.exports = __toCommonJS(dist_src_exports); -var import_core = __nccwpck_require__(6762); -var import_plugin_request_log = __nccwpck_require__(8883); -var import_plugin_paginate_rest = __nccwpck_require__(4193); -var import_plugin_rest_endpoint_methods = __nccwpck_require__(3044); - -// pkg/dist-src/version.js -var VERSION = "20.0.2"; - -// pkg/dist-src/index.js -var Octokit = import_core.Octokit.plugin( - import_plugin_request_log.requestLog, - import_plugin_rest_endpoint_methods.legacyRestEndpointMethods, - import_plugin_paginate_rest.paginateRest -).defaults({ - userAgent: `octokit-rest.js/${VERSION}` -}); -// Annotate the CommonJS export names for ESM import in node: -0 && (0); - - /***/ }), /***/ 3682: @@ -32627,8 +32769,8 @@ function wrappy (fn, cb) { /***/ }), -/***/ 978: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { +/***/ 6932: +/***/ (function(__unused_webpack_module, exports) { "use strict"; @@ -32643,9 +32785,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getReleaseUrlByVersion = void 0; -const rest_1 = __nccwpck_require__(5375); -const octokit = new rest_1.Octokit(); -function getReleaseDownloadUrl(owner, repo, release_id) { +function getReleaseDownloadUrl(octokit, owner, repo, release_id) { return __awaiter(this, void 0, void 0, function* () { let assets = yield octokit.rest.repos.listReleaseAssets({ owner: owner, @@ -32655,7 +32795,7 @@ function getReleaseDownloadUrl(owner, repo, release_id) { return assets.data[0].browser_download_url; }); } -function getReleaseUrlByTag(owner, repo, tag) { +function getReleaseUrlByTag(octokit, owner, repo, tag) { return __awaiter(this, void 0, void 0, function* () { let tagName = `Ghidra_${tag}_build`; let response = yield octokit.rest.repos.getReleaseByTag({ @@ -32666,10 +32806,10 @@ function getReleaseUrlByTag(owner, repo, tag) { if (response.status != 200) { throw new Error(`Could not find tag '${tagName}' in repo '${repo}' by the owner '${owner}'! Response status was ${response.status}...`); } - return getReleaseDownloadUrl(owner, repo, response.data.id); + return getReleaseDownloadUrl(octokit, owner, repo, response.data.id); }); } -function getLatestReleaseUrl(owner, repo) { +function getLatestReleaseUrl(octokit, owner, repo) { return __awaiter(this, void 0, void 0, function* () { let response = yield octokit.rest.repos.getLatestRelease({ owner: owner, @@ -32678,16 +32818,16 @@ function getLatestReleaseUrl(owner, repo) { if (response.status != 200) { throw new Error(`Could not get the latest release from repo '${repo}' by the owner '${owner}'! Response status was ${response.status}...`); } - return getReleaseDownloadUrl(owner, repo, response.data.id); + return getReleaseDownloadUrl(octokit, owner, repo, response.data.id); }); } -function getReleaseUrlByVersion(owner, repo, version) { +function getReleaseUrlByVersion(octokit, owner, repo, version) { return __awaiter(this, void 0, void 0, function* () { if (version == "latest") { - return getLatestReleaseUrl(owner, repo); + return getLatestReleaseUrl(octokit, owner, repo); } else { - return getReleaseUrlByTag(owner, repo, version); + return getReleaseUrlByTag(octokit, owner, repo, version); } }); } @@ -32817,7 +32957,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", ({ value: true })); const core = __importStar(__nccwpck_require__(2186)); -const github = __importStar(__nccwpck_require__(978)); +const github = __importStar(__nccwpck_require__(5438)); +const github_helper = __importStar(__nccwpck_require__(6932)); const installer = __importStar(__nccwpck_require__(2574)); function run() { return __awaiter(this, void 0, void 0, function* () { @@ -32827,10 +32968,12 @@ function run() { let owner = core.getInput("owner"); let repo = core.getInput("repo"); let version = core.getInput("version"); + let auth_token = core.getInput("auth_token"); // First obtain a valid download url.. if (!download_url) { core.debug("Using owner, repo and version inputs to locate a release..."); - download_url = yield github.getReleaseUrlByVersion(owner, repo, version); + const octokit = github.getOctokit(auth_token); + download_url = yield github_helper.getReleaseUrlByVersion(octokit, owner, repo, version); } else { core.debug("The download_url input was provided; ignoring owner, repo and version inputs..."); diff --git a/package-lock.json b/package-lock.json index 74b7f47..0ca7bbf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", + "@actions/github": "^6.0.0", "@actions/tool-cache": "^2.0.1", "@octokit/rest": "^20.0.2" }, @@ -39,6 +40,17 @@ "@actions/io": "^1.0.1" } }, + "node_modules/@actions/github": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-6.0.0.tgz", + "integrity": "sha512-alScpSVnYmjNEXboZjarjukQEzgCRmjMv6Xj47fsdnqGS73bjJNDpiiXmp8jr0UZLdUB6d9jW63IcmddUP+l0g==", + "dependencies": { + "@actions/http-client": "^2.2.0", + "@octokit/core": "^5.0.1", + "@octokit/plugin-paginate-rest": "^9.0.0", + "@octokit/plugin-rest-endpoint-methods": "^10.0.0" + } + }, "node_modules/@actions/http-client": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.0.tgz", diff --git a/package.json b/package.json index 5583cde..f6377eb 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "dependencies": { "@actions/core": "^1.10.1", + "@actions/github": "^6.0.0", "@actions/tool-cache": "^2.0.1", "@octokit/rest": "^20.0.2" } diff --git a/src/github.test.ts b/src/github_helper.test.ts similarity index 70% rename from src/github.test.ts rename to src/github_helper.test.ts index 0201ed6..f74c343 100644 --- a/src/github.test.ts +++ b/src/github_helper.test.ts @@ -1,7 +1,11 @@ -import * as github from "./github"; +import { Octokit } from "@octokit/rest"; +import * as github_helper from "./github_helper"; + +const octokit = new Octokit(); test("Verify Ghidra 10.4 download URL", async () => { - const url = await github.getReleaseUrlByVersion( + const url = await github_helper.getReleaseUrlByVersion( + octokit, "NationalSecurityAgency", "ghidra", "10.4", @@ -12,7 +16,8 @@ test("Verify Ghidra 10.4 download URL", async () => { }); test("Verify latest Ghidra URL", async () => { - const url = await github.getReleaseUrlByVersion( + const url = await github_helper.getReleaseUrlByVersion( + octokit, "NationalSecurityAgency", "ghidra", "latest", @@ -27,7 +32,8 @@ test("Verify latest Ghidra URL", async () => { test("Verify exception on wrong version", async () => { let thrown = false; try { - const url = await github.getReleaseUrlByVersion( + const url = await github_helper.getReleaseUrlByVersion( + octokit, "NationalSecurityAgency", "ghidra", "dummyversion", diff --git a/src/github.ts b/src/github_helper.ts similarity index 73% rename from src/github.ts rename to src/github_helper.ts index fe44c59..36393c9 100644 --- a/src/github.ts +++ b/src/github_helper.ts @@ -1,8 +1,7 @@ -import { Octokit } from "@octokit/rest"; - -const octokit = new Octokit(); +import { GitHub } from "@actions/github/lib/utils"; async function getReleaseDownloadUrl( + octokit: InstanceType, owner: string, repo: string, release_id: number, @@ -16,6 +15,7 @@ async function getReleaseDownloadUrl( } async function getReleaseUrlByTag( + octokit: InstanceType, owner: string, repo: string, tag: string, @@ -31,10 +31,11 @@ async function getReleaseUrlByTag( `Could not find tag '${tagName}' in repo '${repo}' by the owner '${owner}'! Response status was ${response.status}...`, ); } - return getReleaseDownloadUrl(owner, repo, response.data.id); + return getReleaseDownloadUrl(octokit, owner, repo, response.data.id); } async function getLatestReleaseUrl( + octokit: InstanceType, owner: string, repo: string, ): Promise { @@ -47,17 +48,18 @@ async function getLatestReleaseUrl( `Could not get the latest release from repo '${repo}' by the owner '${owner}'! Response status was ${response.status}...`, ); } - return getReleaseDownloadUrl(owner, repo, response.data.id); + return getReleaseDownloadUrl(octokit, owner, repo, response.data.id); } export async function getReleaseUrlByVersion( + octokit: InstanceType, owner: string, repo: string, version: string, ) { if (version == "latest") { - return getLatestReleaseUrl(owner, repo); + return getLatestReleaseUrl(octokit, owner, repo); } else { - return getReleaseUrlByTag(owner, repo, version); + return getReleaseUrlByTag(octokit, owner, repo, version); } } diff --git a/src/installer.test.ts b/src/installer.test.ts index c3ee5f3..d7bf5d5 100644 --- a/src/installer.test.ts +++ b/src/installer.test.ts @@ -1,6 +1,7 @@ import path = require("path"); import io = require("@actions/io"); -import * as github from "./github"; +import { Octokit } from "@octokit/rest"; +import * as github_helper from "./github_helper"; import * as installer from "./installer"; import * as fs from "fs"; @@ -12,8 +13,11 @@ describe("Installer tests", () => { process.env["RUNNER_TOOL_CACHE"] = path.join(__dirname, "runner", "tools"); process.env["RUNNER_TEMP"] = path.join(__dirname, "runner", "temp"); + const octokit = new Octokit(); + // Get a valid URL for installation... - url = await github.getReleaseUrlByVersion( + url = await github_helper.getReleaseUrlByVersion( + octokit, "NationalSecurityAgency", "ghidra", "latest", diff --git a/src/setup-ghidra.ts b/src/setup-ghidra.ts index 151b2c6..d197af0 100644 --- a/src/setup-ghidra.ts +++ b/src/setup-ghidra.ts @@ -1,5 +1,6 @@ import * as core from "@actions/core"; -import * as github from "./github"; +import * as github from "@actions/github"; +import * as github_helper from "./github_helper"; import * as installer from "./installer"; async function run() { @@ -9,11 +10,18 @@ async function run() { let owner = core.getInput("owner"); let repo = core.getInput("repo"); let version = core.getInput("version"); + let auth_token = core.getInput("auth_token"); // First obtain a valid download url.. if (!download_url) { core.debug("Using owner, repo and version inputs to locate a release..."); - download_url = await github.getReleaseUrlByVersion(owner, repo, version); + const octokit = github.getOctokit(auth_token); + download_url = await github_helper.getReleaseUrlByVersion( + octokit, + owner, + repo, + version, + ); } else { core.debug( "The download_url input was provided; ignoring owner, repo and version inputs...",