Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 80501a7b4d |
+2
-9
@@ -4,8 +4,7 @@ branding:
|
||||
color: "orange"
|
||||
description: "Deploy your Cloudflare projects from GitHub using Wrangler"
|
||||
runs:
|
||||
# Possible values: https://github.com/actions/runner/blob/main/src/Runner.Common/Util/NodeUtil.cs#L9
|
||||
using: "node20"
|
||||
using: "node16"
|
||||
main: "dist/index.mjs"
|
||||
inputs:
|
||||
apiToken:
|
||||
@@ -14,10 +13,7 @@ inputs:
|
||||
accountId:
|
||||
description: "Your Cloudflare Account ID"
|
||||
required: false
|
||||
quiet:
|
||||
description: "Supresses output from Wrangler commands, defaults to `false`"
|
||||
required: false
|
||||
default: "false"
|
||||
|
||||
environment:
|
||||
description: "The environment you'd like to deploy your Workers project to - must be defined in wrangler.toml"
|
||||
workingDirectory:
|
||||
@@ -41,6 +37,3 @@ inputs:
|
||||
vars:
|
||||
description: "A string of environment variable names, separated by newlines. These will be bound to your Worker using the values of matching environment variables declared in `env` of this workflow."
|
||||
required: false
|
||||
packageManager:
|
||||
description: "The package manager you'd like to use to install and run wrangler. If not specified, the preferred package manager will be inferred based on the presence of a lockfile or fallback to using npm if no lockfile is found. Valid values are `npm` | `pnpm` | `yarn` | `bun`."
|
||||
required: false
|
||||
|
||||
Vendored
+131
-196
@@ -2816,8 +2816,11 @@ var __webpack_exports__ = {};
|
||||
// EXPORTS
|
||||
__nccwpck_require__.d(__webpack_exports__, {
|
||||
"kj": () => (/* binding */ authenticationSetup),
|
||||
"ny": () => (/* binding */ checkWorkingDirectory),
|
||||
"P8": () => (/* binding */ execCommands),
|
||||
"wJ": () => (/* binding */ getNpxCmd),
|
||||
"VH": () => (/* binding */ installWrangler),
|
||||
"Wp": () => (/* binding */ semverCompare),
|
||||
"cb": () => (/* binding */ uploadSecrets),
|
||||
"cj": () => (/* binding */ wranglerCommands)
|
||||
});
|
||||
@@ -2826,15 +2829,36 @@ __nccwpck_require__.d(__webpack_exports__, {
|
||||
var core = __nccwpck_require__(186);
|
||||
;// CONCATENATED MODULE: external "node:child_process"
|
||||
const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:child_process");
|
||||
;// CONCATENATED MODULE: external "node:util"
|
||||
const external_node_util_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:util");
|
||||
;// CONCATENATED MODULE: external "node:fs"
|
||||
const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs");
|
||||
;// CONCATENATED MODULE: external "node:path"
|
||||
const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path");
|
||||
;// CONCATENATED MODULE: ./src/utils.ts
|
||||
;// CONCATENATED MODULE: external "node:util"
|
||||
const external_node_util_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:util");
|
||||
;// CONCATENATED MODULE: ./src/index.ts
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const execAsync = external_node_util_namespaceObject.promisify(external_node_child_process_namespaceObject.exec);
|
||||
const DEFAULT_WRANGLER_VERSION = "3.4.0";
|
||||
/**
|
||||
* A configuration object that contains all the inputs & immutable state for the action.
|
||||
*/
|
||||
const config = {
|
||||
WRANGLER_VERSION: (0,core.getInput)("wranglerVersion") || DEFAULT_WRANGLER_VERSION,
|
||||
secrets: (0,core.getMultilineInput)("secrets"),
|
||||
workingDirectory: checkWorkingDirectory((0,core.getInput)("workingDirectory")),
|
||||
CLOUDFLARE_API_TOKEN: (0,core.getInput)("apiToken"),
|
||||
CLOUDFLARE_ACCOUNT_ID: (0,core.getInput)("accountId"),
|
||||
ENVIRONMENT: (0,core.getInput)("environment"),
|
||||
VARS: (0,core.getMultilineInput)("vars"),
|
||||
COMMANDS: (0,core.getMultilineInput)("command"),
|
||||
};
|
||||
function getNpxCmd() {
|
||||
return process.env.RUNNER_OS === "Windows" ? "npx.cmd" : "npx";
|
||||
}
|
||||
/**
|
||||
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
|
||||
*/
|
||||
@@ -2851,147 +2875,51 @@ function semverCompare(version1, version2) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function checkWorkingDirectory(workingDirectory = ".") {
|
||||
const normalizedPath = external_node_path_namespaceObject.normalize(workingDirectory);
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(normalizedPath)) {
|
||||
return normalizedPath;
|
||||
}
|
||||
else {
|
||||
throw new Error(`Directory ${workingDirectory} does not exist.`);
|
||||
}
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/packageManagers.ts
|
||||
|
||||
|
||||
const PACKAGE_MANAGERS = {
|
||||
npm: {
|
||||
install: "npm i",
|
||||
exec: "npx",
|
||||
},
|
||||
yarn: {
|
||||
install: "yarn add",
|
||||
exec: "yarn",
|
||||
},
|
||||
pnpm: {
|
||||
install: "pnpm add",
|
||||
exec: "pnpm exec",
|
||||
},
|
||||
bun: {
|
||||
install: "bun i",
|
||||
exec: "bunx",
|
||||
},
|
||||
};
|
||||
function detectPackageManager(workingDirectory = ".") {
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(workingDirectory, "package-lock.json"))) {
|
||||
return "npm";
|
||||
}
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(workingDirectory, "yarn.lock"))) {
|
||||
return "yarn";
|
||||
}
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(workingDirectory, "pnpm-lock.yaml"))) {
|
||||
return "pnpm";
|
||||
}
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(workingDirectory, "bun.lockb"))) {
|
||||
return "bun";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function assertValidPackageManagerValue(name) {
|
||||
if (name && !Object.keys(PACKAGE_MANAGERS).includes(name)) {
|
||||
throw new TypeError(`invalid value provided for "packageManager": ${name}
|
||||
Value must be one of: [${Object.keys(PACKAGE_MANAGERS).join(", ")}]`);
|
||||
}
|
||||
}
|
||||
function getPackageManager(name, { workingDirectory = "." } = {}) {
|
||||
assertValidPackageManagerValue(name);
|
||||
return PACKAGE_MANAGERS[name || detectPackageManager(workingDirectory) || "npm"];
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/index.ts
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const execAsync = external_node_util_namespaceObject.promisify(external_node_child_process_namespaceObject.exec);
|
||||
const DEFAULT_WRANGLER_VERSION = "3.5.1";
|
||||
/**
|
||||
* A configuration object that contains all the inputs & immutable state for the action.
|
||||
*/
|
||||
const config = {
|
||||
WRANGLER_VERSION: (0,core.getInput)("wranglerVersion") || DEFAULT_WRANGLER_VERSION,
|
||||
secrets: (0,core.getMultilineInput)("secrets"),
|
||||
workingDirectory: checkWorkingDirectory((0,core.getInput)("workingDirectory")),
|
||||
CLOUDFLARE_API_TOKEN: (0,core.getInput)("apiToken"),
|
||||
CLOUDFLARE_ACCOUNT_ID: (0,core.getInput)("accountId"),
|
||||
ENVIRONMENT: (0,core.getInput)("environment"),
|
||||
VARS: (0,core.getMultilineInput)("vars"),
|
||||
COMMANDS: (0,core.getMultilineInput)("command"),
|
||||
QUIET_MODE: (0,core.getBooleanInput)("quiet"),
|
||||
PACKAGE_MANAGER: (0,core.getInput)("packageManager"),
|
||||
};
|
||||
const packageManager = getPackageManager(config.PACKAGE_MANAGER, {
|
||||
workingDirectory: config.workingDirectory,
|
||||
});
|
||||
function info(message, bypass) {
|
||||
if (!config.QUIET_MODE || bypass) {
|
||||
(0,core.info)(message);
|
||||
}
|
||||
}
|
||||
function error(message, bypass) {
|
||||
if (!config.QUIET_MODE || bypass) {
|
||||
(0,core.error)(message);
|
||||
}
|
||||
}
|
||||
function startGroup(name) {
|
||||
if (!config.QUIET_MODE) {
|
||||
(0,core.startGroup)(name);
|
||||
}
|
||||
}
|
||||
function endGroup() {
|
||||
if (!config.QUIET_MODE) {
|
||||
(0,core.endGroup)();
|
||||
}
|
||||
}
|
||||
async function main() {
|
||||
try {
|
||||
installWrangler();
|
||||
authenticationSetup();
|
||||
await execCommands((0,core.getMultilineInput)("preCommands"), "pre");
|
||||
await uploadSecrets();
|
||||
await wranglerCommands();
|
||||
await execCommands((0,core.getMultilineInput)("postCommands"), "post");
|
||||
info("🏁 Wrangler Action completed", true);
|
||||
}
|
||||
catch (err) {
|
||||
err instanceof Error && error(err.message);
|
||||
(0,core.setFailed)("🚨 Action failed");
|
||||
}
|
||||
installWrangler();
|
||||
authenticationSetup();
|
||||
await execCommands((0,core.getMultilineInput)("preCommands"), "pre");
|
||||
await uploadSecrets();
|
||||
await wranglerCommands();
|
||||
await execCommands((0,core.getMultilineInput)("postCommands"), "post");
|
||||
}
|
||||
async function runProcess(command, options) {
|
||||
try {
|
||||
const result = await execAsync(command, options);
|
||||
result.stdout && info(result.stdout.toString());
|
||||
result.stderr && error(result.stderr.toString(), true);
|
||||
result.stdout && (0,core.info)(result.stdout.toString());
|
||||
result.stderr && (0,core.error)(result.stderr.toString());
|
||||
return result;
|
||||
}
|
||||
catch (err) {
|
||||
err.stdout && info(err.stdout.toString());
|
||||
err.stderr && error(err.stderr.toString(), true);
|
||||
throw new Error(`\`${command}\` returned non-zero exit code.`);
|
||||
err.stdout && (0,core.info)(err.stdout.toString());
|
||||
err.stderr && (0,core.error)(err.stderr.toString());
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
function checkWorkingDirectory(workingDirectory = ".") {
|
||||
try {
|
||||
const normalizedPath = external_node_path_namespaceObject.normalize(workingDirectory);
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(normalizedPath)) {
|
||||
return normalizedPath;
|
||||
}
|
||||
else {
|
||||
(0,core.setFailed)(`🚨 Directory ${workingDirectory} does not exist.`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
(0,core.setFailed)(`🚨 While checking/creating directory ${workingDirectory} received ${error}`);
|
||||
}
|
||||
}
|
||||
function installWrangler() {
|
||||
if (config["WRANGLER_VERSION"].startsWith("1")) {
|
||||
throw new Error(`Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`);
|
||||
(0,core.setFailed)(`🚨 Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`);
|
||||
}
|
||||
startGroup("📥 Installing Wrangler");
|
||||
const command = `${packageManager.install} wrangler@${config["WRANGLER_VERSION"]}`;
|
||||
info(`Running command: ${command}`);
|
||||
(0,core.startGroup)("📥 Installing Wrangler");
|
||||
const command = `npm install wrangler@${config["WRANGLER_VERSION"]}`;
|
||||
(0,core.info)(`Running command: ${command}`);
|
||||
(0,external_node_child_process_namespaceObject.execSync)(command, { cwd: config["workingDirectory"], env: process.env });
|
||||
info(`✅ Wrangler installed`, true);
|
||||
endGroup();
|
||||
(0,core.info)(`✅ Wrangler installed`);
|
||||
(0,core.endGroup)();
|
||||
}
|
||||
function authenticationSetup() {
|
||||
process.env.CLOUDFLARE_API_TOKEN = config["CLOUDFLARE_API_TOKEN"];
|
||||
@@ -3001,48 +2929,53 @@ async function execCommands(commands, cmdType) {
|
||||
if (!commands.length) {
|
||||
return;
|
||||
}
|
||||
startGroup(`🚀 Running ${cmdType}Commands`);
|
||||
try {
|
||||
const arrPromises = commands.map(async (command) => {
|
||||
const cmd = command.startsWith("wrangler")
|
||||
? `${packageManager.exec} ${command}`
|
||||
: command;
|
||||
info(`🚀 Executing command: ${cmd}`);
|
||||
return await runProcess(cmd, {
|
||||
cwd: config["workingDirectory"],
|
||||
env: process.env,
|
||||
});
|
||||
(0,core.startGroup)(`🚀 Running ${cmdType}Commands`);
|
||||
const arrPromises = commands.map(async (command) => {
|
||||
const cmd = command.startsWith("wrangler")
|
||||
? `${getNpxCmd()} ${command}`
|
||||
: command;
|
||||
(0,core.info)(`🚀 Executing command: ${cmd}`);
|
||||
return await runProcess(cmd, {
|
||||
cwd: config["workingDirectory"],
|
||||
env: process.env,
|
||||
});
|
||||
await Promise.all(arrPromises);
|
||||
}
|
||||
finally {
|
||||
endGroup();
|
||||
}
|
||||
});
|
||||
await Promise.all(arrPromises).catch((result) => {
|
||||
result.stdout && (0,core.info)(result.stdout.toString());
|
||||
result.stderr && (0,core.error)(result.stderr.toString());
|
||||
(0,core.setFailed)(`🚨 ${cmdType}Commands failed`);
|
||||
});
|
||||
(0,core.endGroup)();
|
||||
}
|
||||
/**
|
||||
* A helper function to get the secret from the environment variables.
|
||||
*/
|
||||
function getSecret(secret) {
|
||||
if (!secret) {
|
||||
throw new Error("Secret name cannot be blank.");
|
||||
(0,core.setFailed)("No secret provided");
|
||||
}
|
||||
const value = process.env[secret];
|
||||
if (!value) {
|
||||
throw new Error(`Value for secret ${secret} not found.`);
|
||||
(0,core.setFailed)(`Secret ${secret} not found`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
async function legacyUploadSecrets(secrets, environment, workingDirectory) {
|
||||
const arrPromises = secrets
|
||||
.map((secret) => {
|
||||
const command = `echo ${getSecret(secret)} | ${packageManager.exec} wrangler secret put ${secret}`;
|
||||
return environment ? command.concat(` --env ${environment}`) : command;
|
||||
})
|
||||
.map(async (command) => await execAsync(command, {
|
||||
cwd: workingDirectory,
|
||||
env: process.env,
|
||||
}));
|
||||
await Promise.all(arrPromises);
|
||||
try {
|
||||
const arrPromises = secrets
|
||||
.map((secret) => {
|
||||
const command = `echo ${getSecret(secret)} | ${getNpxCmd()} wrangler secret put ${secret}`;
|
||||
return environment ? command.concat(` --env ${environment}`) : command;
|
||||
})
|
||||
.map(async (command) => await execAsync(command, {
|
||||
cwd: workingDirectory,
|
||||
env: process.env,
|
||||
}));
|
||||
await Promise.all(arrPromises);
|
||||
}
|
||||
catch {
|
||||
(0,core.setFailed)(`🚨 Error uploading secrets`);
|
||||
}
|
||||
}
|
||||
async function uploadSecrets() {
|
||||
const secrets = config["secrets"];
|
||||
@@ -3051,8 +2984,8 @@ async function uploadSecrets() {
|
||||
if (!secrets.length) {
|
||||
return;
|
||||
}
|
||||
startGroup("🔑 Uploading secrets...");
|
||||
try {
|
||||
(0,core.startGroup)("🔑 Uploading Secrets");
|
||||
if (semverCompare(config["WRANGLER_VERSION"], "3.4.0"))
|
||||
return legacyUploadSecrets(secrets, environment, workingDirectory);
|
||||
const secretObj = secrets.reduce((acc, secret) => {
|
||||
@@ -3062,20 +2995,19 @@ async function uploadSecrets() {
|
||||
const environmentSuffix = !environment.length
|
||||
? ""
|
||||
: ` --env ${environment}`;
|
||||
const secretCmd = `echo "${JSON.stringify(secretObj).replaceAll('"', '\\"')}" | ${packageManager.exec} wrangler secret:bulk ${environmentSuffix}`;
|
||||
const secretCmd = `echo "${JSON.stringify(secretObj).replaceAll('"', '\\"')}" | ${getNpxCmd()} wrangler secret:bulk ${environmentSuffix}`;
|
||||
(0,external_node_child_process_namespaceObject.execSync)(secretCmd, {
|
||||
cwd: workingDirectory,
|
||||
env: process.env,
|
||||
stdio: "ignore",
|
||||
});
|
||||
info(`✅ Uploaded secrets`);
|
||||
(0,core.info)(`✅ Uploaded secrets`);
|
||||
}
|
||||
catch (err) {
|
||||
error(`❌ Upload failed`);
|
||||
throw new Error(`Failed to upload secrets.`);
|
||||
catch {
|
||||
(0,core.setFailed)(`🚨 Error uploading secrets`);
|
||||
}
|
||||
finally {
|
||||
endGroup();
|
||||
(0,core.endGroup)();
|
||||
}
|
||||
}
|
||||
function getVarArgs() {
|
||||
@@ -3085,51 +3017,54 @@ function getVarArgs() {
|
||||
return `${envVar}:${process.env[envVar]}`;
|
||||
}
|
||||
else {
|
||||
throw new Error(`Value for var ${envVar} not found in environment.`);
|
||||
(0,core.setFailed)(`🚨 ${envVar} not found in variables.`);
|
||||
}
|
||||
});
|
||||
return envVarArray.length > 0 ? `--var ${envVarArray.join(" ").trim()}` : "";
|
||||
}
|
||||
async function wranglerCommands() {
|
||||
startGroup("🚀 Running Wrangler Commands");
|
||||
try {
|
||||
const commands = config["COMMANDS"];
|
||||
const environment = config["ENVIRONMENT"];
|
||||
if (!commands.length) {
|
||||
const wranglerVersion = config["WRANGLER_VERSION"];
|
||||
const deployCommand = semverCompare("2.20.0", wranglerVersion)
|
||||
? "deploy"
|
||||
: "publish";
|
||||
commands.push(deployCommand);
|
||||
(0,core.startGroup)("🚀 Running Wrangler Commands");
|
||||
const commands = config["COMMANDS"];
|
||||
const environment = config["ENVIRONMENT"];
|
||||
if (!commands.length) {
|
||||
const wranglerVersion = config["WRANGLER_VERSION"];
|
||||
const deployCommand = semverCompare("2.20.0", wranglerVersion)
|
||||
? "deploy"
|
||||
: "publish";
|
||||
commands.push(deployCommand);
|
||||
}
|
||||
const arrPromises = commands.map(async (command) => {
|
||||
if (environment.length > 0 && !command.includes(`--env`)) {
|
||||
command = command.concat(` --env ${environment}`);
|
||||
}
|
||||
const arrPromises = commands.map(async (command) => {
|
||||
if (environment.length > 0 && !command.includes(`--env`)) {
|
||||
command = command.concat(` --env ${environment}`);
|
||||
}
|
||||
const cmd = `${packageManager.exec} wrangler ${command} ${(command.startsWith("deploy") || command.startsWith("publish")) &&
|
||||
!command.includes(`--var`)
|
||||
? getVarArgs()
|
||||
: ""}`.trim();
|
||||
info(`🚀 Executing command: ${cmd}`);
|
||||
return await runProcess(cmd, {
|
||||
cwd: config["workingDirectory"],
|
||||
env: process.env,
|
||||
});
|
||||
const cmd = `${getNpxCmd()} wrangler ${command} ${(command.startsWith("deploy") || command.startsWith("publish")) &&
|
||||
!command.includes(`--var`)
|
||||
? getVarArgs()
|
||||
: ""}`.trim();
|
||||
(0,core.info)(`🚀 Executing command: ${cmd}`);
|
||||
return await runProcess(cmd, {
|
||||
cwd: config["workingDirectory"],
|
||||
env: process.env,
|
||||
});
|
||||
await Promise.all(arrPromises);
|
||||
}
|
||||
finally {
|
||||
endGroup();
|
||||
}
|
||||
});
|
||||
await Promise.all(arrPromises).catch((result) => {
|
||||
result.stdout && (0,core.info)(result.stdout.toString());
|
||||
result.stderr && (0,core.error)(result.stderr.toString());
|
||||
(0,core.setFailed)(`🚨 Command failed`);
|
||||
});
|
||||
(0,core.endGroup)();
|
||||
}
|
||||
main();
|
||||
main().catch(() => (0,core.setFailed)("🚨 Action failed"));
|
||||
|
||||
|
||||
})();
|
||||
|
||||
var __webpack_exports__authenticationSetup = __webpack_exports__.kj;
|
||||
var __webpack_exports__checkWorkingDirectory = __webpack_exports__.ny;
|
||||
var __webpack_exports__execCommands = __webpack_exports__.P8;
|
||||
var __webpack_exports__getNpxCmd = __webpack_exports__.wJ;
|
||||
var __webpack_exports__installWrangler = __webpack_exports__.VH;
|
||||
var __webpack_exports__semverCompare = __webpack_exports__.Wp;
|
||||
var __webpack_exports__uploadSecrets = __webpack_exports__.cb;
|
||||
var __webpack_exports__wranglerCommands = __webpack_exports__.cj;
|
||||
export { __webpack_exports__authenticationSetup as authenticationSetup, __webpack_exports__execCommands as execCommands, __webpack_exports__installWrangler as installWrangler, __webpack_exports__uploadSecrets as uploadSecrets, __webpack_exports__wranglerCommands as wranglerCommands };
|
||||
export { __webpack_exports__authenticationSetup as authenticationSetup, __webpack_exports__checkWorkingDirectory as checkWorkingDirectory, __webpack_exports__execCommands as execCommands, __webpack_exports__getNpxCmd as getNpxCmd, __webpack_exports__installWrangler as installWrangler, __webpack_exports__semverCompare as semverCompare, __webpack_exports__uploadSecrets as uploadSecrets, __webpack_exports__wranglerCommands as wranglerCommands };
|
||||
|
||||
Reference in New Issue
Block a user