Debugging Changes

This commit is contained in:
JamesIves 2020-03-28 10:35:26 -04:00
parent 78f3c44617
commit fb344c2b78
13 changed files with 447 additions and 455 deletions

View File

@ -147,7 +147,6 @@ In addition to the deployment options you must also configure the following.
| `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** |
| `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** |
| `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** |
| `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** |
With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.
@ -305,3 +304,9 @@ If you use a [container](https://help.github.com/en/actions/automating-your-work
### Additional Build Files 📁
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.
### Debugging 🐝
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.
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).

View File

@ -7,7 +7,7 @@ jest.mock('@actions/exec', () => ({
describe('execute', () => {
it('should be called with the correct arguments', async () => {
await stdout('hello')
stdout('hello')
await execute('echo Montezuma', './')
expect(exec).toBeCalledWith('echo Montezuma', [], {
@ -20,9 +20,9 @@ describe('execute', () => {
})
it('should not silence the input when INPUT_DEBUG is defined', async () => {
process.env['DEBUG_DEPLOY_ACTION'] = 'yes'
process.env['RUNNER_DEBUG'] = '1'
await stdout('hello')
stdout('hello')
await execute('echo Montezuma', './')
expect(exec).toBeCalledWith('echo Montezuma', [], {

View File

@ -5,13 +5,14 @@ process.env['GITHUB_SHA'] = '123'
import {action} from '../src/constants'
import {deploy, generateBranch, init, switchToBaseBranch} from '../src/git'
import {execute} from '../src/execute'
import {setFailed} from '@actions/core'
const originalAction = JSON.stringify(action)
jest.mock('@actions/core', () => ({
setFailed: jest.fn(),
getInput: jest.fn()
getInput: jest.fn(),
isDebug: jest.fn(),
info: jest.fn()
}))
jest.mock('../src/execute', () => ({

View File

@ -18,7 +18,9 @@ jest.mock('../src/execute', () => ({
jest.mock('@actions/core', () => ({
setFailed: jest.fn(),
getInput: jest.fn(),
exportVariable: jest.fn()
exportVariable: jest.fn(),
isDebug: jest.fn(),
info: jest.fn()
}))
describe('main', () => {

View File

@ -159,7 +159,7 @@ describe('util', () => {
gitHubToken: 'anothersecret123333'
}
process.env['INPUT_DEBUG'] = 'true'
process.env['RUNNER_DEBUG'] = '1'
const string = `This is an error message! It contains ${action.accessToken} and ${action.gitHubToken} and ${action.repositoryPath}`
expect(suppressSensitiveInformation(string, action)).toBe(

View File

@ -63,7 +63,3 @@ inputs:
WORKSPACE:
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."
required: false
DEBUG:
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."
required: false

View File

@ -33,20 +33,20 @@
"deployment"
],
"dependencies": {
"@actions/core": "^1.2.0",
"@actions/exec": "^1.0.2",
"@actions/github": "^2.0.0"
"@actions/core": "1.2.3",
"@actions/exec": "1.0.3",
"@actions/github": "2.1.1"
},
"devDependencies": {
"@types/jest": "^25.1.0",
"@types/node": "^13.1.2",
"jest": "^25.1.0",
"jest-circus": "^25.1.0",
"prettier": "^2.0.2",
"ts-jest": "^25.0.0",
"eslint": "^6.8.0",
"eslint-plugin-github": "^3.4.1",
"eslint-plugin-jest": "^23.8.2",
"typescript": "^3.7.4"
"@types/jest": "25.1.4",
"@types/node": "13.9.4",
"jest": "25.2.3",
"jest-circus": "25.2.3",
"prettier": "2.0.2",
"ts-jest": "25.0.0",
"eslint": "6.8.0",
"eslint-plugin-github": "3.4.1",
"eslint-plugin-jest": "23.8.2",
"typescript": "3.7.4"
}
}

View File

@ -18,8 +18,6 @@ export interface ActionInterface {
cleanExclude?: string | string[]
/** If you need to customize the commit message for an integration you can do so. */
commitMessage?: string
/** Unhides the Git commands from the function terminal. */
debug?: boolean | string
/** The default branch of the deployment. Similar to baseBranch if you're using this action as a module. */
defaultBranch?: string
/** The git config email. */
@ -57,7 +55,6 @@ export const action: ActionInterface = {
commitMessage: getInput('COMMIT_MESSAGE'),
clean: getInput('CLEAN'),
cleanExclude: getInput('CLEAN_EXCLUDE'),
debug: getInput('DEBUG'),
defaultBranch: process.env.GITHUB_SHA ? process.env.GITHUB_SHA : 'master',
isTest: process.env.UNIT_TEST,
ssh: getInput('SSH'),

View File

@ -1,3 +1,4 @@
import {isDebug} from '@actions/core'
import {exec} from '@actions/exec'
let output: string
@ -13,7 +14,7 @@ export async function execute(cmd: string, cwd: string): Promise<any> {
await exec(cmd, [], {
// Silences the input unless the INPUT_DEBUG flag is set.
silent: process.env.DEBUG_DEPLOY_ACTION ? false : true,
silent: isDebug() ? false : true,
cwd,
listeners: {
stdout

View File

@ -1,3 +1,4 @@
import {info} from '@actions/core'
import {ActionInterface} from './constants'
import {execute} from './execute'
import {
@ -11,20 +12,25 @@ export async function init(action: ActionInterface): Promise<void | Error> {
try {
hasRequiredParameters(action)
console.log(`Deploying using ${action.tokenType} 🔑`)
console.log('Configuring Git…')
info(`Deploying using ${action.tokenType}... 🔑`)
info('Configuring git...')
await execute(`git init`, action.workspace)
await execute(`git config user.name "${action.name}"`, action.workspace)
await execute(`git config user.email "${action.email}"`, action.workspace)
await execute(`git remote rm origin`, action.workspace)
await execute(
`git remote add origin ${action.repositoryPath}`,
action.workspace
)
try {
await execute(`git remote rm origin`, action.workspace)
} finally {
await execute(
`git remote add origin ${action.repositoryPath}`,
action.workspace
)
}
await execute(`git fetch`, action.workspace)
console.log('Git configured… 🔧')
info('Git configured... 🔧')
} catch (error) {
throw new Error(
`There was an error initializing the repository: ${suppressSensitiveInformation(
@ -63,13 +69,13 @@ export async function generateBranch(action: ActionInterface): Promise<void> {
try {
hasRequiredParameters(action)
console.log(`Creating the ${action.branch} branch`)
info(`Creating the ${action.branch} branch...`)
await switchToBaseBranch(action)
await execute(`git checkout --orphan ${action.branch}`, action.workspace)
await execute(`git reset --hard`, action.workspace)
await execute(
`git commit --allow-empty -m "Initial ${action.branch} commit"`,
`git commit --allow-empty -m "Initial ${action.branch} commit."`,
action.workspace
)
await execute(
@ -78,7 +84,7 @@ export async function generateBranch(action: ActionInterface): Promise<void> {
)
await execute(`git fetch`, action.workspace)
console.log(`Created the ${action.branch} branch 🔧`)
info(`Created the ${action.branch} branch... 🔧`)
} catch (error) {
throw new Error(
`There was an error creating the deployment branch: ${suppressSensitiveInformation(
@ -93,7 +99,7 @@ export async function generateBranch(action: ActionInterface): Promise<void> {
export async function deploy(action: ActionInterface): Promise<void> {
const temporaryDeploymentDirectory = 'gh-action-temp-deployment-folder'
const temporaryDeploymentBranch = 'gh-action-temp-deployment-branch'
console.log('Starting to commit changes…')
info('Starting to commit changes...')
try {
hasRequiredParameters(action)
@ -132,7 +138,7 @@ export async function deploy(action: ActionInterface): Promise<void> {
excludes += `--exclude ${item} `
}
} catch {
console.log(
info(
'There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌'
)
}
@ -165,7 +171,7 @@ export async function deploy(action: ActionInterface): Promise<void> {
)
if (!hasFilesToCommit && !action.isTest) {
console.log('There is nothing to commit. Exiting early… 📭')
info('There is nothing to commit. Exiting early... 📭')
return
}
@ -184,7 +190,7 @@ export async function deploy(action: ActionInterface): Promise<void> {
? action.commitMessage
: `Deploying to ${action.branch} from ${action.baseBranch}`
} ${
process.env.GITHUB_SHA ? `@ ${process.env.GITHUB_SHA}` : ''
process.env.GITHUB_SHA ? `- ${process.env.GITHUB_SHA}` : ''
} 🚀" --quiet`,
`${action.workspace}/${temporaryDeploymentDirectory}`
)
@ -193,10 +199,10 @@ export async function deploy(action: ActionInterface): Promise<void> {
`${action.workspace}/${temporaryDeploymentDirectory}`
)
console.log(`Changes committed to the ${action.branch} branch 📦`)
info(`Changes committed to the ${action.branch} branch... 📦`)
// Cleans up temporary files/folders and restores the git state.
console.log('Running post deployment cleanup jobs…')
info('Running post deployment cleanup jobs...')
await execute(
`git checkout --progress --force ${action.defaultBranch}`,
action.workspace

View File

@ -1,4 +1,4 @@
import {exportVariable, setFailed} from '@actions/core'
import {info, setFailed} from '@actions/core'
import {action, ActionInterface} from './constants'
import {deploy, generateBranch, init} from './git'
import {generateRepositoryPath, generateTokenType} from './util'
@ -13,7 +13,7 @@ export default async function run(
let errorState = false
try {
console.log('Checking configuration and starting deployment… 🚦')
info('Checking configuration and starting deployment… 🚦')
const settings = {
...action,
@ -24,18 +24,13 @@ export default async function run(
settings.repositoryPath = generateRepositoryPath(settings)
settings.tokenType = generateTokenType(settings)
if (settings.debug) {
// Sets the debug flag if passed as an arguement.
exportVariable('DEBUG_DEPLOY_ACTION', 'debug')
}
await init(settings)
await deploy(settings)
} catch (error) {
errorState = true
setFailed(error.message)
} finally {
console.log(
info(
`${
errorState
? 'Deployment Failed ❌'

View File

@ -1,4 +1,4 @@
import {getInput} from '@actions/core'
import {isDebug} from '@actions/core'
import {ActionInterface} from './constants'
/* Utility function that checks to see if a value is undefined or not. */
@ -58,7 +58,7 @@ export const suppressSensitiveInformation = (
): string => {
let value = str
if (getInput('DEBUG')) {
if (isDebug()) {
// Data is unmasked in debug mode.
return value
}

787
yarn.lock

File diff suppressed because it is too large Load Diff