From 91d4e8f962f37d107f3ee3803bee1b9501305449 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 31 Jan 2022 08:08:23 -0500 Subject: [PATCH] Part 1: Logging Improvements (#1022) * 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 --- .devcontainer/devcontainer.json | 26 +++++++++----------- .github/workflows/integration.yml | 2 +- .github/workflows/sponsors.yml | 3 +-- .github/workflows/version.yml | 2 +- __tests__/env.js | 1 + __tests__/main.test.ts | 4 ++- __tests__/util.test.ts | 4 +-- src/lib.ts | 41 ++++++++++++++++++++++--------- src/util.ts | 7 +++--- 9 files changed, 55 insertions(+), 35 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7f7128d1..3a3b6710 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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" } diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index f00518e1..7cb331f1 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -218,7 +218,7 @@ jobs: integration-container, integration-ssh, integration-ssh-third-party-client, - integration-env, + integration-env ] runs-on: ubuntu-latest steps: diff --git a/.github/workflows/sponsors.yml b/.github/workflows/sponsors.yml index ee05eea6..bc560d42 100644 --- a/.github/workflows/sponsors.yml +++ b/.github/workflows/sponsors.yml @@ -18,7 +18,7 @@ jobs: file: 'README.md' template: '{{{ login }}}  ' maximum: 9999 - + - name: Generate Sponsors 💖 uses: JamesIves/github-sponsors-readme-action@v1.0.8 with: @@ -28,7 +28,6 @@ jobs: template: '{{{ login }}}  ' marker: 'premium' - - name: Deploy to GitHub Pages uses: JamesIves/github-pages-deploy-action@v4.2.2 with: diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml index 08e7b124..47c18a7d 100644 --- a/.github/workflows/version.yml +++ b/.github/workflows/version.yml @@ -3,7 +3,7 @@ name: Update Major Version Tag on: push: tags: - - "v*" + - 'v*' jobs: update-majorver: diff --git a/__tests__/env.js b/__tests__/env.js index 5c29df78..a63280e2 100644 --- a/__tests__/env.js +++ b/__tests__/env.js @@ -1 +1,2 @@ process.env.ACTIONS_STEP_DEBUG = 'false' +process.env.RUNNER_OS = 'Windows' diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 7cf28f8f..160cc86d 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -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' @@ -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', () => { diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index fa5e1c6a..08399a78 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -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.' ) } }) @@ -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.' ) } }) diff --git a/src/lib.ts b/src/lib.ts index 6af2976d..73e61677 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -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' @@ -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 @@ -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) diff --git a/src/util.ts b/src/util.ts index e3bab3fb..59f7d982 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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 { @@ -47,6 +47,7 @@ const hasRequiredParameters = ( const nonNullParams = params.filter( param => !isNullOrUndefined(action[param]) ) + return Boolean(nonNullParams.length) } @@ -54,7 +55,7 @@ const hasRequiredParameters = ( 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.' ) } @@ -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. ❗` ) }