Skip to content
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

Post Deploy Fixes #183

Merged
merged 3 commits into from
Aug 14, 2023
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
47 changes: 47 additions & 0 deletions __tests__/functions/post-deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as postDeployMessage from '../../src/functions/post-deploy-message'
import * as core from '@actions/core'

const infoMock = jest.spyOn(core, 'info')
const warningMock = jest.spyOn(core, 'warning')

var octokit
var context
Expand All @@ -15,6 +16,7 @@ beforeEach(() => {
jest.clearAllMocks()
jest.spyOn(core, 'info').mockImplementation(() => {})
jest.spyOn(core, 'debug').mockImplementation(() => {})
jest.spyOn(core, 'warning').mockImplementation(() => {})
jest.spyOn(actionStatus, 'actionStatus').mockImplementation(() => {
return undefined
})
Expand Down Expand Up @@ -310,6 +312,51 @@ test('successfully completes a noop branch deployment and removes a non-sticky l
)
})

test('successfully completes a noop branch deployment but does not get any lock data', async () => {
const lockSpy = jest.spyOn(lock, 'lock').mockImplementation(() => {
return {lockData: null}
})
const actionStatusSpy = jest.spyOn(actionStatus, 'actionStatus')
expect(
await postDeploy(
context,
octokit,
123,
12345,
'success',
'test-ref',
true,
456,
'production'
)
).toBe('success - noop')

expect(lockSpy).toHaveBeenCalled()
expect(actionStatusSpy).toHaveBeenCalled()
expect(actionStatusSpy).toHaveBeenCalledWith(
{
actor: 'monalisa',
eventName: 'issue_comment',
payload: {comment: {id: '1'}},
repo: {owner: 'corp', repo: 'test'},
workflow: 'test-workflow'
},
{
rest: {
repos: {
createDeploymentStatus: octokit.rest.repos.createDeploymentStatus
}
}
},
12345,
'Updated 1 server',
true
)
expect(warningMock).toHaveBeenCalledWith(
'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'
)
})

test('successfully completes a production branch deployment with no custom message', async () => {
const actionStatusSpy = jest.spyOn(actionStatus, 'actionStatus')
expect(
Expand Down
6 changes: 5 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/functions/post-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ export async function postDeploy(
core.debug(JSON.stringify(lockData))

// If the lock is sticky, we will NOT remove it
if (lockData.sticky === true) {
if (lockData?.sticky === true) {
core.info('sticky lock detected, will not remove lock')
} else if (lockData === null || lockData === undefined) {
core.warning(
'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'
)
} else {
core.info('non-sticky lock detected, will remove lock')
core.debug(`lockData.sticky: ${lockData.sticky}`)
Expand Down
Loading