From 5525cfc3e421cf6808a7d7f8dc558d59f2053b87 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Thu, 4 Sep 2025 18:37:21 +1000 Subject: [PATCH] feat: support ignoring an existing version of the binary As we move wallet-platform to self-hosted runners for tests we have a new error case where binaries from previous runs may exist on the runner. We need to allow the user to opt-in to ignoring such cases. This is non-breaking as existing behaviour is preserved. Ticket: DO-14423 --- action.yml | 3 + dist/index.js | 940 ++++++++++++++++++++------------------------------ src/index.ts | 12 + 3 files changed, 391 insertions(+), 564 deletions(-) diff --git a/action.yml b/action.yml index 7c39063..2551d19 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,9 @@ inputs: cache: description: Runtime switch to enable/disable caching because GitHub is debugging issues in their caching API default: false + ignore-existing-binary: + description: Skip download if the binary already exists at the destination + default: false runs: using: node20 diff --git a/dist/index.js b/dist/index.js index 1c79c80..09fd14c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -806,12 +806,12 @@ var require_lib = __commonJS({ throw new Error("Client has already been disposed."); } const parsedUrl = new URL(requestUrl); - let info2 = this._prepareRequest(verb, parsedUrl, headers); + let info3 = this._prepareRequest(verb, parsedUrl, headers); const maxTries = this._allowRetries && RetryableHttpVerbs.includes(verb) ? this._maxRetries + 1 : 1; let numTries = 0; let response; do { - response = yield this.requestRaw(info2, data); + response = yield this.requestRaw(info3, data); if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) { let authenticationHandler; for (const handler of this.handlers) { @@ -821,7 +821,7 @@ var require_lib = __commonJS({ } } if (authenticationHandler) { - return authenticationHandler.handleAuthentication(this, info2, data); + return authenticationHandler.handleAuthentication(this, info3, data); } else { return response; } @@ -844,8 +844,8 @@ var require_lib = __commonJS({ } } } - info2 = this._prepareRequest(verb, parsedRedirectUrl, headers); - response = yield this.requestRaw(info2, data); + info3 = this._prepareRequest(verb, parsedRedirectUrl, headers); + response = yield this.requestRaw(info3, data); redirectsRemaining--; } if (!response.message.statusCode || !HttpResponseRetryCodes.includes(response.message.statusCode)) { @@ -874,7 +874,7 @@ var require_lib = __commonJS({ * @param info * @param data */ - requestRaw(info2, data) { + requestRaw(info3, data) { return __awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { function callbackForResult(err, res) { @@ -886,7 +886,7 @@ var require_lib = __commonJS({ resolve(res); } } - this.requestRawWithCallback(info2, data, callbackForResult); + this.requestRawWithCallback(info3, data, callbackForResult); }); }); } @@ -896,12 +896,12 @@ var require_lib = __commonJS({ * @param data * @param onResult */ - requestRawWithCallback(info2, data, onResult) { + requestRawWithCallback(info3, data, onResult) { if (typeof data === "string") { - if (!info2.options.headers) { - info2.options.headers = {}; + if (!info3.options.headers) { + info3.options.headers = {}; } - info2.options.headers["Content-Length"] = Buffer.byteLength(data, "utf8"); + info3.options.headers["Content-Length"] = Buffer.byteLength(data, "utf8"); } let callbackCalled = false; function handleResult(err, res) { @@ -910,7 +910,7 @@ var require_lib = __commonJS({ onResult(err, res); } } - const req = info2.httpModule.request(info2.options, (msg) => { + const req = info3.httpModule.request(info3.options, (msg) => { const res = new HttpClientResponse(msg); handleResult(void 0, res); }); @@ -922,7 +922,7 @@ var require_lib = __commonJS({ if (socket) { socket.end(); } - handleResult(new Error(`Request timeout: ${info2.options.path}`)); + handleResult(new Error(`Request timeout: ${info3.options.path}`)); }); req.on("error", function(err) { handleResult(err); @@ -949,27 +949,27 @@ var require_lib = __commonJS({ return this._getAgent(parsedUrl); } _prepareRequest(method, requestUrl, headers) { - const info2 = {}; - info2.parsedUrl = requestUrl; - const usingSsl = info2.parsedUrl.protocol === "https:"; - info2.httpModule = usingSsl ? https : http; + const info3 = {}; + info3.parsedUrl = requestUrl; + const usingSsl = info3.parsedUrl.protocol === "https:"; + info3.httpModule = usingSsl ? https : http; const defaultPort = usingSsl ? 443 : 80; - info2.options = {}; - info2.options.host = info2.parsedUrl.hostname; - info2.options.port = info2.parsedUrl.port ? parseInt(info2.parsedUrl.port) : defaultPort; - info2.options.path = (info2.parsedUrl.pathname || "") + (info2.parsedUrl.search || ""); - info2.options.method = method; - info2.options.headers = this._mergeHeaders(headers); + info3.options = {}; + info3.options.host = info3.parsedUrl.hostname; + info3.options.port = info3.parsedUrl.port ? parseInt(info3.parsedUrl.port) : defaultPort; + info3.options.path = (info3.parsedUrl.pathname || "") + (info3.parsedUrl.search || ""); + info3.options.method = method; + info3.options.headers = this._mergeHeaders(headers); if (this.userAgent != null) { - info2.options.headers["user-agent"] = this.userAgent; + info3.options.headers["user-agent"] = this.userAgent; } - info2.options.agent = this._getAgent(info2.parsedUrl); + info3.options.agent = this._getAgent(info3.parsedUrl); if (this.handlers) { for (const handler of this.handlers) { - handler.prepareRequest(info2.options); + handler.prepareRequest(info3.options); } } - return info2; + return info3; } _mergeHeaders(headers) { if (this.requestOptions && this.requestOptions.headers) { @@ -2919,7 +2919,7 @@ var require_core = __commonJS({ return inputs.map((input) => input.trim()); } exports2.getMultilineInput = getMultilineInput; - function getBooleanInput(name, options) { + function getBooleanInput2(name, options) { const trueValue = ["true", "True", "TRUE"]; const falseValue = ["false", "False", "FALSE"]; const val = getInput2(name, options); @@ -2930,7 +2930,7 @@ var require_core = __commonJS({ throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${name} Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); } - exports2.getBooleanInput = getBooleanInput; + exports2.getBooleanInput = getBooleanInput2; function setOutput(name, value) { const filePath = process.env["GITHUB_OUTPUT"] || ""; if (filePath) { @@ -2969,10 +2969,10 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); (0, command_1.issueCommand)("notice", (0, utils_1.toCommandProperties)(properties), message instanceof Error ? message.toString() : message); } exports2.notice = notice; - function info2(message) { + function info3(message) { process.stdout.write(message + os.EOL); } - exports2.info = info2; + exports2.info = info3; function startGroup(name) { (0, command_1.issue)("group", name); } @@ -5023,390 +5023,104 @@ var require_tool_cache = __commonJS({ } }); -// node_modules/@octokit/plugin-paginate-rest/dist-node/index.js -var require_dist_node = __commonJS({ - "node_modules/@octokit/plugin-paginate-rest/dist-node/index.js"(exports2, module2) { +// node_modules/fast-content-type-parse/index.js +var require_fast_content_type_parse = __commonJS({ + "node_modules/fast-content-type-parse/index.js"(exports2, module2) { "use strict"; - var __defProp2 = Object.defineProperty; - var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; - var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __hasOwnProp2 = Object.prototype.hasOwnProperty; - var __export = (target, all) => { - for (var name in all) - __defProp2(target, name, { get: all[name], enumerable: true }); + var NullObject = function NullObject2() { }; - var __copyProps2 = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames2(from)) - if (!__hasOwnProp2.call(to, key) && key !== except) - __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); + NullObject.prototype = /* @__PURE__ */ Object.create(null); + var paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\v\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\v\u0020-\u00ff])*"|[!#$%&'*+.^\w`|~-]+) */gu; + var quotedPairRE = /\\([\v\u0020-\u00ff])/gu; + var mediaTypeRE = /^[!#$%&'*+.^\w|~-]+\/[!#$%&'*+.^\w|~-]+$/u; + var defaultContentType = { type: "", parameters: new NullObject() }; + Object.freeze(defaultContentType.parameters); + Object.freeze(defaultContentType); + function parse2(header) { + if (typeof header !== "string") { + throw new TypeError("argument header is required and must be a string"); + } + let index = header.indexOf(";"); + const type = index !== -1 ? header.slice(0, index).trim() : header.trim(); + if (mediaTypeRE.test(type) === false) { + throw new TypeError("invalid media type"); + } + const result = { + type: type.toLowerCase(), + parameters: new NullObject() + }; + if (index === -1) { + return result; } - return to; - }; - var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var dist_src_exports = {}; - __export(dist_src_exports, { - composePaginateRest: () => composePaginateRest, - isPaginatingEndpoint: () => isPaginatingEndpoint, - paginateRest: () => paginateRest2, - paginatingEndpoints: () => paginatingEndpoints - }); - module2.exports = __toCommonJS(dist_src_exports); - var VERSION8 = "11.3.1"; - function normalizePaginatedListResponse(response) { - if (!response.data) { - return { - ...response, - data: [] - }; + let key; + let match; + let value; + paramRE.lastIndex = index; + while (match = paramRE.exec(header)) { + if (match.index !== index) { + throw new TypeError("invalid parameter format"); + } + index += match[0].length; + key = match[1].toLowerCase(); + value = match[2]; + if (value[0] === '"') { + value = value.slice(1, value.length - 1); + quotedPairRE.test(value) && (value = value.replace(quotedPairRE, "$1")); + } + result.parameters[key] = value; } - const responseNeedsNormalization = "total_count" in response.data && !("url" in response.data); - if (!responseNeedsNormalization) - return response; - const incompleteResults = response.data.incomplete_results; - const repositorySelection = response.data.repository_selection; - const totalCount = response.data.total_count; - delete response.data.incomplete_results; - delete response.data.repository_selection; - delete response.data.total_count; - const namespaceKey = Object.keys(response.data)[0]; - const data = response.data[namespaceKey]; - response.data = data; - if (typeof incompleteResults !== "undefined") { - response.data.incomplete_results = incompleteResults; - } - if (typeof repositorySelection !== "undefined") { - response.data.repository_selection = repositorySelection; - } - response.data.total_count = totalCount; - return response; + if (index !== header.length) { + throw new TypeError("invalid parameter format"); + } + return result; } - function iterator(octokit, route, parameters) { - const options = typeof route === "function" ? route.endpoint(parameters) : octokit.request.endpoint(route, parameters); - const requestMethod = typeof route === "function" ? route : octokit.request; - const method = options.method; - const headers = options.headers; - let url = options.url; - return { - [Symbol.asyncIterator]: () => ({ - async next() { - if (!url) - return { done: true }; - try { - const response = await requestMethod({ method, url, headers }); - const normalizedResponse = normalizePaginatedListResponse(response); - url = ((normalizedResponse.headers.link || "").match( - /<([^>]+)>;\s*rel="next"/ - ) || [])[1]; - return { value: normalizedResponse }; - } catch (error3) { - if (error3.status !== 409) - throw error3; - url = ""; - return { - value: { - status: 200, - headers: {}, - data: [] - } - }; - } - } - }) + function safeParse2(header) { + if (typeof header !== "string") { + return defaultContentType; + } + let index = header.indexOf(";"); + const type = index !== -1 ? header.slice(0, index).trim() : header.trim(); + if (mediaTypeRE.test(type) === false) { + return defaultContentType; + } + const result = { + type: type.toLowerCase(), + parameters: new NullObject() }; - } - function paginate(octokit, route, parameters, mapFn) { - if (typeof parameters === "function") { - mapFn = parameters; - parameters = void 0; + if (index === -1) { + return result; } - return gather( - octokit, - [], - iterator(octokit, route, parameters)[Symbol.asyncIterator](), - mapFn - ); - } - function gather(octokit, results, iterator2, mapFn) { - return iterator2.next().then((result) => { - if (result.done) { - return results; - } - let earlyExit = false; - function done() { - earlyExit = true; + let key; + let match; + let value; + paramRE.lastIndex = index; + while (match = paramRE.exec(header)) { + if (match.index !== index) { + return defaultContentType; } - results = results.concat( - mapFn ? mapFn(result.value, done) : result.value.data - ); - if (earlyExit) { - return results; + index += match[0].length; + key = match[1].toLowerCase(); + value = match[2]; + if (value[0] === '"') { + value = value.slice(1, value.length - 1); + quotedPairRE.test(value) && (value = value.replace(quotedPairRE, "$1")); } - return gather(octokit, results, iterator2, mapFn); - }); - } - var composePaginateRest = Object.assign(paginate, { - iterator - }); - var paginatingEndpoints = [ - "GET /advisories", - "GET /app/hook/deliveries", - "GET /app/installation-requests", - "GET /app/installations", - "GET /assignments/{assignment_id}/accepted_assignments", - "GET /classrooms", - "GET /classrooms/{classroom_id}/assignments", - "GET /enterprises/{enterprise}/copilot/usage", - "GET /enterprises/{enterprise}/dependabot/alerts", - "GET /enterprises/{enterprise}/secret-scanning/alerts", - "GET /events", - "GET /gists", - "GET /gists/public", - "GET /gists/starred", - "GET /gists/{gist_id}/comments", - "GET /gists/{gist_id}/commits", - "GET /gists/{gist_id}/forks", - "GET /installation/repositories", - "GET /issues", - "GET /licenses", - "GET /marketplace_listing/plans", - "GET /marketplace_listing/plans/{plan_id}/accounts", - "GET /marketplace_listing/stubbed/plans", - "GET /marketplace_listing/stubbed/plans/{plan_id}/accounts", - "GET /networks/{owner}/{repo}/events", - "GET /notifications", - "GET /organizations", - "GET /orgs/{org}/actions/cache/usage-by-repository", - "GET /orgs/{org}/actions/permissions/repositories", - "GET /orgs/{org}/actions/runners", - "GET /orgs/{org}/actions/secrets", - "GET /orgs/{org}/actions/secrets/{secret_name}/repositories", - "GET /orgs/{org}/actions/variables", - "GET /orgs/{org}/actions/variables/{name}/repositories", - "GET /orgs/{org}/blocks", - "GET /orgs/{org}/code-scanning/alerts", - "GET /orgs/{org}/codespaces", - "GET /orgs/{org}/codespaces/secrets", - "GET /orgs/{org}/codespaces/secrets/{secret_name}/repositories", - "GET /orgs/{org}/copilot/billing/seats", - "GET /orgs/{org}/copilot/usage", - "GET /orgs/{org}/dependabot/alerts", - "GET /orgs/{org}/dependabot/secrets", - "GET /orgs/{org}/dependabot/secrets/{secret_name}/repositories", - "GET /orgs/{org}/events", - "GET /orgs/{org}/failed_invitations", - "GET /orgs/{org}/hooks", - "GET /orgs/{org}/hooks/{hook_id}/deliveries", - "GET /orgs/{org}/installations", - "GET /orgs/{org}/invitations", - "GET /orgs/{org}/invitations/{invitation_id}/teams", - "GET /orgs/{org}/issues", - "GET /orgs/{org}/members", - "GET /orgs/{org}/members/{username}/codespaces", - "GET /orgs/{org}/migrations", - "GET /orgs/{org}/migrations/{migration_id}/repositories", - "GET /orgs/{org}/organization-roles/{role_id}/teams", - "GET /orgs/{org}/organization-roles/{role_id}/users", - "GET /orgs/{org}/outside_collaborators", - "GET /orgs/{org}/packages", - "GET /orgs/{org}/packages/{package_type}/{package_name}/versions", - "GET /orgs/{org}/personal-access-token-requests", - "GET /orgs/{org}/personal-access-token-requests/{pat_request_id}/repositories", - "GET /orgs/{org}/personal-access-tokens", - "GET /orgs/{org}/personal-access-tokens/{pat_id}/repositories", - "GET /orgs/{org}/projects", - "GET /orgs/{org}/properties/values", - "GET /orgs/{org}/public_members", - "GET /orgs/{org}/repos", - "GET /orgs/{org}/rulesets", - "GET /orgs/{org}/rulesets/rule-suites", - "GET /orgs/{org}/secret-scanning/alerts", - "GET /orgs/{org}/security-advisories", - "GET /orgs/{org}/team/{team_slug}/copilot/usage", - "GET /orgs/{org}/teams", - "GET /orgs/{org}/teams/{team_slug}/discussions", - "GET /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments", - "GET /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments/{comment_number}/reactions", - "GET /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/reactions", - "GET /orgs/{org}/teams/{team_slug}/invitations", - "GET /orgs/{org}/teams/{team_slug}/members", - "GET /orgs/{org}/teams/{team_slug}/projects", - "GET /orgs/{org}/teams/{team_slug}/repos", - "GET /orgs/{org}/teams/{team_slug}/teams", - "GET /projects/columns/{column_id}/cards", - "GET /projects/{project_id}/collaborators", - "GET /projects/{project_id}/columns", - "GET /repos/{owner}/{repo}/actions/artifacts", - "GET /repos/{owner}/{repo}/actions/caches", - "GET /repos/{owner}/{repo}/actions/organization-secrets", - "GET /repos/{owner}/{repo}/actions/organization-variables", - "GET /repos/{owner}/{repo}/actions/runners", - "GET /repos/{owner}/{repo}/actions/runs", - "GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts", - "GET /repos/{owner}/{repo}/actions/runs/{run_id}/attempts/{attempt_number}/jobs", - "GET /repos/{owner}/{repo}/actions/runs/{run_id}/jobs", - "GET /repos/{owner}/{repo}/actions/secrets", - "GET /repos/{owner}/{repo}/actions/variables", - "GET /repos/{owner}/{repo}/actions/workflows", - "GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs", - "GET /repos/{owner}/{repo}/activity", - "GET /repos/{owner}/{repo}/assignees", - "GET /repos/{owner}/{repo}/branches", - "GET /repos/{owner}/{repo}/check-runs/{check_run_id}/annotations", - "GET /repos/{owner}/{repo}/check-suites/{check_suite_id}/check-runs", - "GET /repos/{owner}/{repo}/code-scanning/alerts", - "GET /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}/instances", - "GET /repos/{owner}/{repo}/code-scanning/analyses", - "GET /repos/{owner}/{repo}/codespaces", - "GET /repos/{owner}/{repo}/codespaces/devcontainers", - "GET /repos/{owner}/{repo}/codespaces/secrets", - "GET /repos/{owner}/{repo}/collaborators", - "GET /repos/{owner}/{repo}/comments", - "GET /repos/{owner}/{repo}/comments/{comment_id}/reactions", - "GET /repos/{owner}/{repo}/commits", - "GET /repos/{owner}/{repo}/commits/{commit_sha}/comments", - "GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls", - "GET /repos/{owner}/{repo}/commits/{ref}/check-runs", - "GET /repos/{owner}/{repo}/commits/{ref}/check-suites", - "GET /repos/{owner}/{repo}/commits/{ref}/status", - "GET /repos/{owner}/{repo}/commits/{ref}/statuses", - "GET /repos/{owner}/{repo}/contributors", - "GET /repos/{owner}/{repo}/dependabot/alerts", - "GET /repos/{owner}/{repo}/dependabot/secrets", - "GET /repos/{owner}/{repo}/deployments", - "GET /repos/{owner}/{repo}/deployments/{deployment_id}/statuses", - "GET /repos/{owner}/{repo}/environments", - "GET /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies", - "GET /repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules/apps", - "GET /repos/{owner}/{repo}/environments/{environment_name}/secrets", - "GET /repos/{owner}/{repo}/environments/{environment_name}/variables", - "GET /repos/{owner}/{repo}/events", - "GET /repos/{owner}/{repo}/forks", - "GET /repos/{owner}/{repo}/hooks", - "GET /repos/{owner}/{repo}/hooks/{hook_id}/deliveries", - "GET /repos/{owner}/{repo}/invitations", - "GET /repos/{owner}/{repo}/issues", - "GET /repos/{owner}/{repo}/issues/comments", - "GET /repos/{owner}/{repo}/issues/comments/{comment_id}/reactions", - "GET /repos/{owner}/{repo}/issues/events", - "GET /repos/{owner}/{repo}/issues/{issue_number}/comments", - "GET /repos/{owner}/{repo}/issues/{issue_number}/events", - "GET /repos/{owner}/{repo}/issues/{issue_number}/labels", - "GET /repos/{owner}/{repo}/issues/{issue_number}/reactions", - "GET /repos/{owner}/{repo}/issues/{issue_number}/timeline", - "GET /repos/{owner}/{repo}/keys", - "GET /repos/{owner}/{repo}/labels", - "GET /repos/{owner}/{repo}/milestones", - "GET /repos/{owner}/{repo}/milestones/{milestone_number}/labels", - "GET /repos/{owner}/{repo}/notifications", - "GET /repos/{owner}/{repo}/pages/builds", - "GET /repos/{owner}/{repo}/projects", - "GET /repos/{owner}/{repo}/pulls", - "GET /repos/{owner}/{repo}/pulls/comments", - "GET /repos/{owner}/{repo}/pulls/comments/{comment_id}/reactions", - "GET /repos/{owner}/{repo}/pulls/{pull_number}/comments", - "GET /repos/{owner}/{repo}/pulls/{pull_number}/commits", - "GET /repos/{owner}/{repo}/pulls/{pull_number}/files", - "GET /repos/{owner}/{repo}/pulls/{pull_number}/reviews", - "GET /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}/comments", - "GET /repos/{owner}/{repo}/releases", - "GET /repos/{owner}/{repo}/releases/{release_id}/assets", - "GET /repos/{owner}/{repo}/releases/{release_id}/reactions", - "GET /repos/{owner}/{repo}/rules/branches/{branch}", - "GET /repos/{owner}/{repo}/rulesets", - "GET /repos/{owner}/{repo}/rulesets/rule-suites", - "GET /repos/{owner}/{repo}/secret-scanning/alerts", - "GET /repos/{owner}/{repo}/secret-scanning/alerts/{alert_number}/locations", - "GET /repos/{owner}/{repo}/security-advisories", - "GET /repos/{owner}/{repo}/stargazers", - "GET /repos/{owner}/{repo}/subscribers", - "GET /repos/{owner}/{repo}/tags", - "GET /repos/{owner}/{repo}/teams", - "GET /repos/{owner}/{repo}/topics", - "GET /repositories", - "GET /search/code", - "GET /search/commits", - "GET /search/issues", - "GET /search/labels", - "GET /search/repositories", - "GET /search/topics", - "GET /search/users", - "GET /teams/{team_id}/discussions", - "GET /teams/{team_id}/discussions/{discussion_number}/comments", - "GET /teams/{team_id}/discussions/{discussion_number}/comments/{comment_number}/reactions", - "GET /teams/{team_id}/discussions/{discussion_number}/reactions", - "GET /teams/{team_id}/invitations", - "GET /teams/{team_id}/members", - "GET /teams/{team_id}/projects", - "GET /teams/{team_id}/repos", - "GET /teams/{team_id}/teams", - "GET /user/blocks", - "GET /user/codespaces", - "GET /user/codespaces/secrets", - "GET /user/emails", - "GET /user/followers", - "GET /user/following", - "GET /user/gpg_keys", - "GET /user/installations", - "GET /user/installations/{installation_id}/repositories", - "GET /user/issues", - "GET /user/keys", - "GET /user/marketplace_purchases", - "GET /user/marketplace_purchases/stubbed", - "GET /user/memberships/orgs", - "GET /user/migrations", - "GET /user/migrations/{migration_id}/repositories", - "GET /user/orgs", - "GET /user/packages", - "GET /user/packages/{package_type}/{package_name}/versions", - "GET /user/public_emails", - "GET /user/repos", - "GET /user/repository_invitations", - "GET /user/social_accounts", - "GET /user/ssh_signing_keys", - "GET /user/starred", - "GET /user/subscriptions", - "GET /user/teams", - "GET /users", - "GET /users/{username}/events", - "GET /users/{username}/events/orgs/{org}", - "GET /users/{username}/events/public", - "GET /users/{username}/followers", - "GET /users/{username}/following", - "GET /users/{username}/gists", - "GET /users/{username}/gpg_keys", - "GET /users/{username}/keys", - "GET /users/{username}/orgs", - "GET /users/{username}/packages", - "GET /users/{username}/projects", - "GET /users/{username}/received_events", - "GET /users/{username}/received_events/public", - "GET /users/{username}/repos", - "GET /users/{username}/social_accounts", - "GET /users/{username}/ssh_signing_keys", - "GET /users/{username}/starred", - "GET /users/{username}/subscriptions" - ]; - function isPaginatingEndpoint(arg) { - if (typeof arg === "string") { - return paginatingEndpoints.includes(arg); - } else { - return false; + result.parameters[key] = value; } + if (index !== header.length) { + return defaultContentType; + } + return result; } - function paginateRest2(octokit) { - return { - paginate: Object.assign(paginate.bind(null, octokit), { - iterator: iterator.bind(null, octokit) - }) - }; - } - paginateRest2.VERSION = VERSION8; + module2.exports.default = { parse: parse2, safeParse: safeParse2 }; + module2.exports.parse = parse2; + module2.exports.safeParse = safeParse2; + module2.exports.defaultContentType = defaultContentType; } }); // node_modules/@octokit/plugin-rest-endpoint-methods/dist-node/index.js -var require_dist_node2 = __commonJS({ +var require_dist_node = __commonJS({ "node_modules/@octokit/plugin-rest-endpoint-methods/dist-node/index.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; @@ -5432,7 +5146,7 @@ var require_dist_node2 = __commonJS({ restEndpointMethods: () => restEndpointMethods }); module2.exports = __toCommonJS(dist_src_exports); - var VERSION8 = "13.2.2"; + var VERSION9 = "13.2.2"; var Endpoints = { actions: { addCustomLabelsToSelfHostedRunnerForOrg: [ @@ -7499,7 +7213,7 @@ var require_dist_node2 = __commonJS({ rest: api }; } - restEndpointMethods.VERSION = VERSION8; + restEndpointMethods.VERSION = VERSION9; function legacyRestEndpointMethods2(octokit) { const api = endpointsToMethods(octokit); return { @@ -7507,7 +7221,7 @@ var require_dist_node2 = __commonJS({ rest: api }; } - legacyRestEndpointMethods2.VERSION = VERSION8; + legacyRestEndpointMethods2.VERSION = VERSION9; } }); @@ -9007,13 +8721,10 @@ function lowercaseKeys(object) { }, {}); } function isPlainObject(value) { - if (typeof value !== "object" || value === null) - return false; - if (Object.prototype.toString.call(value) !== "[object Object]") - return false; + if (typeof value !== "object" || value === null) return false; + if (Object.prototype.toString.call(value) !== "[object Object]") return false; const proto = Object.getPrototypeOf(value); - if (proto === null) - return true; + if (proto === null) return true; const Ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor; return typeof Ctor === "function" && Ctor instanceof Ctor && Function.prototype.call(Ctor) === Function.prototype.call(value); } @@ -9021,10 +8732,8 @@ function mergeDeep(defaults, options) { const result = Object.assign({}, defaults); Object.keys(options).forEach((key) => { if (isPlainObject(options[key])) { - if (!(key in defaults)) - Object.assign(result, { [key]: options[key] }); - else - result[key] = mergeDeep(defaults[key], options[key]); + if (!(key in defaults)) Object.assign(result, { [key]: options[key] }); + else result[key] = mergeDeep(defaults[key], options[key]); } else { Object.assign(result, { [key]: options[key] }); } @@ -9074,9 +8783,9 @@ function addQueryParameters(url, parameters) { return `${name}=${encodeURIComponent(parameters[name])}`; }).join("&"); } -var urlVariableRegex = /\{[^}]+\}/g; +var urlVariableRegex = /\{[^{}}]+\}/g; function removeNonChars(variableName) { - return variableName.replace(/^\W+|\W+$/g, "").split(/,/); + return variableName.replace(/(?:^\W+)|(?:(? { const format = options.mediaType.format ? `.${options.mediaType.format}` : "+json"; return `application/vnd.github.${preview}-preview${format}`; @@ -9303,6 +9012,9 @@ function withDefaults(oldDefaults, newDefaults) { } var endpoint = withDefaults(null, DEFAULTS); +// node_modules/@octokit/request/dist-bundle/index.js +var import_fast_content_type_parse = __toESM(require_fast_content_type_parse(), 1); + // node_modules/@octokit/request-error/dist-src/index.js var RequestError = class extends Error { name; @@ -9320,11 +9032,11 @@ var RequestError = class extends Error { response; constructor(message, statusCode, options) { super(message); - if (Error.captureStackTrace) { - Error.captureStackTrace(this, this.constructor); - } this.name = "HttpError"; - this.status = statusCode; + this.status = Number.parseInt(statusCode); + if (Number.isNaN(this.status)) { + this.status = 0; + } if ("response" in options) { this.response = options.response; } @@ -9332,7 +9044,7 @@ var RequestError = class extends Error { if (options.request.headers.authorization) { requestCopy.headers = Object.assign({}, options.request.headers, { authorization: options.request.headers.authorization.replace( - / .*$/, + /(? [ - name, - String(value) - ]) - ), - signal: (_d = requestOptions.request) == null ? void 0 : _d.signal, - // duplex must be set if request.body is ReadableStream or Async Iterables. - // See https://fetch.spec.whatwg.org/#dom-requestinit-duplex. - ...requestOptions.body && { duplex: "half" } - }).then(async (response) => { - url = response.url; - status = response.status; - for (const keyAndValue of response.headers) { - headers[keyAndValue[0]] = keyAndValue[1]; - } - if ("deprecation" in headers) { - const matches = headers.link && headers.link.match(/<([^>]+)>; rel="deprecation"/); - const deprecationLink = matches && matches.pop(); - log.warn( - `[@octokit/request] "${requestOptions.method} ${requestOptions.url}" is deprecated. It is scheduled to be removed on ${headers.sunset}${deprecationLink ? `. See ${deprecationLink}` : ""}` - ); - } - if (status === 204 || status === 205) { - return; - } - if (requestOptions.method === "HEAD") { - if (status < 400) { - return; + const log = ((_b = requestOptions.request) == null ? void 0 : _b.log) || console; + const parseSuccessResponseBody = ((_c = requestOptions.request) == null ? void 0 : _c.parseSuccessResponseBody) !== false; + const body = isPlainObject2(requestOptions.body) || Array.isArray(requestOptions.body) ? JSON.stringify(requestOptions.body) : requestOptions.body; + const requestHeaders = Object.fromEntries( + Object.entries(requestOptions.headers).map(([name, value]) => [ + name, + String(value) + ]) + ); + let fetchResponse; + try { + fetchResponse = await fetch(requestOptions.url, { + method: requestOptions.method, + body, + redirect: (_d = requestOptions.request) == null ? void 0 : _d.redirect, + headers: requestHeaders, + signal: (_e = requestOptions.request) == null ? void 0 : _e.signal, + // duplex must be set if request.body is ReadableStream or Async Iterables. + // See https://fetch.spec.whatwg.org/#dom-requestinit-duplex. + ...requestOptions.body && { duplex: "half" } + }); + } catch (error3) { + let message = "Unknown Error"; + if (error3 instanceof Error) { + if (error3.name === "AbortError") { + error3.status = 500; + throw error3; } - throw new RequestError(response.statusText, status, { - response: { - url, - status, - headers, - data: void 0 - }, - request: requestOptions - }); - } - if (status === 304) { - throw new RequestError("Not modified", status, { - response: { - url, - status, - headers, - data: await getResponseData(response) - }, - request: requestOptions - }); - } - if (status >= 400) { - const data = await getResponseData(response); - const error3 = new RequestError(toErrorMessage(data), status, { - response: { - url, - status, - headers, - data - }, - request: requestOptions - }); - throw error3; - } - return parseSuccessResponseBody ? await getResponseData(response) : response.body; - }).then((data) => { - return { - status, - url, - headers, - data - }; - }).catch((error3) => { - if (error3 instanceof RequestError) - throw error3; - else if (error3.name === "AbortError") - throw error3; - let message = error3.message; - if (error3.name === "TypeError" && "cause" in error3) { - if (error3.cause instanceof Error) { - message = error3.cause.message; - } else if (typeof error3.cause === "string") { - message = error3.cause; + message = error3.message; + if (error3.name === "TypeError" && "cause" in error3) { + if (error3.cause instanceof Error) { + message = error3.cause.message; + } else if (typeof error3.cause === "string") { + message = error3.cause; + } } } - throw new RequestError(message, 500, { + const requestError = new RequestError(message, 500, { request: requestOptions }); - }); + requestError.cause = error3; + throw requestError; + } + const status = fetchResponse.status; + const url = fetchResponse.url; + const responseHeaders = {}; + for (const [key, value] of fetchResponse.headers) { + responseHeaders[key] = value; + } + const octokitResponse = { + url, + status, + headers: responseHeaders, + data: "" + }; + if ("deprecation" in responseHeaders) { + const matches = responseHeaders.link && responseHeaders.link.match(/<([^<>]+)>; rel="deprecation"/); + const deprecationLink = matches && matches.pop(); + log.warn( + `[@octokit/request] "${requestOptions.method} ${requestOptions.url}" is deprecated. It is scheduled to be removed on ${responseHeaders.sunset}${deprecationLink ? `. See ${deprecationLink}` : ""}` + ); + } + if (status === 204 || status === 205) { + return octokitResponse; + } + if (requestOptions.method === "HEAD") { + if (status < 400) { + return octokitResponse; + } + throw new RequestError(fetchResponse.statusText, status, { + response: octokitResponse, + request: requestOptions + }); + } + if (status === 304) { + octokitResponse.data = await getResponseData(fetchResponse); + throw new RequestError("Not modified", status, { + response: octokitResponse, + request: requestOptions + }); + } + if (status >= 400) { + octokitResponse.data = await getResponseData(fetchResponse); + throw new RequestError(toErrorMessage(octokitResponse.data), status, { + response: octokitResponse, + request: requestOptions + }); + } + octokitResponse.data = parseSuccessResponseBody ? await getResponseData(fetchResponse) : fetchResponse.body; + return octokitResponse; } async function getResponseData(response) { + var _a; const contentType = response.headers.get("content-type"); - if (/application\/json/.test(contentType)) { - return response.json().catch(() => response.text()).catch(() => ""); + if (!contentType) { + return response.text().catch(() => ""); } - if (!contentType || /^text\/|charset=utf-8$/.test(contentType)) { - return response.text(); + const mimetype = (0, import_fast_content_type_parse.safeParse)(contentType); + if (isJSONResponse(mimetype)) { + let text = ""; + try { + text = await response.text(); + return JSON.parse(text); + } catch (err) { + return text; + } + } else if (mimetype.type.startsWith("text/") || ((_a = mimetype.parameters.charset) == null ? void 0 : _a.toLowerCase()) === "utf-8") { + return response.text().catch(() => ""); + } else { + return response.arrayBuffer().catch(() => new ArrayBuffer(0)); } - return getBufferResponse(response); +} +function isJSONResponse(mimetype) { + return mimetype.type === "application/json" || mimetype.type === "application/scim+json"; } function toErrorMessage(data) { - if (typeof data === "string") + if (typeof data === "string") { return data; - let suffix; - if ("documentation_url" in data) { - suffix = ` - ${data.documentation_url}`; - } else { - suffix = ""; + } + if (data instanceof ArrayBuffer) { + return "Unknown error"; } if ("message" in data) { - if (Array.isArray(data.errors)) { - return `${data.message}: ${data.errors.map(JSON.stringify).join(", ")}${suffix}`; - } - return `${data.message}${suffix}`; + const suffix = "documentation_url" in data ? ` - ${data.documentation_url}` : ""; + return Array.isArray(data.errors) ? `${data.message}: ${data.errors.map((v) => JSON.stringify(v)).join(", ")}${suffix}` : `${data.message}${suffix}`; } return `Unknown error: ${JSON.stringify(data)}`; } @@ -9522,11 +9228,7 @@ function withDefaults2(oldEndpoint, newDefaults) { defaults: withDefaults2.bind(null, endpoint2) }); } -var request = withDefaults2(endpoint, { - headers: { - "user-agent": `octokit-request.js/${VERSION2} ${getUserAgent()}` - } -}); +var request = withDefaults2(endpoint, defaults_default); // node_modules/@octokit/graphql/dist-bundle/index.js var VERSION3 = "0.0.0-development"; @@ -9837,23 +9539,125 @@ function requestLog(octokit) { } requestLog.VERSION = VERSION5; +// node_modules/@octokit/plugin-paginate-rest/dist-bundle/index.js +var VERSION6 = "0.0.0-development"; +function normalizePaginatedListResponse(response) { + if (!response.data) { + return { + ...response, + data: [] + }; + } + const responseNeedsNormalization = "total_count" in response.data && !("url" in response.data); + if (!responseNeedsNormalization) return response; + const incompleteResults = response.data.incomplete_results; + const repositorySelection = response.data.repository_selection; + const totalCount = response.data.total_count; + delete response.data.incomplete_results; + delete response.data.repository_selection; + delete response.data.total_count; + const namespaceKey = Object.keys(response.data)[0]; + const data = response.data[namespaceKey]; + response.data = data; + if (typeof incompleteResults !== "undefined") { + response.data.incomplete_results = incompleteResults; + } + if (typeof repositorySelection !== "undefined") { + response.data.repository_selection = repositorySelection; + } + response.data.total_count = totalCount; + return response; +} +function iterator(octokit, route, parameters) { + const options = typeof route === "function" ? route.endpoint(parameters) : octokit.request.endpoint(route, parameters); + const requestMethod = typeof route === "function" ? route : octokit.request; + const method = options.method; + const headers = options.headers; + let url = options.url; + return { + [Symbol.asyncIterator]: () => ({ + async next() { + if (!url) return { done: true }; + try { + const response = await requestMethod({ method, url, headers }); + const normalizedResponse = normalizePaginatedListResponse(response); + url = ((normalizedResponse.headers.link || "").match( + /<([^<>]+)>;\s*rel="next"/ + ) || [])[1]; + return { value: normalizedResponse }; + } catch (error3) { + if (error3.status !== 409) throw error3; + url = ""; + return { + value: { + status: 200, + headers: {}, + data: [] + } + }; + } + } + }) + }; +} +function paginate(octokit, route, parameters, mapFn) { + if (typeof parameters === "function") { + mapFn = parameters; + parameters = void 0; + } + return gather( + octokit, + [], + iterator(octokit, route, parameters)[Symbol.asyncIterator](), + mapFn + ); +} +function gather(octokit, results, iterator2, mapFn) { + return iterator2.next().then((result) => { + if (result.done) { + return results; + } + let earlyExit = false; + function done() { + earlyExit = true; + } + results = results.concat( + mapFn ? mapFn(result.value, done) : result.value.data + ); + if (earlyExit) { + return results; + } + return gather(octokit, results, iterator2, mapFn); + }); +} +var composePaginateRest = Object.assign(paginate, { + iterator +}); +function paginateRest(octokit) { + return { + paginate: Object.assign(paginate.bind(null, octokit), { + iterator: iterator.bind(null, octokit) + }) + }; +} +paginateRest.VERSION = VERSION6; + // node_modules/@octokit/rest/dist-src/index.js -var import_plugin_paginate_rest = __toESM(require_dist_node(), 1); -var import_plugin_rest_endpoint_methods = __toESM(require_dist_node2(), 1); +var import_plugin_rest_endpoint_methods = __toESM(require_dist_node(), 1); // node_modules/@octokit/rest/dist-src/version.js -var VERSION6 = "21.0.2"; +var VERSION7 = "21.0.2"; // node_modules/@octokit/rest/dist-src/index.js -var Octokit2 = Octokit.plugin(requestLog, import_plugin_rest_endpoint_methods.legacyRestEndpointMethods, import_plugin_paginate_rest.paginateRest).defaults( +var Octokit2 = Octokit.plugin(requestLog, import_plugin_rest_endpoint_methods.legacyRestEndpointMethods, paginateRest).defaults( { - userAgent: `octokit-rest.js/${VERSION6}` + userAgent: `octokit-rest.js/${VERSION7}` } ); // node_modules/@octokit/plugin-throttling/dist-bundle/index.js var import_light = __toESM(require_light(), 1); -var VERSION7 = "0.0.0-development"; +var VERSION8 = "0.0.0-development"; var noop2 = () => Promise.resolve(); function wrapRequest(state, request2, options) { return state.retryLimiter.schedule(doRequest, state, request2, options); @@ -9996,8 +9800,8 @@ function throttling(octokit, octokitOptions) { "error", (e) => octokit.log.warn("Error in throttling-plugin limit handler", e) ); - state.retryLimiter.on("failed", async function(error3, info2) { - const [state2, request2, options] = info2.args; + state.retryLimiter.on("failed", async function(error3, info3) { + const [state2, request2, options] = info3.args; const { pathname } = new URL(options.url, "http://github.test"); const shouldRetryGraphQL = pathname.startsWith("/graphql") && error3.status !== 401; if (!(shouldRetryGraphQL || error3.status === 403 || error3.status === 429)) { @@ -10050,7 +9854,7 @@ function throttling(octokit, octokitOptions) { octokit.hook.wrap("request", wrapRequest.bind(null, state)); return {}; } -throttling.VERSION = VERSION7; +throttling.VERSION = VERSION8; throttling.triggersNotification = triggersNotification; // src/octokit.ts @@ -10361,7 +10165,7 @@ function getDestinationDirectory(storageDirectory, slug, tag, platform2, archite `${platform2}-${architecture}` ); } -async function installGitHubReleaseBinary(octokit, targetRelease, storageDirectory, token) { +async function installGitHubReleaseBinary(octokit, targetRelease, storageDirectory, token, ignoreExisting) { const targetTriple = getTargetTriple((0, import_node_os.arch)(), (0, import_node_os.platform)()); const releaseTag = await findExactSemanticVersionTag( octokit, @@ -10391,6 +10195,12 @@ async function installGitHubReleaseBinary(octokit, targetRelease, storageDirecto destinationBasename ); fs.mkdirSync(destinationDirectory, { recursive: true }); + if (fs.existsSync(destinationFilename)) { + if (ignoreExisting) { + core2.info(`Binary already exists at ${destinationFilename}, ignoring and leaving system as-is`); + return; + } + } await tc.downloadTool( releaseAsset.url, destinationFilename, @@ -10424,6 +10234,7 @@ async function main() { ); const maybeTargetReleases = parseTargetReleases(core2.getInput("targets")); const maybeHomeDirectory = parseEnvironmentVariable("HOME"); + const ignoreExisting = core2.getBooleanInput("ignore-existing-binary"); const errors = [maybeToken, maybeTargetReleases, maybeHomeDirectory].flatMap( getErrors ); @@ -10446,7 +10257,8 @@ async function main() { octokit, targetRelease, storageDirectory, - token + token, + ignoreExisting ) ) ); diff --git a/src/index.ts b/src/index.ts index 7c95725..35e44af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,6 +46,7 @@ async function installGitHubReleaseBinary( targetRelease: TargetRelease, storageDirectory: string, token: string, + ignoreExisting: boolean, ): Promise { const targetTriple = getTargetTriple(arch(), platform()); @@ -81,6 +82,15 @@ async function installGitHubReleaseBinary( ); fs.mkdirSync(destinationDirectory, { recursive: true }); + + // Check if file already exists and skip if ignoreExisting is true + if (fs.existsSync(destinationFilename)) { + if (ignoreExisting) { + core.info(`Binary already exists at ${destinationFilename}, ignoring and leaving system as-is`); + return; + } + } + await tc.downloadTool( releaseAsset.url, destinationFilename, @@ -120,6 +130,7 @@ async function main(): Promise { ); const maybeTargetReleases = parseTargetReleases(core.getInput("targets")); const maybeHomeDirectory = parseEnvironmentVariable("HOME"); + const ignoreExisting = core.getBooleanInput("ignore-existing-binary"); const errors = [maybeToken, maybeTargetReleases, maybeHomeDirectory].flatMap( getErrors, @@ -149,6 +160,7 @@ async function main(): Promise { targetRelease, storageDirectory, token, + ignoreExisting, ), ), );