Skip to content

Commit

Permalink
Quiet feature
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JacobMGEvans committed Aug 15, 2023
1 parent 36ba30d commit df2c9a0
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 70 deletions.
12 changes: 12 additions & 0 deletions .changeset/gold-moose-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"wrangler-action": patch
---

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
9 changes: 9 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ./
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/workerHealthCheck.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions action-env-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.env.INPUT_QUIET ??= "false";
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
114 changes: 57 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
37 changes: 32 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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): void {
if (config.QUIET_MODE) {
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.
*/
Expand Down Expand Up @@ -60,6 +86,7 @@ async function main() {
await uploadSecrets();
await wranglerCommands();
await execCommands(getMultilineInput("postCommands"), "post");
info("🏁 Wrangler Action completed", true);
}

async function runProcess(
Expand Down Expand Up @@ -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();
}

Expand Down
7 changes: 7 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "vitest/dist/config";

export default defineConfig({
test: {
setupFiles: ["./action-env-setup.ts"],
},
});

0 comments on commit df2c9a0

Please sign in to comment.