Compare commits

..

33 Commits

Author SHA1 Message Date
github-actions[bot] 09fc6b5045 Automatic compilation 2023-08-31 16:02:19 +00:00
Cina Saffary 416205365a Merge pull request #165 from cloudflare/cina/fix-release-workflow-pt2
Build action before pushing dist-tags
2023-08-31 10:55:48 -05:00
Cina Saffary 7292a4ae99 Build action before pushing dist-tags 2023-08-31 10:26:14 -05:00
Cina Saffary 4528b66125 Merge pull request #164 from cloudflare/cina/fix-release-workflow
add `tag_name` input to Tag & Release Action step of release workflow
2023-08-31 09:51:29 -05:00
Cina Saffary ee3e2a9b37 add tag_name input to Tag & Release Action 2023-08-30 17:27:17 -05:00
Cina Saffary 361844799a Merge pull request #163 from cloudflare/changeset-release/main
Version Packages
2023-08-30 09:39:11 -05:00
github-actions[bot] 26103fa86c Version Packages 2023-08-30 14:04:59 +00:00
Cina Saffary 47d4afdbd8 Merge pull request #161 from cloudflare/cina/throw-on-failures
Refactor error handling to stop execution on errors
2023-08-30 09:04:22 -05:00
Cina Saffary d7637bf514 workaround to fix failing workflow. Refs #162
The action fails to upload secrets during one of the testing steps since the Worker doesn't exist yet.
2023-08-29 19:39:50 -05:00
Cina Saffary 71199d2757 prettier scripts incorrectly set --ignore-path
--ignore-path is meant to be the path of an ignore-file, not the actual directories to ignore.
2023-08-29 18:27:03 -05:00
Cina Saffary 2962e94ac8 Move unit-tested modules into utils file
This fixes the issue where running the unit tests invoked the entire action since index.ts calls `main()` at the top-level scope.
2023-08-29 18:16:41 -05:00
Cina Saffary 5517edbb28 Avoid double "Error: Error:" logging 2023-08-29 18:00:03 -05:00
Cina Saffary f74c325efc Limit error logging on secret upload 2023-08-29 17:57:19 -05:00
Cina Saffary 105f191b19 Update snapshot for checkWorkingDirectory test 2023-08-29 17:43:29 -05:00
Cina Saffary e5251df521 Refactor error handling to stop execution on errors. Fixes #160. 2023-08-29 16:36:50 -05:00
Jacob M-G Evans b076e889fb Merge pull request #159 from cloudflare/jacobmgevans/gh-workflow
Automation release
2023-08-24 15:45:07 -05:00
Jacob M-G Evans 30e126d1a4 consolidated workflows and triggers Action release based on changeset event output 'publish' being true 2023-08-24 15:35:32 -05:00
Jacob M-G Evans fcf648c789 Merge pull request #158 from cloudflare/changeset-release/main
Version Packages
2023-08-17 11:06:50 -05:00
github-actions[bot] fcbabec21e Version Packages 2023-08-16 15:55:01 +00:00
Jacob M-G Evans 0aa12f0c2b Merge pull request #154 from cloudflare/jacobmgevans/silence-mode
Quiet feature
2023-08-16 10:54:36 -05:00
Jacob M-G Evans ad7441b6ad Merge pull request #157 from EstebanBorai/main
fix: use `wrangler@3.5.1` by default
2023-08-16 10:51:54 -05:00
Jacob M-G Evans 3f40637a1c Quiet feature
Some of the stderr, stdout, info & groupings can be a little noisy for some users and use cases.
This feature allows for a option to be passed 'quiet: true' this would significantly reduce the noise.

There will still be output that lets the user know Wrangler Installed and Wrangler Action completed successfully.
Any failure status will still be output to the user as well, to prevent silent failures.

resolves #142
2023-08-16 09:37:29 -05:00
Esteban Borai 4132892387 fix: use wrangler@3.5.1 by default 2023-08-15 17:23:30 -04:00
lrapoport-cf 62ce9d23a3 Merge pull request #155 from ethanppl/fix-readme
Fix examples in README.md
2023-08-14 13:23:31 -04:00
Ethan f089b0a195 Update README.md
Co-authored-by: lrapoport-cf <107272160+lrapoport-cf@users.noreply.github.com>
2023-08-14 22:06:06 +08:00
Ethan Pang 4318a2fb97 Fix examples in README.md 2023-08-14 18:19:03 +08:00
lrapoport-cf c8bbc2b667 Merge pull request #153 from cloudflare/lrapoport/update-codeowners
Add wrangler-admin as codeowner
2023-08-11 14:32:08 -04:00
lrapoport-cf 3c262de2e3 Add wrangler-admin as codeowner 2023-08-11 14:29:40 -04:00
Jacob M-G Evans 36ba30dcc9 Merge pull request #152 from cloudflare/JacobMGEvans-patch-1
Update README.md
2023-08-11 11:40:47 -05:00
Jacob M-G Evans a9ac89cd00 Update README.md 2023-08-11 11:37:23 -05:00
Jacob M-G Evans 93b26a6664 Merge pull request #151 from cloudflare/jacobmgevans/release-trigger
Changing publish trigger for build & tagging to released or edit
2023-08-10 17:10:35 -05:00
Jacob M-G Evans 9641d961b5 Changing publish trigger for build & tagging to released or edit 2023-08-10 17:09:55 -05:00
Jacob M-G Evans 5b3d60c156 Testing Changeset behavior 2023-08-10 16:51:52 -05:00
2 changed files with 146 additions and 127 deletions
+4 -1
View File
@@ -13,7 +13,10 @@ 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:
+142 -126
View File
@@ -2816,11 +2816,8 @@ 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)
});
@@ -2833,29 +2830,9 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
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: external "node:util"
const external_node_util_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:util");
;// CONCATENATED MODULE: ./src/index.ts
;// CONCATENATED MODULE: ./src/utils.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";
}
@@ -2875,51 +2852,97 @@ 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: 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.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"),
};
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() {
installWrangler();
authenticationSetup();
await execCommands((0,core.getMultilineInput)("preCommands"), "pre");
await uploadSecrets();
await wranglerCommands();
await execCommands((0,core.getMultilineInput)("postCommands"), "post");
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");
}
}
async function runProcess(command, options) {
try {
const result = await execAsync(command, options);
result.stdout && (0,core.info)(result.stdout.toString());
result.stderr && (0,core.error)(result.stderr.toString());
result.stdout && info(result.stdout.toString());
result.stderr && error(result.stderr.toString(), true);
return result;
}
catch (err) {
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}`);
err.stdout && info(err.stdout.toString());
err.stderr && error(err.stderr.toString(), true);
throw new Error(`\`${command}\` returned non-zero exit code.`);
}
}
function installWrangler() {
if (config["WRANGLER_VERSION"].startsWith("1")) {
(0,core.setFailed)(`🚨 Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`);
throw new Error(`Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`);
}
(0,core.startGroup)("📥 Installing Wrangler");
startGroup("📥 Installing Wrangler");
const command = `npm install wrangler@${config["WRANGLER_VERSION"]}`;
(0,core.info)(`Running command: ${command}`);
info(`Running command: ${command}`);
(0,external_node_child_process_namespaceObject.execSync)(command, { cwd: config["workingDirectory"], env: process.env });
(0,core.info)(`✅ Wrangler installed`);
(0,core.endGroup)();
info(`✅ Wrangler installed`, true);
endGroup();
}
function authenticationSetup() {
process.env.CLOUDFLARE_API_TOKEN = config["CLOUDFLARE_API_TOKEN"];
@@ -2929,53 +2952,48 @@ async function execCommands(commands, cmdType) {
if (!commands.length) {
return;
}
(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,
startGroup(`🚀 Running ${cmdType}Commands`);
try {
const arrPromises = commands.map(async (command) => {
const cmd = command.startsWith("wrangler")
? `${getNpxCmd()} ${command}`
: command;
info(`🚀 Executing command: ${cmd}`);
return await runProcess(cmd, {
cwd: config["workingDirectory"],
env: process.env,
});
});
});
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)();
await Promise.all(arrPromises);
}
finally {
endGroup();
}
}
/**
* A helper function to get the secret from the environment variables.
*/
function getSecret(secret) {
if (!secret) {
(0,core.setFailed)("No secret provided");
throw new Error("Secret name cannot be blank.");
}
const value = process.env[secret];
if (!value) {
(0,core.setFailed)(`Secret ${secret} not found`);
throw new Error(`Value for secret ${secret} not found.`);
}
return value;
}
async function legacyUploadSecrets(secrets, environment, workingDirectory) {
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`);
}
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);
}
async function uploadSecrets() {
const secrets = config["secrets"];
@@ -2984,8 +3002,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) => {
@@ -3001,13 +3019,14 @@ async function uploadSecrets() {
env: process.env,
stdio: "ignore",
});
(0,core.info)(`✅ Uploaded secrets`);
info(`✅ Uploaded secrets`);
}
catch {
(0,core.setFailed)(`🚨 Error uploading secrets`);
catch (err) {
error(`❌ Upload failed`);
throw new Error(`Failed to upload secrets.`);
}
finally {
(0,core.endGroup)();
endGroup();
}
}
function getVarArgs() {
@@ -3017,54 +3036,51 @@ function getVarArgs() {
return `${envVar}:${process.env[envVar]}`;
}
else {
(0,core.setFailed)(`🚨 ${envVar} not found in variables.`);
throw new Error(`Value for var ${envVar} not found in environment.`);
}
});
return envVarArray.length > 0 ? `--var ${envVarArray.join(" ").trim()}` : "";
}
async function wranglerCommands() {
(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}`);
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);
}
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,
const arrPromises = commands.map(async (command) => {
if (environment.length > 0 && !command.includes(`--env`)) {
command = command.concat(` --env ${environment}`);
}
const cmd = `${getNpxCmd()} 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,
});
});
});
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)();
await Promise.all(arrPromises);
}
finally {
endGroup();
}
}
main().catch(() => (0,core.setFailed)("🚨 Action failed"));
main();
})();
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__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 };
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 };