Skip to content

Commit c5d47e3

Browse files
committed
move the logging and setFailed logic into the deploymentConfirmation function
1 parent 5571e1d commit c5d47e3

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

__tests__/functions/deployment-confirmation.test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ beforeEach(() => {
1313
jest.spyOn(core, 'info').mockImplementation(() => {})
1414
jest.spyOn(core, 'debug').mockImplementation(() => {})
1515
jest.spyOn(core, 'warning').mockImplementation(() => {})
16+
jest.spyOn(core, 'setFailed').mockImplementation(() => {})
1617

1718
// Mock setTimeout to execute immediately
1819
jest.spyOn(global, 'setTimeout').mockImplementation(fn => fn())
@@ -118,6 +119,9 @@ test('successfully prompts for deployment confirmation and gets confirmed by the
118119
expect(core.info).toHaveBeenCalledWith(
119120
`🕒 waiting ${COLORS.highlight}60${COLORS.reset} seconds for deployment confirmation`
120121
)
122+
expect(core.info).toHaveBeenCalledWith(
123+
`✅ deployment confirmed by ${COLORS.highlight}monalisa${COLORS.reset} - sha: ${COLORS.highlight}abc123${COLORS.reset}`
124+
)
121125

122126
expect(octokit.rest.reactions.listForIssueComment).toHaveBeenCalledWith({
123127
comment_id: 124,
@@ -159,6 +163,10 @@ test('user rejects the deployment with thumbs down', async () => {
159163
repo: 'test',
160164
headers: API_HEADERS
161165
})
166+
167+
expect(core.setFailed).toHaveBeenCalledWith(
168+
`❌ deployment rejected by ${COLORS.highlight}monalisa${COLORS.reset}`
169+
)
162170
})
163171

164172
test('deployment confirmation times out after no response', async () => {
@@ -185,7 +193,7 @@ test('deployment confirmation times out after no response', async () => {
185193
headers: API_HEADERS
186194
})
187195

188-
expect(core.info).toHaveBeenCalledWith(
196+
expect(core.setFailed).toHaveBeenCalledWith(
189197
`⏱️ deployment confirmation timed out after ${COLORS.highlight}60${COLORS.reset} seconds`
190198
)
191199
})
@@ -229,6 +237,9 @@ test('ignores reactions from other users', async () => {
229237
expect(core.debug).toHaveBeenCalledWith(
230238
'ignoring reaction from other-user, expected monalisa'
231239
)
240+
expect(core.info).toHaveBeenCalledWith(
241+
`✅ deployment confirmed by ${COLORS.highlight}monalisa${COLORS.reset} - sha: ${COLORS.highlight}abc123${COLORS.reset}`
242+
)
232243
})
233244

234245
test('handles API errors gracefully', async () => {
@@ -254,4 +265,7 @@ test('handles API errors gracefully', async () => {
254265
'temporary failure when checking for reactions on the deployment confirmation comment: API error'
255266
)
256267
expect(octokit.rest.reactions.listForIssueComment).toHaveBeenCalledTimes(2)
268+
expect(core.info).toHaveBeenCalledWith(
269+
`✅ deployment confirmed by ${COLORS.highlight}monalisa${COLORS.reset} - sha: ${COLORS.highlight}abc123${COLORS.reset}`
270+
)
257271
})

dist/index.js

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/deployment-confirmation.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ export async function deploymentConfirmation(context, octokit, data) {
106106
headers: API_HEADERS
107107
})
108108

109+
core.info(
110+
`✅ deployment confirmed by ${COLORS.highlight}${context.actor}${COLORS.reset} - sha: ${COLORS.highlight}${data.sha}${COLORS.reset}`
111+
)
112+
109113
return true
110114
} else if (reaction.content === thumbsDown) {
111115
// Update confirmation comment with cancellation message
@@ -116,6 +120,10 @@ export async function deploymentConfirmation(context, octokit, data) {
116120
headers: API_HEADERS
117121
})
118122

123+
core.setFailed(
124+
`❌ deployment rejected by ${COLORS.highlight}${context.actor}${COLORS.reset}`
125+
)
126+
119127
return false
120128
}
121129
} else {
@@ -143,7 +151,7 @@ export async function deploymentConfirmation(context, octokit, data) {
143151
headers: API_HEADERS
144152
})
145153

146-
core.info(
154+
core.setFailed(
147155
`⏱️ deployment confirmation timed out after ${COLORS.highlight}${data.deployment_confirmation_timeout}${COLORS.reset} seconds`
148156
)
149157
return false

src/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ export async function run() {
608608
const log_url = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${github_run_id}`
609609

610610
// if the deployment_confirmation is set to 'true', then we will prompt the user to confirm the deployment
611-
if (inputs.deployment_confirmation) {
611+
if (inputs.deployment_confirmation === true) {
612612
const deploymentConfirmed = await deploymentConfirmation(
613613
context,
614614
octokit,
@@ -631,13 +631,13 @@ export async function run() {
631631
}
632632
)
633633
if (deploymentConfirmed === true) {
634-
core.info(
635-
`✅ deployment confirmed by ${COLORS.highlight}${context.actor}${COLORS.reset} - sha: ${COLORS.highlight}${precheckResults.sha}${COLORS.reset}`
634+
core.debug(
635+
`deploymentConfirmation() was successful - continuing with the deployment`
636636
)
637637
} else {
638638
// Set the bypass state to true so that the post run logic will not run
639639
core.saveState('bypass', 'true')
640-
core.setFailed(`❌ deployment not confirmed - exiting`)
640+
core.debug(`❌ deployment not confirmed - exiting`)
641641
return 'failure'
642642
}
643643
}

0 commit comments

Comments
 (0)