8000 fix issue #866 - upgrading to typescript 4.4.3 by lucassabreu · Pull Request #896 · JamesIves/github-pages-deploy-action · GitHub
[go: up one dir, main page]

Skip to content

fix issue #866 - upgrading to typescript 4.4.3 #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('git', () => {
try {
await init(action)
} catch (error) {
expect(error.message).toBe(
expect(error instanceof Error && error.message).toBe(
'There was an error initializing the repository: Mocked throw ❌'
)
}
Expand Down Expand Up @@ -419,7 +419,7 @@ describe('git', () => {
try {
await deploy(action)
} catch (error) {
expect(error.message).toBe(
expect(error instanceof Error && error.message).toBe(
'The deploy step encountered an error: Mocked throw ❌'
)
}
Expand Down
2 changes: 1 addition & 1 deletion __tests__/ssh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('configureSSH', () => {
try {
await configureSSH(action)
} catch (error) {
expect(error.message).toBe(
expect(error instanceof Error && error.message).toBe(
'The ssh client configuration encountered an error: Mocked throw ❌'
)
}
Expand Down
31 changes: 25 additions & 6 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
generateFolderPath,
suppressSensitiveInformation,
checkParameters,
stripProtocolFromUrl
stripProtocolFromUrl,
extractErrorMessage
} from '../src/util'

describe('util', () => {
Expand Down Expand Up @@ -222,7 +223,7 @@ describe('util', () => {
try {
checkParameters(action)
} catch (e) {
expect(e.message).toMatch(
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.'
)
}
Expand All @@ -242,7 +243,7 @@ describe('util', () => {
try {
checkParameters(action)
} catch (e) {
expect(e.message).toMatch(
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.'
)
}
Expand All @@ -262,7 +263,7 @@ describe('util', () => {
try {
checkParameters(action)
} catch (e) {
expect(e.message).toMatch('Branch is required.')
expect(e instanceof Error && e.message).toMatch('Branch is required.')
}
})

Expand All @@ -280,7 +281,7 @@ describe('util', () => {
try {
checkParameters(action)
} catch (e) {
expect(e.message).toMatch(
expect(e instanceof Error && e.message).toMatch(
'You must provide the action with a folder to deploy.'
)
}
Expand All @@ -301,7 +302,7 @@ describe('util', () => {
action.folderPath = generateFolderPath(action)
checkParameters(action)
} catch (e) {
expect(e.message).toMatch(
expect(e instanceof Error && e.message).toMatch(
`The directory you're trying to deploy named notARealFolder doesn't exist. Please double check the path and any prerequisite build scripts and try again. ❗`
)
}
Expand All @@ -327,4 +328,22 @@ describe('util', () => {
)
})
})

describe('extractErrorMessage', () => {
it('gets the message of a Error', () => {
expect(extractErrorMessage(new Error('a error message'))).toBe(
'a error message'
)
})

it('gets the message of a string', () => {
expect(extractErrorMessage('a error message')).toBe('a error message')
})

it('gets the message of a object', () => {
expect(extractErrorMessage({special: 'a error message'})).toBe(
`{"special":"a error message"}`
)
})
})
})
2 changes: 1 addition & 1 deletion __tests__/worktree.error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('generateWorktree', () => {
true
)
} catch (error) {
expect(error.message).toBe(
expect(error instanceof Error && error.message).toBe(
'There was an error creating the worktree: Mocked throw ❌'
)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
"prettier": "2.4.1",
"rimraf": "3.0.2",
"ts-jest": "26.5.6",
"typescript": "4.3.5"
"typescript": "4.4.3"
}
}
10 changes: 7 additions & 3 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import fs from 'fs'
import {ActionInterface, Status, TestFlag} from './constants'
import {execute} from './execute'
import {generateWorktree} from './worktree'
import {isNullOrUndefined, suppressSensitiveInformation} from './util'
import {
extractErrorMessage,
isNullOrUndefined,
suppressSensitiveInformation
} from './util'

/* Initializes git in the workspace. */
export async function init(action: ActionInterface): Promise<void | Error> {
Expand Down Expand Up @@ -63,7 +67,7 @@ export async function init(action: ActionInterface): Promise<void | Error> {
} catch (error) {
throw new Error(
`There was an error initializing the repository: ${suppressSensitiveInformation(
error.message,
extractErrorMessage(error),
action
)} ❌`
)
Expand Down Expand Up @@ -208,7 +212,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
} catch (error) {
throw new Error(
`The deploy step encountered an error: ${suppressSensitiveInformation(
error.message,
extractErrorMessage(error),
action
)} ❌`
)
Expand Down
3 changes: 2 additions & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {deploy, init} from './git'
import {configureSSH} from './ssh'
import {
checkParameters,
extractErrorMessage,
generateFolderPath,
generateRepositoryPath,
generateTokenType
Expand Down Expand Up @@ -52,7 +53,7 @@ export default async function run(
status = await deploy(settings)
} catch (error) {
status = Status.FAILED
setFailed(error.message)
setFailed(extractErrorMessage(error))
} finally {
info(
`${
Expand Down
4 changes: 2 additions & 2 deletions src/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {mkdirP} from '@actions/io'
import {execFileSync, execSync} from 'child_process'
import {appendFileSync} from 'fs'
import {ActionInterface} from './constants'
import {suppressSensitiveInformation} from './util'
import {extractErrorMessage, suppressSensitiveInformation} from './util'

export async function configureSSH(action: ActionInterface): Promise<void> {
try {
Expand Down Expand Up @@ -46,7 +46,7 @@ export async function configureSSH(action: ActionInterface): Promise<void> {
} catch (error) {
throw new Error(
`The ssh client configuration encountered an error: ${suppressSensitiveInformation(
error.message,
extractErrorMessage(error),
action
)} ❌`
)
Expand Down
7 changes: 7 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export const suppressSensitiveInformation = (
return value
}

export const extractErrorMessage = (error: unknown): string =>
error instanceof Error
? error.message
: typeof error == 'string'
? error
: JSON.stringify(error)

/** Strips the protocol from a provided URL. */
export const stripProtocolFromUrl = (url: string): string =>
url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, '').split('/')[0]
4 changes: 2 additions & 2 deletions src/worktree.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {info} from '@actions/core'
import {ActionInterface} from './constants'
import {execute} from './execute'
import {suppressSensitiveInformation} from './util'
import {extractErrorMessage, suppressSensitiveInformation} from './util'

export class GitCheckout {
orphan = false
Expand Down Expand Up @@ -77,7 +77,7 @@ export async function generateWorktree(
} catch (error) {
throw new Error(
`There was an error creating the worktree: ${suppressSensitiveInformation(
error.message,
extractErrorMessage(error),
action
)} ❌`
)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4571,10 +4571,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@4.3.5:
version "4.3.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
typescript@4.4.3:
version "4.4.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324"
integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA==

union-value@^1.0.0:
version "1.0.1"
Expand Down
0