diff --git a/dist/index.js b/dist/index.js index a7a4295..87d2b16 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1096,6 +1096,171 @@ var require_oidc_utils = __commonJS({ } }); +// node_modules/@actions/core/lib/summary.js +var require_summary = __commonJS({ + "node_modules/@actions/core/lib/summary.js"(exports) { + "use strict"; + var __awaiter = exports && exports.__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 (e2) { + reject(e2); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e2) { + reject(e2); + } + } + 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.summary = exports.markdownSummary = exports.SUMMARY_DOCS_URL = exports.SUMMARY_ENV_VAR = void 0; + var os_1 = require("os"); + var fs_1 = require("fs"); + var { access, appendFile, writeFile: writeFile2 } = fs_1.promises; + exports.SUMMARY_ENV_VAR = "GITHUB_STEP_SUMMARY"; + exports.SUMMARY_DOCS_URL = "https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary"; + var Summary = class { + constructor() { + this._buffer = ""; + } + filePath() { + return __awaiter(this, void 0, void 0, function* () { + if (this._filePath) { + return this._filePath; + } + const pathFromEnv = process.env[exports.SUMMARY_ENV_VAR]; + if (!pathFromEnv) { + throw new Error(`Unable to find environment variable for $${exports.SUMMARY_ENV_VAR}. Check if your runtime environment supports job summaries.`); + } + try { + yield access(pathFromEnv, fs_1.constants.R_OK | fs_1.constants.W_OK); + } catch (_a) { + throw new Error(`Unable to access summary file: '${pathFromEnv}'. Check if the file has correct read/write permissions.`); + } + this._filePath = pathFromEnv; + return this._filePath; + }); + } + wrap(tag, content, attrs = {}) { + const htmlAttrs = Object.entries(attrs).map(([key, value]) => ` ${key}="${value}"`).join(""); + if (!content) { + return `<${tag}${htmlAttrs}>`; + } + return `<${tag}${htmlAttrs}>${content}`; + } + write(options) { + return __awaiter(this, void 0, void 0, function* () { + const overwrite = !!(options === null || options === void 0 ? void 0 : options.overwrite); + const filePath = yield this.filePath(); + const writeFunc = overwrite ? writeFile2 : appendFile; + yield writeFunc(filePath, this._buffer, { encoding: "utf8" }); + return this.emptyBuffer(); + }); + } + clear() { + return __awaiter(this, void 0, void 0, function* () { + return this.emptyBuffer().write({ overwrite: true }); + }); + } + stringify() { + return this._buffer; + } + isEmptyBuffer() { + return this._buffer.length === 0; + } + emptyBuffer() { + this._buffer = ""; + return this; + } + addRaw(text, addEOL = false) { + this._buffer += text; + return addEOL ? this.addEOL() : this; + } + addEOL() { + return this.addRaw(os_1.EOL); + } + addCodeBlock(code, lang) { + const attrs = Object.assign({}, lang && { lang }); + const element = this.wrap("pre", this.wrap("code", code), attrs); + return this.addRaw(element).addEOL(); + } + addList(items, ordered = false) { + const tag = ordered ? "ol" : "ul"; + const listItems = items.map((item) => this.wrap("li", item)).join(""); + const element = this.wrap(tag, listItems); + return this.addRaw(element).addEOL(); + } + addTable(rows) { + const tableBody = rows.map((row) => { + const cells = row.map((cell) => { + if (typeof cell === "string") { + return this.wrap("td", cell); + } + const { header, data, colspan, rowspan } = cell; + const tag = header ? "th" : "td"; + const attrs = Object.assign(Object.assign({}, colspan && { colspan }), rowspan && { rowspan }); + return this.wrap(tag, data, attrs); + }).join(""); + return this.wrap("tr", cells); + }).join(""); + const element = this.wrap("table", tableBody); + return this.addRaw(element).addEOL(); + } + addDetails(label, content) { + const element = this.wrap("details", this.wrap("summary", label) + content); + return this.addRaw(element).addEOL(); + } + addImage(src, alt, options) { + const { width, height } = options || {}; + const attrs = Object.assign(Object.assign({}, width && { width }), height && { height }); + const element = this.wrap("img", null, Object.assign({ src, alt }, attrs)); + return this.addRaw(element).addEOL(); + } + addHeading(text, level) { + const tag = `h${level}`; + const allowedTag = ["h1", "h2", "h3", "h4", "h5", "h6"].includes(tag) ? tag : "h1"; + const element = this.wrap(allowedTag, text); + return this.addRaw(element).addEOL(); + } + addSeparator() { + const element = this.wrap("hr", null); + return this.addRaw(element).addEOL(); + } + addBreak() { + const element = this.wrap("br", null); + return this.addRaw(element).addEOL(); + } + addQuote(text, cite) { + const attrs = Object.assign({}, cite && { cite }); + const element = this.wrap("blockquote", text, attrs); + return this.addRaw(element).addEOL(); + } + addLink(text, href) { + const element = this.wrap("a", text, { href }); + return this.addRaw(element).addEOL(); + } + }; + var _summary = new Summary(); + exports.markdownSummary = _summary; + exports.summary = _summary; + } +}); + // node_modules/@actions/core/lib/core.js var require_core = __commonJS({ "node_modules/@actions/core/lib/core.js"(exports) { @@ -1296,6 +1461,14 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); }); } exports.getIDToken = getIDToken; + var summary_1 = require_summary(); + Object.defineProperty(exports, "summary", { enumerable: true, get: function() { + return summary_1.summary; + } }); + var summary_2 = require_summary(); + Object.defineProperty(exports, "markdownSummary", { enumerable: true, get: function() { + return summary_2.markdownSummary; + } }); } }); @@ -9755,10 +9928,13 @@ var require_ponyfill_es2018 = __commonJS({ const byteLengthSizeFunction = (chunk) => { return chunk.byteLength; }; - Object.defineProperty(byteLengthSizeFunction, "name", { - value: "size", - configurable: true - }); + try { + Object.defineProperty(byteLengthSizeFunction, "name", { + value: "size", + configurable: true + }); + } catch (_a) { + } class ByteLengthQueuingStrategy { constructor(options) { assertRequiredArgument(options, 1, "ByteLengthQueuingStrategy"); @@ -9803,10 +9979,13 @@ var require_ponyfill_es2018 = __commonJS({ const countSizeFunction = () => { return 1; }; - Object.defineProperty(countSizeFunction, "name", { - value: "size", - configurable: true - }); + try { + Object.defineProperty(countSizeFunction, "name", { + value: "size", + configurable: true + }); + } catch (_a) { + } class CountQueuingStrategy { constructor(options) { assertRequiredArgument(options, 1, "CountQueuingStrategy"); @@ -10925,10 +11104,10 @@ var init_multipart_parser = __esm({ }); // index.ts +var import_path = require("path"); +var import_promises = require("fs/promises"); var core = __toESM(require_core()); var github = __toESM(require_github()); -var import_promises = require("fs/promises"); -var import_path = require("path"); // node_modules/node-fetch/src/index.js var import_node_http2 = __toESM(require("node:http"), 1); @@ -11666,7 +11845,9 @@ var Request = class extends Body { throw new TypeError(`${parsedURL} is an url with embedded credentials.`); } let method = init.method || input.method || "GET"; - method = method.toUpperCase(); + if (/^(delete|get|head|options|post|put)$/i.test(method)) { + method = method.toUpperCase(); + } if ("data" in init) { doBadDataWarn(); } @@ -12108,9 +12289,17 @@ var getRelease = (octokit, { owner, repo, version }) => { if (version === "latest") { return octokit.rest.repos.getLatestRelease({ owner, repo }); } else if (tagsMatch !== null && tagsMatch[1]) { - return octokit.rest.repos.getReleaseByTag({ owner, repo, tag: tagsMatch[1] }); + return octokit.rest.repos.getReleaseByTag({ + owner, + repo, + tag: tagsMatch[1] + }); } else { - return octokit.rest.repos.getRelease({ owner, repo, release_id: Math.trunc(Number(version)) }); + return octokit.rest.repos.getRelease({ + owner, + repo, + release_id: Math.trunc(Number(version)) + }); } }; var MAX_RETRY = 5; @@ -12118,10 +12307,7 @@ var RETRY_INTERVAL = 1e3; var fetchAssetFile = async (octokit, { id, outputPath, owner, repo, token }) => { const { body, - headers: { - accept, - "user-agent": userAgent - }, + headers: { accept, "user-agent": userAgent }, method, url } = octokit.request.endpoint("GET /repos/:owner/:repo/releases/assets/:asset_id", { @@ -12164,43 +12350,34 @@ var printOutput = (release) => { core.setOutput("name", release.data.name); core.setOutput("body", release.data.body); }; +var filterByFileName = (file) => (asset) => file === asset.name; +var filterByRegex = (file) => (asset) => new RegExp(file).test(asset.name); var main = async () => { const { owner, repo } = getRepo(core.getInput("repo", { required: false }), github.context); const token = core.getInput("token", { required: false }); const version = core.getInput("version", { required: false }); const inputTarget = core.getInput("target", { required: false }); const file = core.getInput("file", { required: true }); + const usesRegex = core.getBooleanInput("regex", { required: false }); const target = inputTarget === "" ? file : inputTarget; const octokit = github.getOctokit(token); const release = await getRelease(octokit, { owner, repo, version }); - const asset = release.data.assets.find((e2) => e2.name === file); - if (typeof asset === "undefined") - throw new Error("Could not find asset id"); - await fetchAssetFile(octokit, { id: asset.id, outputPath: target, owner, repo, token }); - printOutput(release); -}; -var mainRegex = async () => { - const { owner, repo } = getRepo(core.getInput("repo", { required: false }), github.context); - const token = core.getInput("token", { required: false }); - const version = core.getInput("version", { required: false }); - const file = core.getInput("file", { required: true }); - const target = core.getInput("target", { required: true }); - const octokit = github.getOctokit(token); - const release = await getRelease(octokit, { owner, repo, version }); - const regexp = new RegExp(file); - const assets = release.data.assets.filter((e2) => regexp.test(e2.name)); + const assetFilterFn = usesRegex ? filterByRegex(file) : filterByFileName(file); + const assets = release.data.assets.filter(assetFilterFn); if (assets.length === 0) throw new Error("Could not find asset id"); for (const asset of assets) { - await fetchAssetFile(octokit, { id: asset.id, outputPath: `${target}${asset.name}`, owner, repo, token }); + await fetchAssetFile(octokit, { + id: asset.id, + outputPath: usesRegex ? `${target}${asset.name}` : target, + owner, + repo, + token + }); } printOutput(release); }; -if (core.getBooleanInput("regex", { required: false })) { - mainRegex(); -} else { - main(); -} +void main(); /*! * is-plain-object * diff --git a/index.ts b/index.ts index 0446ee8..95a7300 100644 --- a/index.ts +++ b/index.ts @@ -56,6 +56,8 @@ type GetReleaseResult = ReturnType extends Promise ? T : never; +type Asset = GetReleaseResult['data']['assets'][0]; + interface FetchAssetFileOptions { readonly id: number; readonly outputPath: string; @@ -122,6 +124,11 @@ const printOutput = (release: GetReleaseResult): void => { core.setOutput('body', release.data.body); }; +const filterByFileName = (file: string) => (asset: Asset) => + file === asset.name; +const filterByRegex = (file: string) => (asset: Asset) => + new RegExp(file).test(asset.name); + const main = async (): Promise => { const { owner, repo } = getRepo( core.getInput('repo', { required: false }), @@ -131,43 +138,22 @@ const main = async (): Promise => { const version = core.getInput('version', { required: false }); const inputTarget = core.getInput('target', { required: false }); const file = core.getInput('file', { required: true }); + const usesRegex = core.getBooleanInput('regex', { required: false }); const target = inputTarget === '' ? file : inputTarget; const octokit = github.getOctokit(token); const release = await getRelease(octokit, { owner, repo, version }); - const asset = release.data.assets.find((e) => e.name === file); - if (typeof asset === 'undefined') throw new Error('Could not find asset id'); - await fetchAssetFile(octokit, { - id: asset.id, - outputPath: target, - owner, - repo, - token, - }); - printOutput(release); -}; - -const mainRegex = async (): Promise => { - const { owner, repo } = getRepo( - core.getInput('repo', { required: false }), - github.context - ); - const token = core.getInput('token', { required: false }); - const version = core.getInput('version', { required: false }); - const file = core.getInput('file', { required: true }); - const target = core.getInput('target', { required: true }); - - const octokit = github.getOctokit(token); - const release = await getRelease(octokit, { owner, repo, version }); + const assetFilterFn = usesRegex + ? filterByRegex(file) + : filterByFileName(file); - const regexp = new RegExp(file); - const assets = release.data.assets.filter((e) => regexp.test(e.name)); + const assets = release.data.assets.filter(assetFilterFn); if (assets.length === 0) throw new Error('Could not find asset id'); for (const asset of assets) { await fetchAssetFile(octokit, { id: asset.id, - outputPath: `${target}${asset.name}`, + outputPath: usesRegex ? `${target}${asset.name}` : target, owner, repo, token, @@ -176,8 +162,4 @@ const mainRegex = async (): Promise => { printOutput(release); }; -if (core.getBooleanInput('regex', { required: false })) { - void mainRegex(); -} else { - void main(); -} +void main();