Skip to content

Commit 5e59914

Browse files
authored
Merge pull request #183 from github/post-deploy-fixes
Post Deploy Fixes
2 parents d92479f + a4dbbee commit 5e59914

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

__tests__/functions/post-deploy.test.js

+47
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as postDeployMessage from '../../src/functions/post-deploy-message'
77
import * as core from '@actions/core'
88

99
const infoMock = jest.spyOn(core, 'info')
10+
const warningMock = jest.spyOn(core, 'warning')
1011

1112
var octokit
1213
var context
@@ -15,6 +16,7 @@ beforeEach(() => {
1516
jest.clearAllMocks()
1617
jest.spyOn(core, 'info').mockImplementation(() => {})
1718
jest.spyOn(core, 'debug').mockImplementation(() => {})
19+
jest.spyOn(core, 'warning').mockImplementation(() => {})
1820
jest.spyOn(actionStatus, 'actionStatus').mockImplementation(() => {
1921
return undefined
2022
})
@@ -310,6 +312,51 @@ test('successfully completes a noop branch deployment and removes a non-sticky l
310312
)
311313
})
312314

315+
test('successfully completes a noop branch deployment but does not get any lock data', async () => {
316+
const lockSpy = jest.spyOn(lock, 'lock').mockImplementation(() => {
317+
return {lockData: null}
318+
})
319+
const actionStatusSpy = jest.spyOn(actionStatus, 'actionStatus')
320+
expect(
321+
await postDeploy(
322+
context,
323+
octokit,
324+
123,
325+
12345,
326+
'success',
327+
'test-ref',
328+
true,
329+
456,
330+
'production'
331+
)
332+
).toBe('success - noop')
333+
334+
expect(lockSpy).toHaveBeenCalled()
335+
expect(actionStatusSpy).toHaveBeenCalled()
336+
expect(actionStatusSpy).toHaveBeenCalledWith(
337+
{
338+
actor: 'monalisa',
339+
eventName: 'issue_comment',
340+
payload: {comment: {id: '1'}},
341+
repo: {owner: 'corp', repo: 'test'},
342+
workflow: 'test-workflow'
343+
},
344+
{
345+
rest: {
346+
repos: {
347+
createDeploymentStatus: octokit.rest.repos.createDeploymentStatus
348+
}
349+
}
350+
},
351+
12345,
352+
'Updated 1 server',
353+
true
354+
)
355+
expect(warningMock).toHaveBeenCalledWith(
356+
'a request to obtain the lock data returned null or undefined - the lock may have been removed by another process while this Action was running'
357+
)
358+
})
359+
313360
test('successfully completes a production branch deployment with no custom message', async () => {
314361
const actionStatusSpy = jest.spyOn(actionStatus, 'actionStatus')
315362
expect(

dist/index.js

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/post-deploy.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ export async function postDeploy(
9797
core.debug(JSON.stringify(lockData))
9898

9999
// If the lock is sticky, we will NOT remove it
100-
if (lockData.sticky === true) {
100+
if (lockData?.sticky === true) {
101101
core.info('sticky lock detected, will not remove lock')
102+
} else if (lockData === null || lockData === undefined) {
103+
core.warning(
104+
'a request to obtain the lock data returned null or undefined - the lock may have been removed by another process while this Action was running'
105+
)
102106
} else {
103107
core.info('non-sticky lock detected, will remove lock')
104108
core.debug(`lockData.sticky: ${lockData.sticky}`)

0 commit comments

Comments
 (0)