8000 fix issue #866 - upgrading to typescript 4.4.3 (#896) · Wulf/github-pages-deploy-action@460c7b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 460c7b8

Browse files
fix issue JamesIves#866 - upgrading to typescript 4.4.3 (JamesIves#896)
* Bump typescript from 4.3.5 to 4.4.3 Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.3.5 to 4.4.3. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](microsoft/TypeScript@v4.3.5...v4.4.3) --- updated-dependencies: - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * (fix): extract error message * (fix): error is unknown on __tests__ * (fix): add cover Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 21e2299 commit 460c7b8

File tree

11 files changed

+54
-23
lines changed

11 files changed

+54
-23
lines changed

__tests__/git.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('git', () => {
8080
try {
8181
await init(action)
8282
} catch (error) {
83-
expect(error.message).toBe(
83+
expect(error instanceof Error && error.message).toBe(
8484
'There was an error initializing the repository: Mocked throw ❌'
8585
)
8686
}
@@ -419,7 +419,7 @@ describe('git', () => {
419419
try {
420420
await deploy(action)
421421
} catch (error) {
422-
expect(error.message).toBe(
422+
expect(error instanceof Error && error.message).toBe(
423423
'The deploy step encountered an error: Mocked throw ❌'
424424
)
425425
}

__tests__/ssh.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ describe('configureSSH', () => {
133133
try {
134134
await configureSSH(action)
135135
} catch (error) {
136-
expect(error.message).toBe(
136+
expect(error instanceof Error && error.message).toBe(
137137
'The ssh client configuration encountered an error: Mocked throw ❌'
138138
)
139139
}

__tests__/util.test.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
generateFolderPath,
77
suppressSensitiveInformation,
88
checkParameters,
9-
stripProtocolFromUrl
9+
stripProtocolFromUrl,
10+
extractErrorMessage
1011
} from '../src/util'
1112

1213
describe('util', () => {
@@ -222,7 +223,7 @@ describe('util', () => {
222223
try {
223224
checkParameters(action)
224225
} catch (e) {
225-
expect(e.message).toMatch(
226+
expect(e instanceof Error && e.message).toMatch(
226227
'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.'
227228
)
228229
}
@@ -242,7 +243,7 @@ describe('util', () => {
242243
try {
243244
checkParameters(action)
244245
} catch (e) {
245-
expect(e.message).toMatch(
246+
expect(e instanceof Error && e.message).toMatch(
246247
'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.'
247248
)
248249
}
@@ -262,7 +263,7 @@ describe('util', () => {
262263
try {
263264
checkParameters(action)
264265
} catch (e) {
265-
expect(e.message).toMatch('Branch is required.')
266+
expect(e instanceof Error && e.message).toMatch('Branch is required.')
266267
}
267268
})
268269

@@ -280,7 +281,7 @@ describe('util', () => {
280281
try {
281282
checkParameters(action)
282283
} catch (e) {
283-
expect(e.message).toMatch(
284+
expect(e instanceof Error && e.message).toMatch(
284285
'You must provide the action with a folder to deploy.'
285286
)
286287
}
@@ -301,7 +302,7 @@ describe('util', () => {
301302
action.folderPath = generateFolderPath(action)
302303
checkParameters(action)
303304
} catch (e) {
304-
expect(e.message).toMatch(
305+
expect(e instanceof Error && e.message).toMatch(
305306
`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. ❗`
306307
)
307308
}
@@ -327,4 +328,22 @@ describe('util', () => {
327328
)
328329
})
329330
})
331+
332+
describe('extractErrorMessage', () => {
333+
it('gets the message of a Error', () => {
334+
expect(extractErrorMessage(new Error('a error message'))).toBe(
335+
'a error message'
336+
)
337+
})
338+
339+
it('gets the message of a string', () => {
340+
expect(extractErrorMessage('a error message')).toBe('a error message')
341+
})
342+
343+
it('gets the message of a object', () => {
344+
expect(extractErrorMessage({special: 'a error message'})).toBe(
345+
`{"special":"a error message"}`
346+
)
347+
})
348+
})
330349
})

__tests__/worktree.error.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('generateWorktree', () => {
2828
true
2929
)
3030
} catch (error) {
31-
expect(error.message).toBe(
31+
expect(error instanceof Error && error.message).toBe(
3232
'There was an error creating the worktree: Mocked throw ❌'
3333
)
3434
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@
5252
"prettier": "2.4.1",
5353
"rimraf": "3.0.2",
5454
"ts-jest": "26.5.6",
55-
"typescript": "4.3.5"
55+
"typescript": "4.4.3"
5656
}
5757
}

src/git.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import fs from 'fs'
44
import {ActionInterface, Status, TestFlag} from './constants'
55
import {execute} from './execute'
66
import {generateWorktree} from './worktree'
7-
import {isNullOrUndefined, suppressSensitiveInformation} from './util'
7+
import {
8+
extractErrorMessage,
9+
isNullOrUndefined,
10+
suppressSensitiveInformation
11+
} from './util'
812

913
/* Initializes git in the workspace. */
1014
export async function init(action: ActionInterface): Promise<void | Error> {
@@ -63,7 +67,7 @@ export async function init(action: ActionInterface): Promise<void | Error> {
6367
} catch (error) {
6468
throw new Error(
6569
`There was an error initializing the repository: ${suppressSensitiveInformation(
66-
error.message,
70+
extractErrorMessage(error),
6771
action
6872
)} ❌`
6973
)
@@ -208,7 +212,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
208212
} catch (error) {
209213
throw new Error(
210214
`The deploy step encountered an error: ${suppressSensitiveInformation(
211-
error.message,
215+
extractErrorMessage(error),
212216
action
213217
)} ❌`
214218
)

src/lib.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {deploy, init} from './git'
44
import {configureSSH} from './ssh'
55
import {
66
checkParameters,
7+
extractErrorMessage,
78
generateFolderPath,
89
generateRepositoryPath,
910
generateTokenType
@@ -52,7 +53,7 @@ export default async function run(
5253
status = await deploy(settings)
5354
} catch (error) {
5455
status = Status.FAILED
55-
setFailed(error.message)
56+
setFailed(extractErrorMessage(error))
5657
} finally {
5758
info(
5859
`${

src/ssh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {mkdirP} from '@actions/io'
33
import {execFileSync, execSync} from 'child_process'
44
import {appendFileSync} from 'fs'
55
import {ActionInterface} from './constants'
6-
import {suppressSensitiveInformation} from './util'
6+
import {extractErrorMessage, suppressSensitiveInformation} from './util'
77

88
export async function configureSSH(action: ActionInterface): Promise<void> {
99
try {
@@ -46,7 +46,7 @@ export async function configureSSH(action: ActionInterface): Promise<void> {
4646
} catch (error) {
4747
throw new Error(
4848
`The ssh client configuration encountered an error: ${suppressSensitiveInformation(
49-
error.message,
49+
extractErrorMessage(error),
5050
action
5151
)} ❌`
5252
)

src/util.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ export const suppressSensitiveInformation = (
9090
return value
9191
}
9292

93+
export const extractErrorMessage = (error: unknown): string =>
94+
error instanceof Error
95+
? error.message
96+
: typeof error == 'string'
97+
? error
98+
: JSON.stringify(error)
99+
93100
/** Strips the protocol from a provided URL. */
94101
export const stripProtocolFromUrl = (url: string): string =>
95102
url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, '').split('/')[0]

src/worktree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {info} from '@actions/core'
22
import {ActionInterface} from './constants'
33
import {execute} from './execute'
4-
import {suppressSensitiveInformation} from './util'
4+
import {extractErrorMessage, suppressSensitiveInformation} from './util'
55

66
export class GitCheckout {
77
orphan = false
@@ -77,7 +77,7 @@ export async function generateWorktree(
7777
} catch (error) {
7878
throw new Error(
7979
`There was an error creating the worktree: ${suppressSensitiveInformation(
80-
error.message,
80+
extractErrorMessage(error),
8181
action
8282
)} ❌`
8383
)

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4538,10 +4538,10 @@ typedarray-to-buffer@^3.1.5:
45384538
dependencies:
45394539
is-typedarray "^1.0.0"
45404540

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

45464546
union-value@^1.0.0:
45474547
version "1.0.1"

0 commit comments

Comments
 (0)
0