@@ -17,6 +17,7 @@ import * as nakedCommandCheck from '../src/functions/naked-command-check'
1717import * as validDeploymentOrder from '../src/functions/valid-deployment-order'
1818import * as commitSafetyChecks from '../src/functions/commit-safety-checks'
1919import * as timestamp from '../src/functions/timestamp'
20+ import * as deploymentConfirmation from '../src/functions/deployment-confirmation'
2021import { COLORS } from '../src/functions/colors'
2122
2223const setOutputMock = jest . spyOn ( core , 'setOutput' )
@@ -91,6 +92,8 @@ beforeEach(() => {
9192 process . env . INPUT_IGNORED_CHECKS = ''
9293 process . env . INPUT_USE_SECURITY_WARNINGS = 'true'
9394 process . env . INPUT_ALLOW_NON_DEFAULT_TARGET_BRANCH_DEPLOYMENTS = 'false'
95+ process . env . INPUT_DEPLOYMENT_CONFIRMATION = 'false'
96+ process . env . INPUT_DEPLOYMENT_CONFIRMATION_TIMEOUT = '60'
9497
9598 github . context . payload = {
9699 issue : {
@@ -148,6 +151,11 @@ beforeEach(() => {
148151 jest . spyOn ( isDeprecated , 'isDeprecated' ) . mockImplementation ( ( ) => {
149152 return false
150153 } )
154+ jest
155+ . spyOn ( deploymentConfirmation , 'deploymentConfirmation' )
156+ . mockImplementation ( ( ) => {
157+ return true
158+ } )
151159 jest . spyOn ( lock , 'lock' ) . mockImplementation ( ( ) => {
152160 return true
153161 } )
@@ -220,6 +228,81 @@ test('successfully runs the action', async () => {
220228 )
221229} )
222230
231+ test ( 'successfully runs the action with deployment confirmation' , async ( ) => {
232+ process . env . INPUT_DEPLOYMENT_CONFIRMATION = 'true'
233+
234+ jest
235+ . spyOn ( deploymentConfirmation , 'deploymentConfirmation' )
236+ . mockImplementation ( ( ) => {
237+ return true
238+ } )
239+
240+ expect ( await run ( ) ) . toBe ( 'success' )
241+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'deployment_id' , 123 )
242+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'comment_body' , '.deploy' )
243+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'triggered' , 'true' )
244+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'comment_id' , 123 )
245+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'ref' , 'test-ref' )
246+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'noop' , false )
247+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'continue' , 'true' )
248+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'isPost' , 'true' )
249+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'actionsToken' , 'faketoken' )
250+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'environment' , 'production' )
251+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'comment_id' , 123 )
252+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'ref' , 'test-ref' )
253+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'noop' , false )
254+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'type' , 'deploy' )
255+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'deployment_id' , 123 )
256+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'sha' , 'abc123' )
257+ expect ( debugMock ) . toHaveBeenCalledWith ( 'production_environment: true' )
258+ expect ( debugMock ) . toHaveBeenCalledWith (
259+ 'deploymentConfirmation() was successful - continuing with the deployment'
260+ )
261+ expect ( saveStateMock ) . not . toHaveBeenCalledWith ( 'environment_url' , String )
262+ expect ( setOutputMock ) . not . toHaveBeenCalledWith ( 'environment_url' , String )
263+ expect ( infoMock ) . toHaveBeenCalledWith (
264+ `🧑🚀 commit sha to deploy: ${ COLORS . highlight } ${ mock_sha } ${ COLORS . reset } `
265+ )
266+ expect ( infoMock ) . toHaveBeenCalledWith (
267+ `🚀 ${ COLORS . success } deployment started!${ COLORS . reset } `
268+ )
269+ } )
270+
271+ test ( 'rejects the deployment when deployment confirmation is set, but does not succeed' , async ( ) => {
272+ process . env . INPUT_DEPLOYMENT_CONFIRMATION = 'true'
273+
274+ jest
275+ . spyOn ( deploymentConfirmation , 'deploymentConfirmation' )
276+ . mockImplementation ( ( ) => {
277+ return false
278+ } )
279+
280+ expect ( await run ( ) ) . toBe ( 'failure' )
281+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'comment_body' , '.deploy' )
282+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'triggered' , 'true' )
283+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'comment_id' , 123 )
284+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'ref' , 'test-ref' )
285+ expect ( setOutputMock ) . not . toHaveBeenCalledWith ( 'continue' , 'true' )
286+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'isPost' , 'true' )
287+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'actionsToken' , 'faketoken' )
288+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'environment' , 'production' )
289+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'comment_id' , 123 )
290+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'ref' , 'test-ref' )
291+ expect ( saveStateMock ) . not . toHaveBeenCalledWith ( 'noop' , false )
292+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'type' , 'deploy' )
293+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'sha' , 'abc123' )
294+ expect ( debugMock ) . not . toHaveBeenCalledWith ( 'production_environment: true' )
295+ expect ( debugMock ) . toHaveBeenCalledWith (
296+ '❌ deployment not confirmed - exiting'
297+ )
298+ expect ( saveStateMock ) . not . toHaveBeenCalledWith ( 'environment_url' , String )
299+ expect ( setOutputMock ) . not . toHaveBeenCalledWith ( 'environment_url' , String )
300+ expect ( saveStateMock ) . toHaveBeenCalledWith ( 'bypass' , 'true' )
301+ expect ( infoMock ) . not . toHaveBeenCalledWith (
302+ `🧑🚀 commit sha to deploy: ${ COLORS . highlight } ${ mock_sha } ${ COLORS . reset } `
303+ )
304+ } )
305+
223306test ( 'successfully runs the action on a deployment to development and with branch updates disabled' , async ( ) => {
224307 process . env . INPUT_UPDATE_BRANCH = 'disabled'
225308 github . context . payload . comment . body = '.deploy to development'
0 commit comments