Compare commits

..

49 Commits

Author SHA1 Message Date
github-actions[bot] 3870f7e9d7 Automatic compilation 2023-10-10 14:28:57 +00:00
Cina Saffary 556068fb59 Merge pull request #191 from cloudflare/changeset-release/main
Version Packages
2023-10-10 09:25:51 -05:00
github-actions[bot] caa59485d0 Version Packages 2023-10-10 14:16:00 +00:00
Cina Saffary c2494c1ca6 Merge pull request #190 from cloudflare/cina/180-fix-undefined-package-manager
Use npm as fallback if no `packageManager` specified
2023-10-10 09:14:13 -05:00
Cina Saffary 528687aaf4 Refactor to use npm as a fallback if no packageManager specified...
and no lockfile is present. Fixes #180
2023-10-09 17:20:09 -05:00
lrapoport-cf bd50d10af9 Merge pull request #185 from cloudflare/lrapoport/fix-issue-workflow
Fix issue workflow
2023-10-05 15:34:02 -04:00
lrapoport-cf 2513ffc6cc Fix workflow syntax for multiple conditions 2023-10-05 15:29:35 -04:00
lrapoport-cf 9df50d42e4 Merge pull request #182 from cloudflare/lrapoport/update-issues-workflow
Update issues workflow
2023-10-05 15:06:06 -04:00
lrapoport-cf 4611c14c05 Fix format 2023-10-05 15:01:41 -04:00
lrapoport-cf ac3f259fcf Add PR workflow 2023-10-02 11:29:17 -04:00
lrapoport-cf b2645622e9 Rename issue workflow and job 2023-10-02 11:29:03 -04:00
lrapoport-cf f4e6269765 Add transferred issues to workers-sdk GH project 2023-10-02 11:26:14 -04:00
Cina Saffary 72931e59b2 Merge pull request #174 from cloudflare/changeset-release/main
Version Packages
2023-10-02 10:23:58 -05:00
github-actions[bot] e0254d06bc Version Packages 2023-09-18 19:12:19 +00:00
Jacob M-G Evans 13d70757d2 Merge pull request #166 from nix6839/many-package-manager
Support many package managers
2023-09-18 14:11:51 -05:00
Han Yeong-woo aec73ae744 Add wangler files in fixtures 2023-09-19 03:52:00 +09:00
Han Yeong-woo f0cc3efccf Install yarn and pnpm on test 2023-09-19 03:51:27 +09:00
Han Yeong-woo 50b529e7b8 Fix pass arg issue 2023-09-19 03:50:54 +09:00
Han Yeong-woo 6771675815 Run format 2023-09-19 01:37:01 +09:00
Jacob M-G Evans 4ae0557f8d Update two-rocks-hope.md 2023-09-18 11:33:50 -05:00
Han Yeong-woo 7d7b98826e Add changeset 2023-09-19 01:30:36 +09:00
Han Yeong-woo d1073d57ba Run format 2023-09-19 01:30:35 +09:00
Han Yeong-woo c3b99e2c18 Ignore to pnpm-lock.yaml in formatting 2023-09-19 01:30:35 +09:00
Han Yeong-woo 2375787b23 Move test fixtures to parent directory 2023-09-19 01:30:35 +09:00
Han Yeong-woo 11f981cea4 Add tests for package managers support 2023-09-19 01:30:34 +09:00
Han Yeong-woo 868dbd9a40 Remove unused function 2023-09-19 01:30:34 +09:00
Han Yeong-woo a009342d77 Add packageManager setting 2023-09-19 01:30:34 +09:00
Han Yeong-woo f2e4cda4dd Detect package manager and uses its commands
Fix #156
2023-09-19 01:30:33 +09:00
Han Yeong-woo f4f2e854d7 Add isValidPackcageManager() util 2023-09-19 01:30:33 +09:00
Han Yeong-woo cbe5f5b523 Add detect package manager util function 2023-09-19 01:30:33 +09:00
Jacob M-G Evans fcf2d83f3d Merge pull request #172 from cloudflare/demosjarco/main
Node 20 update
2023-09-18 11:29:49 -05:00
DemosJarco f5d1ca36ae Added comment with link 2023-09-04 11:54:36 -07:00
DemosJarco 4d6d6abfb4 Update action.yml 2023-09-04 11:50:59 -07: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
2 changed files with 159 additions and 118 deletions
+6 -1
View File
@@ -4,7 +4,8 @@ branding:
color: "orange"
description: "Deploy your Cloudflare projects from GitHub using Wrangler"
runs:
using: "node16"
# Possible values: https://github.com/actions/runner/blob/main/src/Runner.Common/Util/NodeUtil.cs#L9
using: "node20"
main: "dist/index.mjs"
inputs:
apiToken:
@@ -40,3 +41,7 @@ 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, a value will be inferred based on the presence of a lockfile. Valid values: [npm, pnpm, yarn]"
required: false
default: npm
+153 -117
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)
});
@@ -2829,12 +2826,81 @@ __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: external "node:util"
const external_node_util_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:util");
;// CONCATENATED MODULE: ./src/utils.ts
/**
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
*/
function semverCompare(version1, version2) {
if (version2 === "latest")
return true;
const version1Parts = version1.split(".");
const version2Parts = version2.split(".");
for (const version1Part of version1Parts) {
const version2Part = version2Parts.shift();
if (version1Part !== version2Part && version2Part) {
return version1Part < version2Part ? true : false;
}
}
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",
},
};
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";
}
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
@@ -2856,10 +2922,11 @@ const config = {
VARS: (0,core.getMultilineInput)("vars"),
COMMANDS: (0,core.getMultilineInput)("command"),
QUIET_MODE: (0,core.getBooleanInput)("quiet"),
PACKAGE_MANAGER: (0,core.getInput)("packageManager"),
};
function getNpxCmd() {
return process.env.RUNNER_OS === "Windows" ? "npx.cmd" : "npx";
}
const packageManager = getPackageManager(config.PACKAGE_MANAGER, {
workingDirectory: config.workingDirectory,
});
function info(message, bypass) {
if (!config.QUIET_MODE || bypass) {
(0,core.info)(message);
@@ -2880,30 +2947,20 @@ function endGroup() {
(0,core.endGroup)();
}
}
/**
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
*/
function semverCompare(version1, version2) {
if (version2 === "latest")
return true;
const version1Parts = version1.split(".");
const version2Parts = version2.split(".");
for (const version1Part of version1Parts) {
const version2Part = version2Parts.shift();
if (version1Part !== version2Part && version2Part) {
return version1Part < version2Part ? true : false;
}
}
return false;
}
async function main() {
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);
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 {
@@ -2915,29 +2972,15 @@ async function runProcess(command, options) {
catch (err) {
err.stdout && info(err.stdout.toString());
err.stderr && error(err.stderr.toString(), true);
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}`);
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`);
}
startGroup("📥 Installing Wrangler");
const command = `npm install wrangler@${config["WRANGLER_VERSION"]}`;
const command = `${packageManager.install} wrangler@${config["WRANGLER_VERSION"]}`;
info(`Running command: ${command}`);
(0,external_node_child_process_namespaceObject.execSync)(command, { cwd: config["workingDirectory"], env: process.env });
info(`✅ Wrangler installed`, true);
@@ -2952,52 +2995,47 @@ async function execCommands(commands, cmdType) {
return;
}
startGroup(`🚀 Running ${cmdType}Commands`);
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,
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,
});
});
});
await Promise.all(arrPromises).catch((result) => {
result.stdout && info(result.stdout.toString());
result.stderr && error(result.stderr.toString(), true);
(0,core.setFailed)(`🚨 ${cmdType}Commands failed`);
});
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)} | ${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);
}
async function uploadSecrets() {
const secrets = config["secrets"];
@@ -3006,8 +3044,8 @@ async function uploadSecrets() {
if (!secrets.length) {
return;
}
startGroup("🔑 Uploading secrets...");
try {
startGroup("🔑 Uploading Secrets");
if (semverCompare(config["WRANGLER_VERSION"], "3.4.0"))
return legacyUploadSecrets(secrets, environment, workingDirectory);
const secretObj = secrets.reduce((acc, secret) => {
@@ -3017,7 +3055,7 @@ async function uploadSecrets() {
const environmentSuffix = !environment.length
? ""
: ` --env ${environment}`;
const secretCmd = `echo "${JSON.stringify(secretObj).replaceAll('"', '\\"')}" | ${getNpxCmd()} wrangler secret:bulk ${environmentSuffix}`;
const secretCmd = `echo "${JSON.stringify(secretObj).replaceAll('"', '\\"')}" | ${packageManager.exec} wrangler secret:bulk ${environmentSuffix}`;
(0,external_node_child_process_namespaceObject.execSync)(secretCmd, {
cwd: workingDirectory,
env: process.env,
@@ -3025,8 +3063,9 @@ async function uploadSecrets() {
});
info(`✅ Uploaded secrets`);
}
catch {
(0,core.setFailed)(`🚨 Error uploading secrets`);
catch (err) {
error(`❌ Upload failed`);
throw new Error(`Failed to upload secrets.`);
}
finally {
endGroup();
@@ -3039,54 +3078,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() {
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}`);
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();
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 = `${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,
});
});
});
await Promise.all(arrPromises).catch((result) => {
result.stdout && info(result.stdout.toString());
result.stderr && error(result.stderr.toString());
(0,core.setFailed)(`🚨 Command failed`);
});
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 };