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
This commit is contained in:
Jacob M-G Evans 2023-08-11 15:36:20 -05:00
parent 36ba30dcc9
commit 3f40637a1c
No known key found for this signature in database
GPG key ID: 2A0C497CAB123094
9 changed files with 134 additions and 73 deletions

View file

@ -0,0 +1,12 @@
---
"wrangler-action": minor
---
feat: Quiet mode
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

View file

@ -34,6 +34,15 @@ jobs:
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --dry-run
- name: Only build app w/ quiet enabled
uses: ./
with:
quiet: true
workingDirectory: "./test/base"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --dry-run
# START Setup and teardown of Worker Environment Tests
- name: Environment support
uses: ./

View file

@ -8,9 +8,11 @@ function workerHealthCheck() {
const response = buffer.toString();
response.includes("OK")
? console.log(`Status: Worker is up! Secrets: ${response}`)
: console.log(`Worker is down!`);
if (response.includes("OK")) {
console.log(`Status: Worker is up! Response: ${response}`);
} else {
throw new Error(`Worker is down! Response: ${response}`);
}
return response;
}

1
action-env-setup.ts Normal file
View file

@ -0,0 +1 @@
process.env.INPUT_QUIET ??= "false";

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:

114
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "wrangler-action",
"version": "3.0.1",
"version": "3.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "wrangler-action",
"version": "3.0.1",
"version": "3.0.2",
"license": "MIT OR Apache-2.0",
"dependencies": {
"@actions/core": "^1.10.0"
@ -14,12 +14,12 @@
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@cloudflare/workers-types": "^4.20230710.1",
"@types/node": "^20.4.2",
"@cloudflare/workers-types": "^4.20230814.0",
"@types/node": "^20.5.0",
"@vercel/ncc": "^0.36.1",
"prettier": "^3.0.0",
"prettier": "^3.0.1",
"typescript": "^5.1.6",
"vitest": "^0.33.0"
"vitest": "^0.34.1"
}
},
"node_modules/@actions/core": {
@ -366,9 +366,9 @@
}
},
"node_modules/@cloudflare/workers-types": {
"version": "4.20230801.0",
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20230801.0.tgz",
"integrity": "sha512-RzRUR+J/T3h58qbTZHYntYsnZXu3JnrlZIhqP2hhdyfoZAZ/+ko4wX0foAqlYHi+kXWaWtySHBuMcx6ec6TXlQ==",
"version": "4.20230814.0",
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20230814.0.tgz",
"integrity": "sha512-+jHiGjZg2UpULZSSHmHLqUG45TLg1s+uppSMlGvMn0u/xyFsRX9HX6b8Ydg/oHSp3jfSuPtX05GSvtgRAmrWTg==",
"dev": true
},
"node_modules/@esbuild/android-arm": {
@ -879,9 +879,9 @@
"dev": true
},
"node_modules/@types/node": {
"version": "20.4.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.6.tgz",
"integrity": "sha512-q0RkvNgMweWWIvSMDiXhflGUKMdIxBo2M2tYM/0kEGDueQByFzK4KZAgu5YHGFNxziTlppNpTIBcqHQAxlfHdA==",
"version": "20.5.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.0.tgz",
"integrity": "sha512-Mgq7eCtoTjT89FqNoTzzXg2XvCi5VMhRV6+I2aYanc6kQCBImeNaAYRs/DyoVqk1YEUJK5gN9VO7HRIdz4Wo3Q==",
"dev": true
},
"node_modules/@types/normalize-package-data": {
@ -906,13 +906,13 @@
}
},
"node_modules/@vitest/expect": {
"version": "0.33.0",
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-0.33.0.tgz",
"integrity": "sha512-sVNf+Gla3mhTCxNJx+wJLDPp/WcstOe0Ksqz4Vec51MmgMth/ia0MGFEkIZmVGeTL5HtjYR4Wl/ZxBxBXZJTzQ==",
"version": "0.34.1",
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-0.34.1.tgz",
"integrity": "sha512-q2CD8+XIsQ+tHwypnoCk8Mnv5e6afLFvinVGCq3/BOT4kQdVQmY6rRfyKkwcg635lbliLPqbunXZr+L1ssUWiQ==",
"dev": true,
"dependencies": {
"@vitest/spy": "0.33.0",
"@vitest/utils": "0.33.0",
"@vitest/spy": "0.34.1",
"@vitest/utils": "0.34.1",
"chai": "^4.3.7"
},
"funding": {
@ -920,12 +920,12 @@
}
},
"node_modules/@vitest/runner": {
"version": "0.33.0",
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-0.33.0.tgz",
"integrity": "sha512-UPfACnmCB6HKRHTlcgCoBh6ppl6fDn+J/xR8dTufWiKt/74Y9bHci5CKB8tESSV82zKYtkBJo9whU3mNvfaisg==",
"version": "0.34.1",
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-0.34.1.tgz",
"integrity": "sha512-YfQMpYzDsYB7yqgmlxZ06NI4LurHWfrH7Wy3Pvf/z/vwUSgq1zLAb1lWcItCzQG+NVox+VvzlKQrYEXb47645g==",
"dev": true,
"dependencies": {
"@vitest/utils": "0.33.0",
"@vitest/utils": "0.34.1",
"p-limit": "^4.0.0",
"pathe": "^1.1.1"
},
@ -949,9 +949,9 @@
}
},
"node_modules/@vitest/snapshot": {
"version": "0.33.0",
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-0.33.0.tgz",
"integrity": "sha512-tJjrl//qAHbyHajpFvr8Wsk8DIOODEebTu7pgBrP07iOepR5jYkLFiqLq2Ltxv+r0uptUb4izv1J8XBOwKkVYA==",
"version": "0.34.1",
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-0.34.1.tgz",
"integrity": "sha512-0O9LfLU0114OqdF8lENlrLsnn024Tb1CsS9UwG0YMWY2oGTQfPtkW+B/7ieyv0X9R2Oijhi3caB1xgGgEgclSQ==",
"dev": true,
"dependencies": {
"magic-string": "^0.30.1",
@ -963,9 +963,9 @@
}
},
"node_modules/@vitest/spy": {
"version": "0.33.0",
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-0.33.0.tgz",
"integrity": "sha512-Kv+yZ4hnH1WdiAkPUQTpRxW8kGtH8VRTnus7ZTGovFYM1ZezJpvGtb9nPIjPnptHbsyIAxYZsEpVPYgtpjGnrg==",
"version": "0.34.1",
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-0.34.1.tgz",
"integrity": "sha512-UT4WcI3EAPUNO8n6y9QoEqynGGEPmmRxC+cLzneFFXpmacivjHZsNbiKD88KUScv5DCHVDgdBsLD7O7s1enFcQ==",
"dev": true,
"dependencies": {
"tinyspy": "^2.1.1"
@ -975,9 +975,9 @@
}
},
"node_modules/@vitest/utils": {
"version": "0.33.0",
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-0.33.0.tgz",
"integrity": "sha512-pF1w22ic965sv+EN6uoePkAOTkAPWM03Ri/jXNyMIKBb/XHLDPfhLvf/Fa9g0YECevAIz56oVYXhodLvLQ/awA==",
"version": "0.34.1",
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-0.34.1.tgz",
"integrity": "sha512-/ql9dsFi4iuEbiNcjNHQWXBum7aL8pyhxvfnD9gNtbjR9fUKAjxhj4AA3yfLXg6gJpMGGecvtF8Au2G9y3q47Q==",
"dev": true,
"dependencies": {
"diff-sequences": "^29.4.3",
@ -3054,9 +3054,9 @@
}
},
"node_modules/prettier": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz",
"integrity": "sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==",
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.1.tgz",
"integrity": "sha512-fcOWSnnpCrovBsmFZIGIy9UqK2FaI7Hqax+DIO0A9UxeVoY4iweyaFjS5TavZN97Hfehph0nhsZnjlVKzEQSrQ==",
"dev": true,
"bin": {
"prettier": "bin/prettier.cjs"
@ -3288,9 +3288,9 @@
}
},
"node_modules/rollup": {
"version": "3.27.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-3.27.0.tgz",
"integrity": "sha512-aOltLCrYZ0FhJDm7fCqwTjIUEVjWjcydKBV/Zeid6Mn8BWgDCUBBWT5beM5ieForYNo/1ZHuGJdka26kvQ3Gzg==",
"version": "3.28.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-3.28.0.tgz",
"integrity": "sha512-d7zhvo1OUY2SXSM6pfNjgD5+d0Nz87CUp4mt8l/GgVP3oBsPwzNvSzyu1me6BSG9JIgWNTVcafIXBIyM8yQ3yw==",
"dev": true,
"bin": {
"rollup": "dist/bin/rollup"
@ -3772,9 +3772,9 @@
"dev": true
},
"node_modules/tinypool": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tinypool/-/tinypool-0.6.0.tgz",
"integrity": "sha512-FdswUUo5SxRizcBc6b1GSuLpLjisa8N8qMyYoP3rl+bym+QauhtJP5bvZY1ytt8krKGmMLYIRl36HBZfeAoqhQ==",
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/tinypool/-/tinypool-0.7.0.tgz",
"integrity": "sha512-zSYNUlYSMhJ6Zdou4cJwo/p7w5nmAH17GRfU/ui3ctvjXFErXXkruT4MWW6poDeXgCaIBlGLrfU6TbTXxyGMww==",
"dev": true,
"engines": {
"node": ">=14.0.0"
@ -4075,14 +4075,14 @@
}
},
"node_modules/vite": {
"version": "4.4.8",
"resolved": "https://registry.npmjs.org/vite/-/vite-4.4.8.tgz",
"integrity": "sha512-LONawOUUjxQridNWGQlNizfKH89qPigK36XhMI7COMGztz8KNY0JHim7/xDd71CZwGT4HtSRgI7Hy+RlhG0Gvg==",
"version": "4.4.9",
"resolved": "https://registry.npmjs.org/vite/-/vite-4.4.9.tgz",
"integrity": "sha512-2mbUn2LlUmNASWwSCNSJ/EG2HuSRTnVNaydp6vMCm5VIqJsjMfbIWtbH2kDuwUVW5mMUKKZvGPX/rqeqVvv1XA==",
"dev": true,
"dependencies": {
"esbuild": "^0.18.10",
"postcss": "^8.4.26",
"rollup": "^3.25.2"
"postcss": "^8.4.27",
"rollup": "^3.27.1"
},
"bin": {
"vite": "bin/vite.js"
@ -4130,9 +4130,9 @@
}
},
"node_modules/vite-node": {
"version": "0.33.0",
"resolved": "https://registry.npmjs.org/vite-node/-/vite-node-0.33.0.tgz",
"integrity": "sha512-19FpHYbwWWxDr73ruNahC+vtEdza52kA90Qb3La98yZ0xULqV8A5JLNPUff0f5zID4984tW7l3DH2przTJUZSw==",
"version": "0.34.1",
"resolved": "https://registry.npmjs.org/vite-node/-/vite-node-0.34.1.tgz",
"integrity": "sha512-odAZAL9xFMuAg8aWd7nSPT+hU8u2r9gU3LRm9QKjxBEF2rRdWpMuqkrkjvyVQEdNFiBctqr2Gg4uJYizm5Le6w==",
"dev": true,
"dependencies": {
"cac": "^6.7.14",
@ -4153,19 +4153,19 @@
}
},
"node_modules/vitest": {
"version": "0.33.0",
"resolved": "https://registry.npmjs.org/vitest/-/vitest-0.33.0.tgz",
"integrity": "sha512-1CxaugJ50xskkQ0e969R/hW47za4YXDUfWJDxip1hwbnhUjYolpfUn2AMOulqG/Dtd9WYAtkHmM/m3yKVrEejQ==",
"version": "0.34.1",
"resolved": "https://registry.npmjs.org/vitest/-/vitest-0.34.1.tgz",
"integrity": "sha512-G1PzuBEq9A75XSU88yO5G4vPT20UovbC/2osB2KEuV/FisSIIsw7m5y2xMdB7RsAGHAfg2lPmp2qKr3KWliVlQ==",
"dev": true,
"dependencies": {
"@types/chai": "^4.3.5",
"@types/chai-subset": "^1.3.3",
"@types/node": "*",
"@vitest/expect": "0.33.0",
"@vitest/runner": "0.33.0",
"@vitest/snapshot": "0.33.0",
"@vitest/spy": "0.33.0",
"@vitest/utils": "0.33.0",
"@vitest/expect": "0.34.1",
"@vitest/runner": "0.34.1",
"@vitest/snapshot": "0.34.1",
"@vitest/spy": "0.34.1",
"@vitest/utils": "0.34.1",
"acorn": "^8.9.0",
"acorn-walk": "^8.2.0",
"cac": "^6.7.14",
@ -4178,9 +4178,9 @@
"std-env": "^3.3.3",
"strip-literal": "^1.0.1",
"tinybench": "^2.5.0",
"tinypool": "^0.6.0",
"tinypool": "^0.7.0",
"vite": "^3.0.0 || ^4.0.0",
"vite-node": "0.33.0",
"vite-node": "0.34.1",
"why-is-node-running": "^2.2.2"
},
"bin": {

View file

@ -34,11 +34,11 @@
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@cloudflare/workers-types": "^4.20230710.1",
"@types/node": "^20.4.2",
"@cloudflare/workers-types": "^4.20230814.0",
"@types/node": "^20.5.0",
"@vercel/ncc": "^0.36.1",
"prettier": "^3.0.0",
"prettier": "^3.0.1",
"typescript": "^5.1.6",
"vitest": "^0.33.0"
"vitest": "^0.34.1"
}
}

View file

@ -1,11 +1,12 @@
import {
getInput,
getMultilineInput,
info,
setFailed,
endGroup,
startGroup,
error,
info as originalInfo,
error as originalError,
endGroup as originalEndGroup,
startGroup as originalStartGroup,
getBooleanInput,
} from "@actions/core";
import { execSync, exec } from "node:child_process";
import { existsSync } from "node:fs";
@ -27,12 +28,37 @@ const config = {
ENVIRONMENT: getInput("environment"),
VARS: getMultilineInput("vars"),
COMMANDS: getMultilineInput("command"),
QUIET_MODE: getBooleanInput("quiet"),
} as const;
function getNpxCmd() {
return process.env.RUNNER_OS === "Windows" ? "npx.cmd" : "npx";
}
function info(message: string, bypass?: boolean): void {
if (!config.QUIET_MODE || bypass) {
originalInfo(message);
}
}
function error(message: string, bypass?: boolean): void {
if (!config.QUIET_MODE || bypass) {
originalError(message);
}
}
function startGroup(name: string): void {
if (!config.QUIET_MODE) {
originalStartGroup(name);
}
}
function endGroup(): void {
if (!config.QUIET_MODE) {
originalEndGroup();
}
}
/**
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
*/
@ -60,6 +86,7 @@ async function main() {
await uploadSecrets();
await wranglerCommands();
await execCommands(getMultilineInput("postCommands"), "post");
info("🏁 Wrangler Action completed", true);
}
async function runProcess(
@ -70,12 +97,12 @@ async function runProcess(
const result = await execAsync(command, options);
result.stdout && info(result.stdout.toString());
result.stderr && error(result.stderr.toString());
result.stderr && error(result.stderr.toString(), true);
return result;
} catch (err: any) {
err.stdout && info(err.stdout.toString());
err.stderr && error(err.stderr.toString());
err.stderr && error(err.stderr.toString(), true);
throw err;
}
}
@ -105,7 +132,7 @@ function installWrangler() {
const command = `npm install wrangler@${config["WRANGLER_VERSION"]}`;
info(`Running command: ${command}`);
execSync(command, { cwd: config["workingDirectory"], env: process.env });
info(`✅ Wrangler installed`);
info(`✅ Wrangler installed`, true);
endGroup();
}
@ -135,7 +162,7 @@ async function execCommands(commands: string[], cmdType: string) {
await Promise.all(arrPromises).catch((result) => {
result.stdout && info(result.stdout.toString());
result.stderr && error(result.stderr.toString());
result.stderr && error(result.stderr.toString(), true);
setFailed(`🚨 ${cmdType}Commands failed`);
});
endGroup();

7
vitest.config.ts Normal file
View file

@ -0,0 +1,7 @@
import { defineConfig } from "vitest/dist/config";
export default defineConfig({
test: {
setupFiles: ["./action-env-setup.ts"],
},
});