From 540e98cd40d4cfe4983d91c3db017639ecb40bba Mon Sep 17 00:00:00 2001 From: Aaron Adams Date: Tue, 3 Jan 2023 16:20:15 +0000 Subject: [PATCH 1/2] Add workingDirectory input --- action.yml | 3 ++ index.js | 98 +++++++++++++++++++++++++++------------------------- src/index.ts | 4 ++- 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/action.yml b/action.yml index 7eca57d..8d8d8e9 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,9 @@ inputs: branch: description: "The name of the branch you want to deploy to" required: false + workingDirectory: + description: "The working directory in which to run Wrangler" + required: false runs: using: "node16" main: "index.js" diff --git a/index.js b/index.js index 10fbcff..01ee532 100644 --- a/index.js +++ b/index.js @@ -1940,7 +1940,7 @@ var require_path_utils = __commonJS({ }; Object.defineProperty(exports, "__esModule", { value: true }); exports.toPlatformPath = exports.toWin32Path = exports.toPosixPath = void 0; - var path2 = __importStar(require("path")); + var path3 = __importStar(require("path")); function toPosixPath(pth) { return pth.replace(/[\\]/g, "/"); } @@ -1950,7 +1950,7 @@ var require_path_utils = __commonJS({ } exports.toWin32Path = toWin32Path; function toPlatformPath(pth) { - return pth.replace(/[/\\]/g, path2.sep); + return pth.replace(/[/\\]/g, path3.sep); } exports.toPlatformPath = toPlatformPath; } @@ -2021,7 +2021,7 @@ var require_core = __commonJS({ var file_command_1 = require_file_command(); var utils_1 = require_utils(); var os = __importStar(require("os")); - var path2 = __importStar(require("path")); + var path3 = __importStar(require("path")); var oidc_utils_1 = require_oidc_utils(); var ExitCode; (function(ExitCode2) { @@ -2049,7 +2049,7 @@ var require_core = __commonJS({ } else { command_1.issueCommand("add-path", {}, inputPath); } - process.env["PATH"] = `${inputPath}${path2.delimiter}${process.env["PATH"]}`; + process.env["PATH"] = `${inputPath}${path3.delimiter}${process.env["PATH"]}`; } exports.addPath = addPath; function getInput2(name, options) { @@ -2201,8 +2201,8 @@ var require_context = __commonJS({ if (fs_1.existsSync(process.env.GITHUB_EVENT_PATH)) { this.payload = JSON.parse(fs_1.readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: "utf8" })); } else { - const path2 = process.env.GITHUB_EVENT_PATH; - process.stdout.write(`GITHUB_EVENT_PATH ${path2} does not exist${os_1.EOL}`); + const path3 = process.env.GITHUB_EVENT_PATH; + process.stdout.write(`GITHUB_EVENT_PATH ${path3} does not exist${os_1.EOL}`); } } this.eventName = process.env.GITHUB_EVENT_NAME; @@ -3520,14 +3520,14 @@ var require_url_state_machine = __commonJS({ return url.replace(/\u0009|\u000A|\u000D/g, ""); } function shortenPath(url) { - const path2 = url.path; - if (path2.length === 0) { + const path3 = url.path; + if (path3.length === 0) { return; } - if (url.scheme === "file" && path2.length === 1 && isNormalizedWindowsDriveLetter(path2[0])) { + if (url.scheme === "file" && path3.length === 1 && isNormalizedWindowsDriveLetter(path3[0])) { return; } - path2.pop(); + path3.pop(); } function includesCredentials(url) { return url.username !== "" || url.password !== ""; @@ -7857,14 +7857,14 @@ var require_util = __commonJS({ if (!(url instanceof URL)) { const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80; let origin = url.origin != null ? url.origin : `${url.protocol}//${url.hostname}:${port}`; - let path2 = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`; + let path3 = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`; if (origin.endsWith("/")) { origin = origin.substring(0, origin.length - 1); } - if (path2 && !path2.startsWith("/")) { - path2 = `/${path2}`; + if (path3 && !path3.startsWith("/")) { + path3 = `/${path3}`; } - url = new URL(origin + path2); + url = new URL(origin + path3); } return url; } @@ -8471,18 +8471,18 @@ var require_utils5 = __commonJS({ if (decode) return decode(data, hint); } - function basename(path2) { - if (typeof path2 !== "string") + function basename(path3) { + if (typeof path3 !== "string") return ""; - for (let i = path2.length - 1; i >= 0; --i) { - switch (path2.charCodeAt(i)) { + for (let i = path3.length - 1; i >= 0; --i) { + switch (path3.charCodeAt(i)) { case 47: case 92: - path2 = path2.slice(i + 1); - return path2 === ".." || path2 === "." ? "" : path2; + path3 = path3.slice(i + 1); + return path3 === ".." || path3 === "." ? "" : path3; } } - return path2 === ".." || path2 === "." ? "" : path2; + return path3 === ".." || path3 === "." ? "" : path3; } var TOKEN = [ 0, @@ -13522,7 +13522,7 @@ var require_request = __commonJS({ } var Request = class { constructor(origin, { - path: path2, + path: path3, method, body, headers, @@ -13534,11 +13534,11 @@ var require_request = __commonJS({ bodyTimeout, throwOnError }, handler) { - if (typeof path2 !== "string") { + if (typeof path3 !== "string") { throw new InvalidArgumentError("path must be a string"); - } else if (path2[0] !== "/" && !(path2.startsWith("http://") || path2.startsWith("https://")) && method !== "CONNECT") { + } else if (path3[0] !== "/" && !(path3.startsWith("http://") || path3.startsWith("https://")) && method !== "CONNECT") { throw new InvalidArgumentError("path must be an absolute URL or start with a slash"); - } else if (invalidPathRegex.exec(path2) !== null) { + } else if (invalidPathRegex.exec(path3) !== null) { throw new InvalidArgumentError("invalid request path"); } if (typeof method !== "string") { @@ -13579,7 +13579,7 @@ var require_request = __commonJS({ this.completed = false; this.aborted = false; this.upgrade = upgrade || null; - this.path = query ? util.buildURL(path2, query) : path2; + this.path = query ? util.buildURL(path3, query) : path3; this.origin = origin; this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent; this.blocking = blocking == null ? false : blocking; @@ -14426,9 +14426,9 @@ var require_RedirectHandler = __commonJS({ return this.handler.onHeaders(statusCode, headers, resume, statusText); } const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin))); - const path2 = search ? `${pathname}${search}` : pathname; + const path3 = search ? `${pathname}${search}` : pathname; this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin); - this.opts.path = path2; + this.opts.path = path3; this.opts.origin = origin; this.opts.maxRedirections = 0; if (statusCode === 303 && this.opts.method !== "HEAD") { @@ -15503,7 +15503,7 @@ var require_client = __commonJS({ } } function write(client, request) { - const { body, method, path: path2, host, upgrade, headers, blocking } = request; + const { body, method, path: path3, host, upgrade, headers, blocking } = request; const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH"; if (body && typeof body.read === "function") { body.read(0); @@ -15549,7 +15549,7 @@ var require_client = __commonJS({ if (blocking) { socket[kBlocking] = true; } - let header = `${method} ${path2} HTTP/1.1\r + let header = `${method} ${path3} HTTP/1.1\r `; if (typeof host === "string") { header += `host: ${host}\r @@ -17543,20 +17543,20 @@ var require_mock_utils = __commonJS({ } return true; } - function safeUrl(path2) { - if (typeof path2 !== "string") { - return path2; + function safeUrl(path3) { + if (typeof path3 !== "string") { + return path3; } - const pathSegments = path2.split("?"); + const pathSegments = path3.split("?"); if (pathSegments.length !== 2) { - return path2; + return path3; } const qp = new URLSearchParams(pathSegments.pop()); qp.sort(); return [...pathSegments, qp.toString()].join("?"); } - function matchKey(mockDispatch2, { path: path2, method, body, headers }) { - const pathMatch = matchValue(mockDispatch2.path, path2); + function matchKey(mockDispatch2, { path: path3, method, body, headers }) { + const pathMatch = matchValue(mockDispatch2.path, path3); const methodMatch = matchValue(mockDispatch2.method, method); const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true; const headersMatch = matchHeaders(mockDispatch2, headers); @@ -17574,7 +17574,7 @@ var require_mock_utils = __commonJS({ function getMockDispatch(mockDispatches, key) { const basePath = key.query ? buildURL(key.path, key.query) : key.path; const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath; - let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path2 }) => matchValue(safeUrl(path2), resolvedPath)); + let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path3 }) => matchValue(safeUrl(path3), resolvedPath)); if (matchedMockDispatches.length === 0) { throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`); } @@ -17611,9 +17611,9 @@ var require_mock_utils = __commonJS({ } } function buildKey(opts) { - const { path: path2, method, body, headers, query } = opts; + const { path: path3, method, body, headers, query } = opts; return { - path: path2, + path: path3, method, body, headers, @@ -18025,10 +18025,10 @@ var require_pending_interceptors_formatter = __commonJS({ } format(pendingInterceptors) { const withPrettyHeaders = pendingInterceptors.map( - ({ method, path: path2, data: { statusCode }, persist, times, timesInvoked, origin }) => ({ + ({ method, path: path3, data: { statusCode }, persist, times, timesInvoked, origin }) => ({ Method: method, Origin: origin, - Path: path2, + Path: path3, "Status code": statusCode, Persistent: persist ? "\u2705" : "\u274C", Invocations: timesInvoked, @@ -20354,11 +20354,11 @@ var require_fetch = __commonJS({ const { request } = fetchParams; const { protocol: scheme, - pathname: path2 + pathname: path3 } = requestCurrentURL(request); switch (scheme) { case "about:": { - if (path2 === "blank") { + if (path3 === "blank") { const resp = makeResponse({ statusText: "OK", headersList: [ @@ -20989,11 +20989,11 @@ var require_undici = __commonJS({ if (typeof opts.path !== "string") { throw new InvalidArgumentError("invalid opts.path"); } - let path2 = opts.path; + let path3 = opts.path; if (!opts.path.startsWith("/")) { - path2 = `/${path2}`; + path3 = `/${path3}`; } - url = new URL(util.parseOrigin(url).origin + path2); + url = new URL(util.parseOrigin(url).origin + path3); } else { if (!opts) { opts = typeof url === "object" ? url : {}; @@ -22060,6 +22060,7 @@ var src_default = shellac; // src/index.ts var import_undici = __toESM(require_undici()); var import_process = require("process"); +var import_node_path = __toESM(require("path")); try { const apiToken = (0, import_core.getInput)("apiToken", { required: true }); const accountId = (0, import_core.getInput)("accountId", { required: true }); @@ -22067,6 +22068,7 @@ try { const directory = (0, import_core.getInput)("directory", { required: true }); const gitHubToken = (0, import_core.getInput)("gitHubToken", { required: false }); const branch = (0, import_core.getInput)("branch", { required: false }); + const workingDirectory = (0, import_core.getInput)("workingDirectory", { required: false }); const getProject = async () => { const response = await (0, import_undici.fetch)( `https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`, @@ -22076,7 +22078,7 @@ try { return result; }; const createPagesDeployment = async () => { - await src_default` + await src_default.in(import_node_path.default.join(process.cwd(), workingDirectory))` $ export CLOUDFLARE_API_TOKEN="${apiToken}" if ${accountId} { $ export CLOUDFLARE_ACCOUNT_ID="${accountId}" diff --git a/src/index.ts b/src/index.ts index 511668b..c871b74 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { context, getOctokit } from "@actions/github"; import shellac from "shellac"; import { fetch } from "undici"; import { env } from "process"; +import path from "node:path"; type Octokit = ReturnType; @@ -14,6 +15,7 @@ try { const directory = getInput("directory", { required: true }); const gitHubToken = getInput("gitHubToken", { required: false }); const branch = getInput("branch", { required: false }); + const workingDirectory = getInput("workingDirectory", { required: false }); const getProject = async () => { const response = await fetch( @@ -26,7 +28,7 @@ try { const createPagesDeployment = async () => { // TODO: Replace this with an API call to wrangler so we can get back a full deployment response object - await shellac` + await shellac.in(path.join(process.cwd(), workingDirectory))` $ export CLOUDFLARE_API_TOKEN="${apiToken}" if ${accountId} { $ export CLOUDFLARE_ACCOUNT_ID="${accountId}" From 74c6b6255a10968b6576a27f197bace7ccb67833 Mon Sep 17 00:00:00 2001 From: Aaron Adams Date: Wed, 4 Jan 2023 01:21:38 +0000 Subject: [PATCH 2/2] Document workingDirectory --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8ebbbcb..3f15015 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,10 @@ The branch name is used by Cloudflare Pages to determine if the deployment is pr If you are in a Git workspace, Wrangler will automatically pull the branch information for you. You can override this manually by adding the argument `branch: YOUR_BRANCH_NAME`. +### Specifying a working directory + +By default Wrangler will run in the root package directory. If your app lives in a monorepo and you want to run Wrangler from its directory, add `workingDirectory: YOUR_PACKAGE_DIRECTORY`. + ## Outputs | Name | Description |