Skip to content

Commit b71ad75

Browse files
authored
Silent Settings (JamesIves#347)
1 parent c4c5b7b commit b71ad75

File tree

6 files changed

+108
-35
lines changed

6 files changed

+108
-35
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ In addition to the deployment options you must also configure the following.
147147
| `CLEAN` | If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to `true`. | `with` | **No** |
148148
| `CLEAN_EXCLUDE` | If you need to use `CLEAN` but you'd like to preserve certain files or folders you can use this option. This should be formatted as an array but stored as a string. For example: `'["filename.js", "folder"]'` | `with` | **No** |
149149
| `SINGLE_COMMIT` | This option can be toggled to `true` if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history. **Using this option will also cause any existing history to be wiped from the deployment branch**. | `with` | **No** |
150+
| `SILENT` | Silences the action output preventing it from displaying git messages and error. | `with` | **No** |
150151
| `WORKSPACE` | This should point to where your project lives on the virtual machine. The GitHub Actions environment will set this for you. It is only neccersary to set this variable if you're using the node module. | `with` | **No** |
151152

152153
With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.
@@ -320,4 +321,4 @@ If you're using a custom domain and require a `CNAME` file, or if you require th
320321

321322
### Debugging 🐝
322323

323-
By default the git commands are hidden from the logs. If you'd like to turn them on you can set the `ACTIONS_STEP_DEBUG` environment variable to true within the [Settings/Secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets) menu. If you're using this action in your own project as a node module via yarn or npm **you may expose your secrets if you toggle this on in a production environment**. You can learn more about debugging GitHub actions [here](https://github.com/actions/toolkit/blob/master/docs/action-debugging.md).
324+
If you'd like to enable action debugging you can set the `ACTIONS_STEP_DEBUG` environment variable to true within the [Settings/Secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets) menu. If you're using this action in your own project as a node module via yarn or npm **you may expose your secrets if you toggle this on in a production environment**. You can learn more about debugging GitHub actions [here](https://github.com/actions/toolkit/blob/master/docs/action-debugging.md).

__tests__/execute.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jest.mock('@actions/exec', () => ({
66
}))
77

88
describe('execute', () => {
9-
it('should be called with the correct arguments', async () => {
9+
it('should be called with the correct arguments when silent mode is enabled', async () => {
1010
stdout('hello')
11-
await execute('echo Montezuma', './')
11+
await execute('echo Montezuma', './', true)
1212

1313
expect(exec).toBeCalledWith('echo Montezuma', [], {
1414
cwd: './',
@@ -19,11 +19,11 @@ describe('execute', () => {
1919
})
2020
})
2121

22-
it('should not silence the input when INPUT_DEBUG is defined', async () => {
22+
it('should not silence the input when action.silent is false', async () => {
2323
process.env['RUNNER_DEBUG'] = '1'
2424

2525
stdout('hello')
26-
await execute('echo Montezuma', './')
26+
await execute('echo Montezuma', './', false)
2727

2828
expect(exec).toBeCalledWith('echo Montezuma', [], {
2929
cwd: './',

__tests__/git.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('git', () => {
3333
describe('init', () => {
3434
it('should execute commands if a GitHub token is provided', async () => {
3535
Object.assign(action, {
36+
silent: false,
3637
repositoryPath: 'JamesIves/github-pages-deploy-action',
3738
folder: 'assets',
3839
branch: 'branch',
@@ -49,6 +50,7 @@ describe('git', () => {
4950

5051
it('should execute commands if an Access Token is provided', async () => {
5152
Object.assign(action, {
53+
silent: false,
5254
repositoryPath: 'JamesIves/github-pages-deploy-action',
5355
folder: 'assets',
5456
branch: 'branch',
@@ -65,6 +67,7 @@ describe('git', () => {
6567

6668
it('should execute commands if SSH is true', async () => {
6769
Object.assign(action, {
70+
silent: false,
6871
repositoryPath: 'JamesIves/github-pages-deploy-action',
6972
folder: 'assets',
7073
branch: 'branch',
@@ -82,6 +85,7 @@ describe('git', () => {
8285

8386
it('should fail if there is no provided GitHub Token, Access Token or SSH bool', async () => {
8487
Object.assign(action, {
88+
silent: false,
8589
repositoryPath: null,
8690
folder: 'assets',
8791
branch: 'branch',
@@ -103,6 +107,7 @@ describe('git', () => {
103107

104108
it('should fail if access token is defined but it is an empty string', async () => {
105109
Object.assign(action, {
110+
silent: false,
106111
repositoryPath: null,
107112
folder: 'assets',
108113
branch: 'branch',
@@ -125,6 +130,7 @@ describe('git', () => {
125130

126131
it('should fail if there is no folder', async () => {
127132
Object.assign(action, {
133+
silent: false,
128134
repositoryPath: 'JamesIves/github-pages-deploy-action',
129135
gitHubToken: '123',
130136
branch: 'branch',
@@ -148,6 +154,7 @@ describe('git', () => {
148154

149155
it('should fail if there is no provided repository path', async () => {
150156
Object.assign(action, {
157+
silent: true,
151158
repositoryPath: null,
152159
folder: 'assets',
153160
branch: 'branch',
@@ -172,6 +179,7 @@ describe('git', () => {
172179

173180
it('should fail if the build folder begins with a /', async () => {
174181
Object.assign(action, {
182+
silent: false,
175183
accessToken: '123',
176184
repositoryPath: 'JamesIves/github-pages-deploy-action',
177185
branch: 'branch',
@@ -194,6 +202,7 @@ describe('git', () => {
194202

195203
it('should fail if the build folder begins with a ./', async () => {
196204
Object.assign(action, {
205+
silent: false,
197206
accessToken: '123',
198207
branch: 'branch',
199208
folder: './',
@@ -215,6 +224,7 @@ describe('git', () => {
215224

216225
it('should not fail if root is used', async () => {
217226
Object.assign(action, {
227+
silent: false,
218228
repositoryPath: 'JamesIves/github-pages-deploy-action',
219229
accessToken: '123',
220230
branch: 'branch',
@@ -235,6 +245,7 @@ describe('git', () => {
235245
describe('generateBranch', () => {
236246
it('should execute six commands', async () => {
237247
Object.assign(action, {
248+
silent: false,
238249
accessToken: '123',
239250
branch: 'branch',
240251
folder: '.',
@@ -250,6 +261,7 @@ describe('git', () => {
250261

251262
it('should fail if there is no branch', async () => {
252263
Object.assign(action, {
264+
silent: false,
253265
accessToken: '123',
254266
branch: null,
255267
folder: '.',
@@ -272,6 +284,7 @@ describe('git', () => {
272284
describe('switchToBaseBranch', () => {
273285
it('should execute one command', async () => {
274286
Object.assign(action, {
287+
silent: false,
275288
accessToken: '123',
276289
branch: 'branch',
277290
folder: '.',
@@ -287,6 +300,7 @@ describe('git', () => {
287300

288301
it('should execute one command if using custom baseBranch', async () => {
289302
Object.assign(action, {
303+
silent: false,
290304
baseBranch: '123',
291305
accessToken: '123',
292306
branch: 'branch',
@@ -303,6 +317,7 @@ describe('git', () => {
303317

304318
it('should fail if one of the required parameters is not available', async () => {
305319
Object.assign(action, {
320+
silent: false,
306321
baseBranch: '123',
307322
accessToken: null,
308323
gitHubToken: null,
@@ -329,6 +344,7 @@ describe('git', () => {
329344
describe('deploy', () => {
330345
it('should execute commands', async () => {
331346
Object.assign(action, {
347+
silent: false,
332348
folder: 'assets',
333349
branch: 'branch',
334350
gitHubToken: '123',
@@ -348,6 +364,7 @@ describe('git', () => {
348364

349365
it('should execute commands with single commit toggled', async () => {
350366
Object.assign(action, {
367+
silent: false,
351368
folder: 'assets',
352369
branch: 'branch',
353370
gitHubToken: '123',
@@ -368,6 +385,7 @@ describe('git', () => {
368385
it('should execute commands with clean options, ommits sha commit message', async () => {
369386
process.env.GITHUB_SHA = ''
370387
Object.assign(action, {
388+
silent: false,
371389
folder: 'assets',
372390
branch: 'branch',
373391
gitHubToken: '123',
@@ -388,6 +406,7 @@ describe('git', () => {
388406

389407
it('should execute commands with clean options stored as an array instead', async () => {
390408
Object.assign(action, {
409+
silent: false,
391410
folder: 'assets',
392411
branch: 'branch',
393412
gitHubToken: '123',
@@ -408,6 +427,7 @@ describe('git', () => {
408427

409428
it('should gracefully handle incorrectly formatted clean exclude items', async () => {
410429
Object.assign(action, {
430+
silent: false,
411431
folder: '.',
412432
branch: 'branch',
413433
gitHubToken: '123',
@@ -428,6 +448,7 @@ describe('git', () => {
428448

429449
it('should stop early if there is nothing to commit', async () => {
430450
Object.assign(action, {
451+
silent: false,
431452
folder: 'assets',
432453
branch: 'branch',
433454
gitHubToken: '123',
@@ -446,6 +467,7 @@ describe('git', () => {
446467

447468
it('should throw an error if one of the required parameters is not available', async () => {
448469
Object.assign(action, {
470+
silent: false,
449471
folder: 'assets',
450472
branch: 'branch',
451473
ssh: null,

src/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export interface ActionInterface {
3838
root?: string
3939
/** Wipes the commit history from the deployment branch in favor of a single commit. */
4040
singleCommit?: boolean | null
41+
/** Determines if the action should run in silent mode or not. */
42+
silent?: boolean
4143
/** Set to true if you're using an ssh client in your build step. */
4244
ssh?: boolean | null
4345
/** If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. */
@@ -87,6 +89,9 @@ export const action: ActionInterface = {
8789
singleCommit: !isNullOrUndefined(getInput('SINGLE_COMMIT'))
8890
? getInput('SINGLE_COMMIT').toLowerCase() === 'true'
8991
: false,
92+
silent: !isNullOrUndefined(getInput('SILENT'))
93+
? getInput('SILENT').toLowerCase() === 'true'
94+
: false,
9095
ssh: !isNullOrUndefined(getInput('SSH'))
9196
? getInput('SSH').toLowerCase() === 'true'
9297
: false,

src/execute.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {isDebug} from '@actions/core'
21
import {exec} from '@actions/exec'
32

43
let output: string
@@ -8,13 +7,18 @@ let output: string
87
*
98
* @param {string} cmd - The command to execute.
109
* @param {string} cwd - The current working directory.
10+
* @param {boolean} silent - Determines if the in/out should be silenced or not.
1111
*/
12-
export async function execute(cmd: string, cwd: string): Promise<any> {
12+
export async function execute(
13+
cmd: string,
14+
cwd: string,
15+
silent?: boolean
16+
): Promise<any> {
1317
output = ''
1418

1519
await exec(cmd, [], {
1620
// Silences the input unless the INPUT_DEBUG flag is set.
17-
silent: isDebug() ? false : true,
21+
silent,
1822
cwd,
1923
listeners: {
2024
stdout

0 commit comments

Comments
 (0)