Add workingDirectory input

pull/50/head
Aaron Adams 2 years ago
parent 1aff065c9e
commit 540e98cd40

@ -22,6 +22,9 @@ inputs:
branch: branch:
description: "The name of the branch you want to deploy to" description: "The name of the branch you want to deploy to"
required: false required: false
workingDirectory:
description: "The working directory in which to run Wrangler"
required: false
runs: runs:
using: "node16" using: "node16"
main: "index.js" main: "index.js"

@ -1940,7 +1940,7 @@ var require_path_utils = __commonJS({
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.toPlatformPath = exports.toWin32Path = exports.toPosixPath = void 0; exports.toPlatformPath = exports.toWin32Path = exports.toPosixPath = void 0;
var path2 = __importStar(require("path")); var path3 = __importStar(require("path"));
function toPosixPath(pth) { function toPosixPath(pth) {
return pth.replace(/[\\]/g, "/"); return pth.replace(/[\\]/g, "/");
} }
@ -1950,7 +1950,7 @@ var require_path_utils = __commonJS({
} }
exports.toWin32Path = toWin32Path; exports.toWin32Path = toWin32Path;
function toPlatformPath(pth) { function toPlatformPath(pth) {
return pth.replace(/[/\\]/g, path2.sep); return pth.replace(/[/\\]/g, path3.sep);
} }
exports.toPlatformPath = toPlatformPath; exports.toPlatformPath = toPlatformPath;
} }
@ -2021,7 +2021,7 @@ var require_core = __commonJS({
var file_command_1 = require_file_command(); var file_command_1 = require_file_command();
var utils_1 = require_utils(); var utils_1 = require_utils();
var os = __importStar(require("os")); var os = __importStar(require("os"));
var path2 = __importStar(require("path")); var path3 = __importStar(require("path"));
var oidc_utils_1 = require_oidc_utils(); var oidc_utils_1 = require_oidc_utils();
var ExitCode; var ExitCode;
(function(ExitCode2) { (function(ExitCode2) {
@ -2049,7 +2049,7 @@ var require_core = __commonJS({
} else { } else {
command_1.issueCommand("add-path", {}, inputPath); 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; exports.addPath = addPath;
function getInput2(name, options) { function getInput2(name, options) {
@ -2201,8 +2201,8 @@ var require_context = __commonJS({
if (fs_1.existsSync(process.env.GITHUB_EVENT_PATH)) { if (fs_1.existsSync(process.env.GITHUB_EVENT_PATH)) {
this.payload = JSON.parse(fs_1.readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: "utf8" })); this.payload = JSON.parse(fs_1.readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: "utf8" }));
} else { } else {
const path2 = process.env.GITHUB_EVENT_PATH; const path3 = process.env.GITHUB_EVENT_PATH;
process.stdout.write(`GITHUB_EVENT_PATH ${path2} does not exist${os_1.EOL}`); process.stdout.write(`GITHUB_EVENT_PATH ${path3} does not exist${os_1.EOL}`);
} }
} }
this.eventName = process.env.GITHUB_EVENT_NAME; this.eventName = process.env.GITHUB_EVENT_NAME;
@ -3520,14 +3520,14 @@ var require_url_state_machine = __commonJS({
return url.replace(/\u0009|\u000A|\u000D/g, ""); return url.replace(/\u0009|\u000A|\u000D/g, "");
} }
function shortenPath(url) { function shortenPath(url) {
const path2 = url.path; const path3 = url.path;
if (path2.length === 0) { if (path3.length === 0) {
return; return;
} }
if (url.scheme === "file" && path2.length === 1 && isNormalizedWindowsDriveLetter(path2[0])) { if (url.scheme === "file" && path3.length === 1 && isNormalizedWindowsDriveLetter(path3[0])) {
return; return;
} }
path2.pop(); path3.pop();
} }
function includesCredentials(url) { function includesCredentials(url) {
return url.username !== "" || url.password !== ""; return url.username !== "" || url.password !== "";
@ -7857,14 +7857,14 @@ var require_util = __commonJS({
if (!(url instanceof URL)) { if (!(url instanceof URL)) {
const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80; 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 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("/")) { if (origin.endsWith("/")) {
origin = origin.substring(0, origin.length - 1); origin = origin.substring(0, origin.length - 1);
} }
if (path2 && !path2.startsWith("/")) { if (path3 && !path3.startsWith("/")) {
path2 = `/${path2}`; path3 = `/${path3}`;
} }
url = new URL(origin + path2); url = new URL(origin + path3);
} }
return url; return url;
} }
@ -8471,18 +8471,18 @@ var require_utils5 = __commonJS({
if (decode) if (decode)
return decode(data, hint); return decode(data, hint);
} }
function basename(path2) { function basename(path3) {
if (typeof path2 !== "string") if (typeof path3 !== "string")
return ""; return "";
for (let i = path2.length - 1; i >= 0; --i) { for (let i = path3.length - 1; i >= 0; --i) {
switch (path2.charCodeAt(i)) { switch (path3.charCodeAt(i)) {
case 47: case 47:
case 92: case 92:
path2 = path2.slice(i + 1); path3 = path3.slice(i + 1);
return path2 === ".." || path2 === "." ? "" : path2; return path3 === ".." || path3 === "." ? "" : path3;
} }
} }
return path2 === ".." || path2 === "." ? "" : path2; return path3 === ".." || path3 === "." ? "" : path3;
} }
var TOKEN = [ var TOKEN = [
0, 0,
@ -13522,7 +13522,7 @@ var require_request = __commonJS({
} }
var Request = class { var Request = class {
constructor(origin, { constructor(origin, {
path: path2, path: path3,
method, method,
body, body,
headers, headers,
@ -13534,11 +13534,11 @@ var require_request = __commonJS({
bodyTimeout, bodyTimeout,
throwOnError throwOnError
}, handler) { }, handler) {
if (typeof path2 !== "string") { if (typeof path3 !== "string") {
throw new InvalidArgumentError("path must be a 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"); 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"); throw new InvalidArgumentError("invalid request path");
} }
if (typeof method !== "string") { if (typeof method !== "string") {
@ -13579,7 +13579,7 @@ var require_request = __commonJS({
this.completed = false; this.completed = false;
this.aborted = false; this.aborted = false;
this.upgrade = upgrade || null; this.upgrade = upgrade || null;
this.path = query ? util.buildURL(path2, query) : path2; this.path = query ? util.buildURL(path3, query) : path3;
this.origin = origin; this.origin = origin;
this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent; this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
this.blocking = blocking == null ? false : blocking; this.blocking = blocking == null ? false : blocking;
@ -14426,9 +14426,9 @@ var require_RedirectHandler = __commonJS({
return this.handler.onHeaders(statusCode, headers, resume, statusText); 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 { 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.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.origin = origin;
this.opts.maxRedirections = 0; this.opts.maxRedirections = 0;
if (statusCode === 303 && this.opts.method !== "HEAD") { if (statusCode === 303 && this.opts.method !== "HEAD") {
@ -15503,7 +15503,7 @@ var require_client = __commonJS({
} }
} }
function write(client, request) { 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"; const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
if (body && typeof body.read === "function") { if (body && typeof body.read === "function") {
body.read(0); body.read(0);
@ -15549,7 +15549,7 @@ var require_client = __commonJS({
if (blocking) { if (blocking) {
socket[kBlocking] = true; socket[kBlocking] = true;
} }
let header = `${method} ${path2} HTTP/1.1\r let header = `${method} ${path3} HTTP/1.1\r
`; `;
if (typeof host === "string") { if (typeof host === "string") {
header += `host: ${host}\r header += `host: ${host}\r
@ -17543,20 +17543,20 @@ var require_mock_utils = __commonJS({
} }
return true; return true;
} }
function safeUrl(path2) { function safeUrl(path3) {
if (typeof path2 !== "string") { if (typeof path3 !== "string") {
return path2; return path3;
} }
const pathSegments = path2.split("?"); const pathSegments = path3.split("?");
if (pathSegments.length !== 2) { if (pathSegments.length !== 2) {
return path2; return path3;
} }
const qp = new URLSearchParams(pathSegments.pop()); const qp = new URLSearchParams(pathSegments.pop());
qp.sort(); qp.sort();
return [...pathSegments, qp.toString()].join("?"); return [...pathSegments, qp.toString()].join("?");
} }
function matchKey(mockDispatch2, { path: path2, method, body, headers }) { function matchKey(mockDispatch2, { path: path3, method, body, headers }) {
const pathMatch = matchValue(mockDispatch2.path, path2); const pathMatch = matchValue(mockDispatch2.path, path3);
const methodMatch = matchValue(mockDispatch2.method, method); const methodMatch = matchValue(mockDispatch2.method, method);
const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true; const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
const headersMatch = matchHeaders(mockDispatch2, headers); const headersMatch = matchHeaders(mockDispatch2, headers);
@ -17574,7 +17574,7 @@ var require_mock_utils = __commonJS({
function getMockDispatch(mockDispatches, key) { function getMockDispatch(mockDispatches, key) {
const basePath = key.query ? buildURL(key.path, key.query) : key.path; const basePath = key.query ? buildURL(key.path, key.query) : key.path;
const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath; 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) { if (matchedMockDispatches.length === 0) {
throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`); throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
} }
@ -17611,9 +17611,9 @@ var require_mock_utils = __commonJS({
} }
} }
function buildKey(opts) { function buildKey(opts) {
const { path: path2, method, body, headers, query } = opts; const { path: path3, method, body, headers, query } = opts;
return { return {
path: path2, path: path3,
method, method,
body, body,
headers, headers,
@ -18025,10 +18025,10 @@ var require_pending_interceptors_formatter = __commonJS({
} }
format(pendingInterceptors) { format(pendingInterceptors) {
const withPrettyHeaders = pendingInterceptors.map( const withPrettyHeaders = pendingInterceptors.map(
({ method, path: path2, data: { statusCode }, persist, times, timesInvoked, origin }) => ({ ({ method, path: path3, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
Method: method, Method: method,
Origin: origin, Origin: origin,
Path: path2, Path: path3,
"Status code": statusCode, "Status code": statusCode,
Persistent: persist ? "\u2705" : "\u274C", Persistent: persist ? "\u2705" : "\u274C",
Invocations: timesInvoked, Invocations: timesInvoked,
@ -20354,11 +20354,11 @@ var require_fetch = __commonJS({
const { request } = fetchParams; const { request } = fetchParams;
const { const {
protocol: scheme, protocol: scheme,
pathname: path2 pathname: path3
} = requestCurrentURL(request); } = requestCurrentURL(request);
switch (scheme) { switch (scheme) {
case "about:": { case "about:": {
if (path2 === "blank") { if (path3 === "blank") {
const resp = makeResponse({ const resp = makeResponse({
statusText: "OK", statusText: "OK",
headersList: [ headersList: [
@ -20989,11 +20989,11 @@ var require_undici = __commonJS({
if (typeof opts.path !== "string") { if (typeof opts.path !== "string") {
throw new InvalidArgumentError("invalid opts.path"); throw new InvalidArgumentError("invalid opts.path");
} }
let path2 = opts.path; let path3 = opts.path;
if (!opts.path.startsWith("/")) { 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 { } else {
if (!opts) { if (!opts) {
opts = typeof url === "object" ? url : {}; opts = typeof url === "object" ? url : {};
@ -22060,6 +22060,7 @@ var src_default = shellac;
// src/index.ts // src/index.ts
var import_undici = __toESM(require_undici()); var import_undici = __toESM(require_undici());
var import_process = require("process"); var import_process = require("process");
var import_node_path = __toESM(require("path"));
try { try {
const apiToken = (0, import_core.getInput)("apiToken", { required: true }); const apiToken = (0, import_core.getInput)("apiToken", { required: true });
const accountId = (0, import_core.getInput)("accountId", { 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 directory = (0, import_core.getInput)("directory", { required: true });
const gitHubToken = (0, import_core.getInput)("gitHubToken", { required: false }); const gitHubToken = (0, import_core.getInput)("gitHubToken", { required: false });
const branch = (0, import_core.getInput)("branch", { required: false }); const branch = (0, import_core.getInput)("branch", { required: false });
const workingDirectory = (0, import_core.getInput)("workingDirectory", { required: false });
const getProject = async () => { const getProject = async () => {
const response = await (0, import_undici.fetch)( const response = await (0, import_undici.fetch)(
`https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`, `https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`,
@ -22076,7 +22078,7 @@ try {
return result; return result;
}; };
const createPagesDeployment = async () => { const createPagesDeployment = async () => {
await src_default` await src_default.in(import_node_path.default.join(process.cwd(), workingDirectory))`
$ export CLOUDFLARE_API_TOKEN="${apiToken}" $ export CLOUDFLARE_API_TOKEN="${apiToken}"
if ${accountId} { if ${accountId} {
$ export CLOUDFLARE_ACCOUNT_ID="${accountId}" $ export CLOUDFLARE_ACCOUNT_ID="${accountId}"

@ -4,6 +4,7 @@ import { context, getOctokit } from "@actions/github";
import shellac from "shellac"; import shellac from "shellac";
import { fetch } from "undici"; import { fetch } from "undici";
import { env } from "process"; import { env } from "process";
import path from "node:path";
type Octokit = ReturnType<typeof getOctokit>; type Octokit = ReturnType<typeof getOctokit>;
@ -14,6 +15,7 @@ try {
const directory = getInput("directory", { required: true }); const directory = getInput("directory", { required: true });
const gitHubToken = getInput("gitHubToken", { required: false }); const gitHubToken = getInput("gitHubToken", { required: false });
const branch = getInput("branch", { required: false }); const branch = getInput("branch", { required: false });
const workingDirectory = getInput("workingDirectory", { required: false });
const getProject = async () => { const getProject = async () => {
const response = await fetch( const response = await fetch(
@ -26,7 +28,7 @@ try {
const createPagesDeployment = async () => { const createPagesDeployment = async () => {
// TODO: Replace this with an API call to wrangler so we can get back a full deployment response object // 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}" $ export CLOUDFLARE_API_TOKEN="${apiToken}"
if ${accountId} { if ${accountId} {
$ export CLOUDFLARE_ACCOUNT_ID="${accountId}" $ export CLOUDFLARE_ACCOUNT_ID="${accountId}"

Loading…
Cancel
Save