Skip to content

Commit fb344c2

Browse files
committed
Debugging Changes
1 parent 78f3c44 commit fb344c2

File tree

13 files changed

+450
-458
lines changed

13 files changed

+450
-458
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ 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
| `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** |
150-
| `DEBUG` | By default the git commands are hidden from the log. If you'd like to turn them on you can toggle this to `true`. **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**. | `with` | **No** |
151150

152151
With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.
153152

@@ -305,3 +304,9 @@ If you use a [container](https://help.github.com/en/actions/automating-your-work
305304
### Additional Build Files 📁
306305

307306
This action maintains the full git history of the deployment branch. Therefore if you're using a custom domain and require a `CNAME` file, or if you require the use of a `.nojekyll` file, you can safely commit these files directly into deployment branch without them being overridden after each deployment.
307+
308+
### Debugging 🐝
309+
310+
By default the git commands are hidden from the logs. If you'd like to turn them on you can set the `ACTIONS_RUNNER_DEBUG` environment variable within the `Settings/Secrets` menu.
311+
312+
If you're using this action in your own project as a node module via yarn or npm you'll need to set `RUNNER_DEBUG` as the environment variable instead. **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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jest.mock('@actions/exec', () => ({
77

88
describe('execute', () => {
99
it('should be called with the correct arguments', async () => {
10-
await stdout('hello')
10+
stdout('hello')
1111
await execute('echo Montezuma', './')
1212

1313
expect(exec).toBeCalledWith('echo Montezuma', [], {
@@ -20,9 +20,9 @@ describe('execute', () => {
2020
})
2121

2222
it('should not silence the input when INPUT_DEBUG is defined', async () => {
23-
process.env['DEBUG_DEPLOY_ACTION'] = 'yes'
23+
process.env['RUNNER_DEBUG'] = '1'
2424

25-
await stdout('hello')
25+
stdout('hello')
2626
await execute('echo Montezuma', './')
2727

2828
expect(exec).toBeCalledWith('echo Montezuma', [], {

__tests__/git.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ process.env['GITHUB_SHA'] = '123'
55
import {action} from '../src/constants'
66
import {deploy, generateBranch, init, switchToBaseBranch} from '../src/git'
77
import {execute} from '../src/execute'
8-
import {setFailed} from '@actions/core'
98

109
const originalAction = JSON.stringify(action)
1110

1211
jest.mock('@actions/core', () => ({
1312
setFailed: jest.fn(),
14-
getInput: jest.fn()
13+
getInput: jest.fn(),
14+
isDebug: jest.fn(),
15+
info: jest.fn()
1516
}))
1617

1718
jest.mock('../src/execute', () => ({

__tests__/main.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ jest.mock('../src/execute', () => ({
1818
jest.mock('@actions/core', () => ({
1919
setFailed: jest.fn(),
2020
getInput: jest.fn(),
21-
exportVariable: jest.fn()
21+
exportVariable: jest.fn(),
22+
isDebug: jest.fn(),
23+
info: jest.fn()
2224
}))
2325

2426
describe('main', () => {

__tests__/util.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe('util', () => {
159159
gitHubToken: 'anothersecret123333'
160160
}
161161

162-
process.env['INPUT_DEBUG'] = 'true'
162+
process.env['RUNNER_DEBUG'] = '1'
163163

164164
const string = `This is an error message! It contains ${action.accessToken} and ${action.gitHubToken} and ${action.repositoryPath}`
165165
expect(suppressSensitiveInformation(string, action)).toBe(

action.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,3 @@ inputs:
6363
WORKSPACE:
6464
description: "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."
6565
required: false
66-
67-
DEBUG:
68-
description: "By default the git commands are hidden from the log. If you'd like to turn them on you can toggle this to true."
69-
required: false

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@
3333
"deployment"
3434
],
3535
"dependencies": {
36-
"@actions/core": "^1.2.0",
37-
"@actions/exec": "^1.0.2",
38-
"@actions/github": "^2.0.0"
36+
"@actions/core": "1.2.3",
37+
"@actions/exec": "1.0.3",
38+
"@actions/github": "2.1.1"
3939
},
4040
"devDependencies": {
41-
"@types/jest": "^25.1.0",
42-
"@types/node": "^13.1.2",
43-
"jest": "^25.1.0",
44-
"jest-circus": "^25.1.0",
45-
"prettier": "^2.0.2",
46-
"ts-jest": "^25.0.0",
47-
"eslint": "^6.8.0",
48-
"eslint-plugin-github": "^3.4.1",
49-
"eslint-plugin-jest": "^23.8.2",
50-
"typescript": "^3.7.4"
41+
"@types/jest": "25.1.4",
42+
"@types/node": "13.9.4",
43+
"jest": "25.2.3",
44+
"jest-circus": "25.2.3",
45+
"prettier": "2.0.2",
46+
"ts-jest": "25.0.0",
47+
"eslint": "6.8.0",
48+
"eslint-plugin-github": "3.4.1",
49+
"eslint-plugin-jest": "23.8.2",
50+
"typescript": "3.7.4"
5151
}
5252
}

src/constants.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ export interface ActionInterface {
1818
cleanExclude?: string | string[]
1919
/** If you need to customize the commit message for an integration you can do so. */
2020
commitMessage?: string
21-
/** Unhides the Git commands from the function terminal. */
22-
debug?: boolean | string
2321
/** The default branch of the deployment. Similar to baseBranch if you're using this action as a module. */
2422
defaultBranch?: string
2523
/** The git config email. */
@@ -57,7 +55,6 @@ export const action: ActionInterface = {
5755
commitMessage: getInput('COMMIT_MESSAGE'),
5856
clean: getInput('CLEAN'),
5957
cleanExclude: getInput('CLEAN_EXCLUDE'),
60-
debug: getInput('DEBUG'),
6158
defaultBranch: process.env.GITHUB_SHA ? process.env.GITHUB_SHA : 'master',
6259
isTest: process.env.UNIT_TEST,
6360
ssh: getInput('SSH'),

src/execute.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {isDebug} from '@actions/core'
12
import {exec} from '@actions/exec'
23

34
let output: string
@@ -13,7 +14,7 @@ export async function execute(cmd: string, cwd: string): Promise<any> {
1314

1415
await exec(cmd, [], {
1516
// Silences the input unless the INPUT_DEBUG flag is set.
16-
silent: process.env.DEBUG_DEPLOY_ACTION ? false : true,
17+
silent: isDebug() ? false : true,
1718
cwd,
1819
listeners: {
1920
stdout

src/git.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {info} from '@actions/core'
12
import {ActionInterface} from './constants'
23
import {execute} from './execute'
34
import {
@@ -11,20 +12,25 @@ export async function init(action: ActionInterface): Promise<void | Error> {
1112
try {
1213
hasRequiredParameters(action)
1314

14-
console.log(`Deploying using ${action.tokenType} 🔑`)
15-
console.log('Configuring Git…')
15+
info(`Deploying using ${action.tokenType}... 🔑`)
16+
info('Configuring git...')
1617

1718
await execute(`git init`, action.workspace)
1819
await execute(`git config user.name "${action.name}"`, action.workspace)
1920
await execute(`git config user.email "${action.email}"`, action.workspace)
20-
await execute(`git remote rm origin`, action.workspace)
21-
await execute(
22-
`git remote add origin ${action.repositoryPath}`,
23-
action.workspace
24-
)
21+
22+
try {
23+
await execute(`git remote rm origin`, action.workspace)
24+
} finally {
25+
await execute(
26+
`git remote add origin ${action.repositoryPath}`,
27+
action.workspace
28+
)
29+
}
30+
2531
await execute(`git fetch`, action.workspace)
2632

27-
console.log('Git configured 🔧')
33+
info('Git configured... 🔧')
2834
} catch (error) {
2935
throw new Error(
3036
`There was an error initializing the repository: ${suppressSensitiveInformation(
@@ -63,13 +69,13 @@ export async function generateBranch(action: ActionInterface): Promise<void> {
6369
try {
6470
hasRequiredParameters(action)
6571

66-
console.log(`Creating the ${action.branch} branch`)
72+
info(`Creating the ${action.branch} branch...`)
6773

6874
await switchToBaseBranch(action)
6975
await execute(`git checkout --orphan ${action.branch}`, action.workspace)
7076
await execute(`git reset --hard`, action.workspace)
7177
await execute(
72-
`git commit --allow-empty -m "Initial ${action.branch} commit"`,
78+
`git commit --allow-empty -m "Initial ${action.branch} commit."`,
7379
action.workspace
7480
)
7581
await execute(
@@ -78,7 +84,7 @@ export async function generateBranch(action: ActionInterface): Promise<void> {
7884
)
7985
await execute(`git fetch`, action.workspace)
8086

81-
console.log(`Created the ${action.branch} branch 🔧`)
87+
info(`Created the ${action.branch} branch... 🔧`)
8288
} catch (error) {
8389
throw new Error(
8490
`There was an error creating the deployment branch: ${suppressSensitiveInformation(
@@ -93,7 +99,7 @@ export async function generateBranch(action: ActionInterface): Promise<void> {
9399
export async function deploy(action: ActionInterface): Promise<void> {
94100
const temporaryDeploymentDirectory = 'gh-action-temp-deployment-folder'
95101
const temporaryDeploymentBranch = 'gh-action-temp-deployment-branch'
96-
console.log('Starting to commit changes')
102+
info('Starting to commit changes...')
97103

98104
try {
99105
hasRequiredParameters(action)
@@ -132,7 +138,7 @@ export async function deploy(action: ActionInterface): Promise<void> {
132138
excludes += `--exclude ${item} `
133139
}
134140
} catch {
135-
console.log(
141+
info(
136142
'There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌'
137143
)
138144
}
@@ -165,7 +171,7 @@ export async function deploy(action: ActionInterface): Promise<void> {
165171
)
166172

167173
if (!hasFilesToCommit && !action.isTest) {
168-
console.log('There is nothing to commit. Exiting early 📭')
174+
info('There is nothing to commit. Exiting early... 📭')
169175
return
170176
}
171177

@@ -184,7 +190,7 @@ export async function deploy(action: ActionInterface): Promise<void> {
184190
? action.commitMessage
185191
: `Deploying to ${action.branch} from ${action.baseBranch}`
186192
} ${
187-
process.env.GITHUB_SHA ? `@ ${process.env.GITHUB_SHA}` : ''
193+
process.env.GITHUB_SHA ? `- ${process.env.GITHUB_SHA}` : ''
188194
} 🚀" --quiet`,
189195
`${action.workspace}/${temporaryDeploymentDirectory}`
190196
)
@@ -193,10 +199,10 @@ export async function deploy(action: ActionInterface): Promise<void> {
193199
`${action.workspace}/${temporaryDeploymentDirectory}`
194200
)
195201

196-
console.log(`Changes committed to the ${action.branch} branch 📦`)
202+
info(`Changes committed to the ${action.branch} branch... 📦`)
197203

198204
// Cleans up temporary files/folders and restores the git state.
199-
console.log('Running post deployment cleanup jobs')
205+
info('Running post deployment cleanup jobs...')
200206
await execute(
201207
`git checkout --progress --force ${action.defaultBranch}`,
202208
action.workspace

0 commit comments

Comments
 (0)