8000 Deployment Issues (#583) · lyrl/github-pages-deploy-action@a099e5d · GitHub
[go: up one dir, main page]

Skip to content

Commit a099e5d

Browse files
JamesIvesPike
andauthored
Deployment Issues (JamesIves#583)
* Update git.ts * Tests * Update git.ts * Formatting * Update src/git.ts Co-authored-by: Axel Hecht <axel@pike.org> * TestFlag * Logging * Update git.ts Co-authored-by: Axel Hecht <axel@pike.org>
1 parent 64eb711 commit a099e5d

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

__tests__/git.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ describe('git', () => {
4040
})
4141

4242
describe('init', () => {
43+
it('should execute commands', async () => {
44+
Object.assign(action, {
45+
silent: false,
46+
repositoryPath: 'JamesIves/github-pages-deploy-action',
47+
token: '123',
48+
branch: 'branch',
49+
folder: '.',
50+
pusher: {
51+
name: 'asd',
52+
email: 'as@cat'
53+
},
54+
isTest: TestFlag.HAS_CHANGED_FILES
55+
})
56+
57+
await init(action)
58+
expect(execute).toBeCalledTimes(4)
59+
})
60+
4361
it('should catch when a function throws an error', async () => {
4462
;(execute as jest.Mock).mockImplementationOnce(() => {
4563
throw new Error('Mocked throw')
@@ -66,6 +84,24 @@ describe('git', () => {
6684
)
6785
}
6886
})
87+
88+
it('should correctly continue when it cannot remove origin', async () => {
89+
Object.assign(action, {
90+
silent: false,
91+
repositoryPath: 'JamesIves/github-pages-deploy-action',
92+
token: '123',
93+
branch: 'branch',
94+
folder: '.',
95+
pusher: {
96+
name: 'asd',
97+
email: 'as@cat'
98+
},
99+
isTest: TestFlag.UNABLE_TO_REMOVE_ORIGIN
100+
})
101+
102+
await init(action)
103+
expect(execute).toBeCalledTimes(4)
104+
})
69105
})
70106

71107
describe('deploy', () => {
@@ -75,6 +111,7 @@ describe('git', () => {
75111
folder: 'assets',
76112
branch: 'branch',
77113
token: '123',
114+
repositoryName: 'JamesIves/montezuma',
78115
pusher: {
79116
name: 'asd',
80117
email: 'as@cat'

__tests__/main.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('main', () => {
4949
debug: true
5050
})
5151
await run(action)
52-
expect(execute).toBeCalledTimes(10)
52+
expect(execute).toBeCalledTimes(12)
5353
expect(rmRF).toBeCalledTimes(1)
5454
expect(exportVariable).toBeCalledTimes(1)
5555
})
@@ -68,7 +68,7 @@ describe('main', () => {
6868
isTest: TestFlag.HAS_CHANGED_FILES
6969
})
7070
await run(action)
71-
expect(execute).toBeCalledTimes(13)
71+
expect(execute).toBeCalledTimes(15)
7272
expect(rmRF).toBeCalledTimes(1)
7373
expect(exportVariable).toBeCalledTimes(1)
7474
})

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const {pusher, repository} = github.context.payload
88
export enum TestFlag {
99
NONE = 0,
1010
HAS_CHANGED_FILES = 1 << 1, // Assume changes to commit
11-
HAS_REMOTE_BRANCH = 1 << 2 // Assume remote repository has existing commits
11+
HAS_REMOTE_BRANCH = 1 << 2, // Assume remote repository has existing commits
12+
UNABLE_TO_REMOVE_ORIGIN = 1 << 3 // Assume we can't remove origin
1213
}
1314

1415
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */

src/git.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ export async function init(action: ActionInterface): Promise<void | Error> {
2323
action.silent
2424
)
2525

26+
try {
27+
await execute(`git remote rm origin`, action.workspace, action.silent)
28+
29+
if (action.isTest === TestFlag.UNABLE_TO_REMOVE_ORIGIN) {
30+
throw new Error()
31+
}
32+
} catch {
33+
info('Attempted to remove origin but failed, continuing…')
34+
}
35+
36+
await execute(
37+
`git remote add origin ${action.repositoryPath}`,
38+
action.workspace,
39+
action.silent
40+
)
41+
2642
info('Git configured… 🔧')
2743
} catch (error) {
2844
throw new Error(
@@ -48,7 +64,9 @@ export async function deploy(action: ActionInterface): Promise<Status> {
4864
const commitMessage = !isNullOrUndefined(action.commitMessage)
4965
? (action.commitMessage as string)
5066
: `Deploying to ${action.branch}${
51-
process.env.GITHUB_SHA ? ` from @ ${process.env.GITHUB_SHA}` : ''
67+
process.env.GITHUB_SHA
68+
? ` from @ ${process.env.GITHUB_REPOSITORY}@${process.env.GITHUB_SHA}`
69+
: ''
5270
} 🚀`
5371

5472
// Checks to see if the remote exists prior to deploying.
@@ -113,12 +131,13 @@ export async function deploy(action: ActionInterface): Promise<Status> {
113131
branchExists && action.singleCommit
114132
? `git diff origin/${action.branch}`
115133
: `git status --porcelain`
134+
info(`Checking if there are files to commit…`)
116135
const hasFilesToCommit =
117136
action.isTest & TestFlag.HAS_CHANGED_FILES ||
118137
(await execute(
119138
checkGitStatus,
120139
`${action.workspace}/${temporaryDeploymentDirectory}`,
121-
action.silent
140+
true // This output is always silenced due to the large output it creates.
122141
))
123142

124143
if (!hasFilesToCommit) {

0 commit comments

Comments
 (0)
0