Skip to content

Commit

Permalink
Part 1: Logging Improvements (#1022)
Browse files Browse the repository at this point in the history
* Part 1 of Logging Improvements

* Update util.test.ts

* Update util.test.ts

* Update util.test.ts

* Update util.test.ts

* Adjustments to tests

* Update util.test.ts

* Update util.ts
  • Loading branch information
JamesIves committed Jan 31, 2022
1 parent cdd72ba commit 91d4e8f
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 35 deletions.
26 changes: 12 additions & 14 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/typescript-node
{
"name": "Node.js & TypeScript",
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "14"
}
},
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"dbaeumer.vscode-eslint"
],
"remoteUser": "node"
"name": "Node.js & TypeScript",
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "14"
}
},
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": ["dbaeumer.vscode-eslint"],
"remoteUser": "node"
}
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ jobs:
integration-container,
integration-ssh,
integration-ssh-third-party-client,
integration-env,
integration-env
]
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/sponsors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
file: 'README.md'
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="50px" alt="{{{ login }}}" /></a>&nbsp;&nbsp;'
maximum: 9999

- name: Generate Sponsors 💖
uses: JamesIves/github-sponsors-readme-action@v1.0.8
with:
Expand All @@ -28,7 +28,6 @@ jobs:
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="80px" alt="{{{ login }}}" /></a>&nbsp;&nbsp;'
marker: 'premium'


- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4.2.2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Update Major Version Tag
on:
push:
tags:
- "v*"
- 'v*'

jobs:
update-majorver:
Expand Down
1 change: 1 addition & 0 deletions __tests__/env.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
process.env.ACTIONS_STEP_DEBUG = 'false'
process.env.RUNNER_OS = 'Windows'
4 changes: 3 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ process.env['INPUT_FOLDER'] = 'build'
process.env['GITHUB_SHA'] = '123'
process.env['INPUT_DEBUG'] = 'debug'
process.env['GITHUB_REF_NAME'] = 'test'
process.env['RUNNER_OS'] = 'Linux'

import '../src/main'
import {action, TestFlag} from '../src/constants'
Expand All @@ -27,7 +28,8 @@ jest.mock('@actions/core', () => ({
setOutput: jest.fn(),
exportVariable: jest.fn(),
isDebug: jest.fn(),
info: jest.fn()
info: jest.fn(),
notice: jest.fn()
}))

describe('main', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('util', () => {
checkParameters(action)
} catch (e) {
expect(e instanceof Error && e.message).toMatch(
'No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true.'
'No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. For more details on how to use an ssh deploy key please refer to the documentation.'
)
}
})
Expand All @@ -244,7 +244,7 @@ describe('util', () => {
checkParameters(action)
} catch (e) {
expect(e instanceof Error && e.message).toMatch(
'No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true.'
'No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. For more details on how to use an ssh deploy key please refer to the documentation.'
)
}
})
Expand Down
41 changes: 30 additions & 11 deletions src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {exportVariable, info, setFailed, setOutput} from '@actions/core'
import {exportVariable, info, notice, setFailed, setOutput} from '@actions/core'
import {ActionInterface, NodeActionInterface, Status} from './constants'
import {deploy, init} from './git'
import {configureSSH} from './ssh'
Expand All @@ -21,8 +21,25 @@ export default async function run(

try {
info(`
GitHub Pages Deploy Action 🚀
╭━━━╮╭╮╭╮╱╭╮╱╱╭╮╱╱╭━━━╮
┃╭━╮┣╯╰┫┃╱┃┃╱╱┃┃╱╱┃╭━╮┃
┃┃╱╰╋╮╭┫╰━╯┣╮╭┫╰━╮┃╰━╯┣━━┳━━┳━━┳━━╮
┃┃╭━╋┫┃┃╭━╮┃┃┃┃╭╮┃┃╭━━┫╭╮┃╭╮┃┃━┫━━┫
┃╰┻━┃┃╰┫┃╱┃┃╰╯┃╰╯┃┃┃╱╱┃╭╮┃╰╯┃┃━╋━━┃
╰━━━┻┻━┻╯╱╰┻━━┻━━╯╰╯╱╱╰╯╰┻━╮┣━━┻━━╯
╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╭━╯┃
╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╰━━╯
╭━━━╮╱╱╱╱╱╭╮╱╱╱╱╱╱╱╱╭━━━╮╱╱╭╮
╰╮╭╮┃╱╱╱╱╱┃┃╱╱╱╱╱╱╱╱┃╭━╮┃╱╭╯╰╮
╱┃┃┃┣━━┳━━┫┃╭━━┳╮╱╭╮┃┃╱┃┣━┻╮╭╋┳━━┳━╮
╱┃┃┃┃┃━┫╭╮┃┃┃╭╮┃┃╱┃┃┃╰━╯┃╭━┫┃┣┫╭╮┃╭╮╮
╭╯╰╯┃┃━┫╰╯┃╰┫╰╯┃╰━╯┃┃╭━╮┃╰━┫╰┫┃╰╯┃┃┃┃
╰━━━┻━━┫╭━┻━┻━━┻━╮╭╯╰╯╱╰┻━━┻━┻┻━━┻╯╰╯
╱╱╱╱╱╱╱┃┃╱╱╱╱╱╱╭━╯┃
╱╱╱╱╱╱╱╰╯╱╱╱╱╱╱╰━━╯
`)

info(`
💖 Support: https://github.com/sponsors/JamesIves
📣 Maintained by James Ives: https://jamesiv.es
Expand Down Expand Up @@ -53,17 +70,19 @@ export default async function run(
status = await deploy(settings)
} catch (error) {
status = Status.FAILED

setFailed(extractErrorMessage(error))
} finally {
info(
`${
status === Status.FAILED
? 'Deployment failed! ❌'
: status === Status.SUCCESS
? 'Completed deployment successfully! ✅'
: 'There is nothing to commit. Exiting early… 📭'
}`
)
const terminationMessage = `${
status === Status.FAILED
? 'Deployment failed! ❌'
: status === Status.SUCCESS
? 'Completed deployment successfully! ✅'
: 'There is nothing to commit. Exiting early… 📭'
}`

info(terminationMessage)
notice(terminationMessage)

exportVariable('deployment_status', status)
setOutput('deployment-status', status)
Expand Down
7 changes: 4 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isDebug, info} from '@actions/core'
import {isDebug, warning} from '@actions/core'
import {existsSync} from 'fs'
import path from 'path'
import {
Expand Down Expand Up @@ -47,14 +47,15 @@ const hasRequiredParameters = <K extends keyof RequiredActionParameters>(
const nonNullParams = params.filter(
param => !isNullOrUndefined(action[param])
)

return Boolean(nonNullParams.length)
}

/* Verifies the action has the required parameters to run, otherwise throw an error. */
export const checkParameters = (action: ActionInterface): void => {
if (!hasRequiredParameters(action, ['token', 'sshKey'])) {
throw new Error(
'No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true.'
'No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. For more details on how to use an ssh deploy key please refer to the documentation.'
)
}

Expand All @@ -77,7 +78,7 @@ export const checkParameters = (action: ActionInterface): void => {
process.env.RUNNER_OS as OperatingSystems
)
) {
info(
warning(
`The operating system you're using is not supported and results may be varied. Please refer to the documentation for more details. ❗`
)
}
Expand Down

0 comments on commit 91d4e8f

Please sign in to comment.