Skip to content

Commit 13ae6c8

Browse files
authored
Merge pull request #187 from github/lock-bug
Lock bug
2 parents 5e59914 + 735fe9f commit 13ae6c8

File tree

12 files changed

+84
-44
lines changed

12 files changed

+84
-44
lines changed

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ body:
4040
id: logs
4141
attributes:
4242
label: Relevant Actions Log Output
43-
description: Please copy and paste any relevant log output. If your Action's workflow is public, please provide a direct link to the logs
43+
description: Please copy and paste any relevant log output. Please ensure to re-run your workflow with debug mode enabled if you can. The debug logs from this Action are quite rich and can help us solve your problem! If your Action's workflow is public, please provide a direct link to the logs. Thank you!
4444

4545
- type: textarea
4646
id: extra

__tests__/functions/lock.test.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ test('successfully obtains a deployment lock (non-sticky) by creating the branch
159159
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
160160
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
161161
expect(debugMock).toHaveBeenCalledWith(
162-
`constructed lock branch: ${environment}-branch-deploy-lock`
162+
`constructed lock branch name: ${environment}-branch-deploy-lock`
163163
)
164164
})
165165

@@ -175,7 +175,7 @@ test('Determines that another user has the lock (GLOBAL) and exits - during a lo
175175
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
176176
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
177177
expect(debugMock).toHaveBeenCalledWith(
178-
`constructed lock branch: ${environment}-branch-deploy-lock`
178+
`constructed lock branch name: ${environment}-branch-deploy-lock`
179179
)
180180
expect(actionStatusSpy).toHaveBeenCalledWith(
181181
context,
@@ -206,7 +206,7 @@ test('Determines that another user has the lock (non-global) and exits - during
206206
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
207207
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
208208
expect(debugMock).toHaveBeenCalledWith(
209-
`constructed lock branch: ${environment}-branch-deploy-lock`
209+
`constructed lock branch name: ${environment}-branch-deploy-lock`
210210
)
211211
expect(actionStatusSpy).toHaveBeenCalledWith(
212212
context,
@@ -265,7 +265,7 @@ test('Determines that another user has the lock (GLOBAL) and exits - during a di
265265
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
266266
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
267267
expect(debugMock).toHaveBeenCalledWith(
268-
`constructed lock branch: global-branch-deploy-lock`
268+
`constructed lock branch name: global-branch-deploy-lock`
269269
)
270270
expect(actionStatusSpy).toHaveBeenCalledWith(
271271
context,
@@ -323,7 +323,7 @@ test('Determines that another user has the lock (non-global) and exits - during
323323
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
324324
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
325325
expect(debugMock).toHaveBeenCalledWith(
326-
`constructed lock branch: ${environment}-branch-deploy-lock`
326+
`constructed lock branch name: ${environment}-branch-deploy-lock`
327327
)
328328
expect(actionStatusSpy).toHaveBeenCalledWith(
329329
context,
@@ -376,7 +376,7 @@ test('Request detailsOnly on the lock file and gets lock file data successfully'
376376
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
377377
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
378378
expect(debugMock).toHaveBeenCalledWith(
379-
`constructed lock branch: ${environment}-branch-deploy-lock`
379+
`constructed lock branch name: ${environment}-branch-deploy-lock`
380380
)
381381
})
382382

@@ -417,7 +417,7 @@ test('Request detailsOnly on the lock file and gets lock file data successfully
417417
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
418418
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
419419
expect(debugMock).toHaveBeenCalledWith(
420-
`constructed lock branch: ${environment}-branch-deploy-lock`
420+
`constructed lock branch name: ${environment}-branch-deploy-lock`
421421
)
422422
})
423423

@@ -460,7 +460,7 @@ test('Request detailsOnly on the lock file and gets lock file data successfully
460460
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
461461
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
462462
expect(debugMock).toHaveBeenCalledWith(
463-
`constructed lock branch: ${environment}-branch-deploy-lock`
463+
`constructed lock branch name: ${environment}-branch-deploy-lock`
464464
)
465465
})
466466

@@ -502,7 +502,7 @@ test('Request detailsOnly on the lock file and gets lock file data successfully
502502
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
503503
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
504504
expect(debugMock).toHaveBeenCalledWith(
505-
`constructed lock branch: global-branch-deploy-lock`
505+
`constructed lock branch name: global-branch-deploy-lock`
506506
)
507507
})
508508

@@ -534,7 +534,7 @@ test('Request detailsOnly on the lock file and does not find a lock --global', a
534534
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
535535
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
536536
expect(debugMock).toHaveBeenCalledWith(
537-
`constructed lock branch: global-branch-deploy-lock`
537+
`constructed lock branch name: global-branch-deploy-lock`
538538
)
539539
})
540540

@@ -577,7 +577,7 @@ test('Request detailsOnly on the lock file and gets lock file data successfully
577577
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
578578
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
579579
expect(debugMock).toHaveBeenCalledWith(
580-
`constructed lock branch: ${environment}-branch-deploy-lock`
580+
`constructed lock branch name: ${environment}-branch-deploy-lock`
581581
)
582582
})
583583

@@ -605,7 +605,7 @@ test('Request detailsOnly on the lock file when the lock branch exists but no lo
605605
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
606606
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
607607
expect(debugMock).toHaveBeenCalledWith(
608-
`constructed lock branch: ${environment}-branch-deploy-lock`
608+
`constructed lock branch name: ${environment}-branch-deploy-lock`
609609
)
610610
})
611611

@@ -638,7 +638,7 @@ test('Request detailsOnly on the lock file when no branch exists', async () => {
638638
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
639639
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
640640
expect(debugMock).toHaveBeenCalledWith(
641-
`constructed lock branch: ${environment}-branch-deploy-lock`
641+
`constructed lock branch name: ${environment}-branch-deploy-lock`
642642
)
643643
})
644644

@@ -668,7 +668,7 @@ test('Request detailsOnly on the lock file when no branch exists and hits an err
668668
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
669669
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
670670
expect(debugMock).toHaveBeenCalledWith(
671-
`constructed lock branch: ${environment}-branch-deploy-lock`
671+
`constructed lock branch name: ${environment}-branch-deploy-lock`
672672
)
673673
}
674674
})
@@ -693,7 +693,7 @@ test('Determines that the lock request is coming from current owner of the lock
693693
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
694694
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
695695
expect(debugMock).toHaveBeenCalledWith(
696-
`constructed lock branch: ${environment}-branch-deploy-lock`
696+
`constructed lock branch name: ${environment}-branch-deploy-lock`
697697
)
698698
expect(infoMock).toHaveBeenCalledWith('monalisa is the owner of the lock')
699699
})
@@ -718,7 +718,7 @@ test('Determines that the lock request is coming from current owner of the lock
718718
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
719719
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
720720
expect(debugMock).toHaveBeenCalledWith(
721-
`constructed lock branch: ${environment}-branch-deploy-lock`
721+
`constructed lock branch name: ${environment}-branch-deploy-lock`
722722
)
723723
expect(infoMock).toHaveBeenCalledWith('monalisa is the owner of the lock')
724724
})
@@ -759,7 +759,7 @@ test('Determines that the lock request is coming from current owner of the lock
759759
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
760760
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
761761
expect(debugMock).toHaveBeenCalledWith(
762-
`constructed lock branch: global-branch-deploy-lock`
762+
`constructed lock branch name: global-branch-deploy-lock`
763763
)
764764
expect(infoMock).toHaveBeenCalledWith('octocat is the owner of the lock')
765765
})
@@ -785,7 +785,7 @@ test('fails to decode the lock file contents', async () => {
785785
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
786786
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
787787
expect(debugMock).toHaveBeenCalledWith(
788-
`constructed lock branch: ${environment}-branch-deploy-lock`
788+
`constructed lock branch name: ${environment}-branch-deploy-lock`
789789
)
790790
}
791791
})
@@ -814,7 +814,7 @@ test('Creates a lock when the lock branch exists but no lock file exists', async
814814
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
815815
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
816816
expect(debugMock).toHaveBeenCalledWith(
817-
`constructed lock branch: ${environment}-branch-deploy-lock`
817+
`constructed lock branch name: ${environment}-branch-deploy-lock`
818818
)
819819
expect(infoMock).toHaveBeenCalledWith('deployment lock obtained')
820820
})
@@ -828,7 +828,7 @@ test('successfully obtains a deployment lock (sticky) by creating the branch and
828828
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
829829
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
830830
expect(debugMock).toHaveBeenCalledWith(
831-
`constructed lock branch: ${environment}-branch-deploy-lock`
831+
`constructed lock branch name: ${environment}-branch-deploy-lock`
832832
)
833833
expect(infoMock).toHaveBeenCalledWith('deployment lock obtained')
834834
expect(infoMock).toHaveBeenCalledWith('deployment lock is sticky')
@@ -845,7 +845,7 @@ test('successfully obtains a deployment lock (sticky) by creating the branch and
845845
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
846846
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
847847
expect(debugMock).toHaveBeenCalledWith(
848-
`constructed lock branch: ${environment}-branch-deploy-lock`
848+
`constructed lock branch name: ${environment}-branch-deploy-lock`
849849
)
850850
expect(infoMock).toHaveBeenCalledWith('deployment lock obtained')
851851
expect(infoMock).toHaveBeenCalledWith('deployment lock is sticky')
@@ -864,7 +864,7 @@ test('successfully obtains a deployment lock (sticky and global) by creating the
864864
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
865865
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
866866
expect(debugMock).toHaveBeenCalledWith(
867-
`constructed lock branch: global-branch-deploy-lock`
867+
`constructed lock branch name: global-branch-deploy-lock`
868868
)
869869
expect(infoMock).toHaveBeenCalledWith('global lock: true')
870870
expect(infoMock).toHaveBeenCalledWith('deployment lock obtained')
@@ -885,7 +885,7 @@ test('successfully obtains a deployment lock (sticky and global) by creating the
885885
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
886886
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
887887
expect(debugMock).toHaveBeenCalledWith(
888-
`constructed lock branch: global-branch-deploy-lock`
888+
`constructed lock branch name: global-branch-deploy-lock`
889889
)
890890
expect(debugMock).toHaveBeenCalledWith('reason: because something is broken')
891891
expect(infoMock).toHaveBeenCalledWith('global lock: true')
@@ -910,7 +910,7 @@ test('successfully obtains a deployment lock (sticky and global) by creating the
910910
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
911911
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
912912
expect(debugMock).toHaveBeenCalledWith(
913-
`constructed lock branch: global-branch-deploy-lock`
913+
`constructed lock branch name: global-branch-deploy-lock`
914914
)
915915
expect(infoMock).toHaveBeenCalledWith('global lock: true')
916916
expect(infoMock).toHaveBeenCalledWith('deployment lock obtained')
@@ -930,7 +930,7 @@ test('successfully obtains a deployment lock (sticky) by creating the branch and
930930
expect(debugMock).toHaveBeenCalledWith(`detected lock env: development`)
931931
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
932932
expect(debugMock).toHaveBeenCalledWith(
933-
`constructed lock branch: development-branch-deploy-lock`
933+
`constructed lock branch name: development-branch-deploy-lock`
934934
)
935935
expect(debugMock).toHaveBeenCalledWith(
936936
'reason: because something is broken badly'
@@ -951,7 +951,7 @@ test('successfully obtains a deployment lock (sticky) by creating the branch and
951951
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
952952
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
953953
expect(debugMock).toHaveBeenCalledWith(
954-
`constructed lock branch: ${environment}-branch-deploy-lock`
954+
`constructed lock branch name: ${environment}-branch-deploy-lock`
955955
)
956956
expect(debugMock).toHaveBeenCalledWith('reason: because something is broken')
957957
expect(infoMock).toHaveBeenCalledWith('global lock: false')

__tests__/functions/trigger-check.test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,33 @@ import * as core from '@actions/core'
33

44
const setOutputMock = jest.spyOn(core, 'setOutput')
55
const infoMock = jest.spyOn(core, 'info')
6+
const debugMock = jest.spyOn(core, 'debug')
67

78
beforeEach(() => {
89
jest.clearAllMocks()
910
jest.spyOn(core, 'setOutput').mockImplementation(() => {})
1011
jest.spyOn(core, 'saveState').mockImplementation(() => {})
1112
jest.spyOn(core, 'info').mockImplementation(() => {})
13+
jest.spyOn(core, 'debug').mockImplementation(() => {})
1214
})
1315

1416
test('checks a message and finds a standard trigger', async () => {
1517
const body = '.deploy'
1618
const trigger = '.deploy'
1719
expect(await triggerCheck(body, trigger)).toBe(true)
1820
expect(setOutputMock).toHaveBeenCalledWith('comment_body', '.deploy')
21+
expect(infoMock).toHaveBeenCalledWith(
22+
'✅ comment body starts with trigger: ".deploy"'
23+
)
1924
})
2025

2126
test('checks a message and does not find trigger', async () => {
2227
const body = '.bad'
2328
const trigger = '.deploy'
2429
expect(await triggerCheck(body, trigger)).toBe(false)
2530
expect(setOutputMock).toHaveBeenCalledWith('comment_body', '.bad')
26-
expect(infoMock).toHaveBeenCalledWith(
27-
'Trigger ".deploy" not found in the comment body'
31+
expect(debugMock).toHaveBeenCalledWith(
32+
'comment body does not start with trigger: ".deploy"'
2833
)
2934
})
3035

@@ -69,7 +74,7 @@ test('checks a message and does not find global trigger', async () => {
6974
'comment_body',
7075
'I want to .ping a website'
7176
)
72-
expect(infoMock).toHaveBeenCalledWith(
73-
'Trigger ".deploy" not found in the comment body'
77+
expect(debugMock).toHaveBeenCalledWith(
78+
'comment body does not start with trigger: ".deploy"'
7479
)
7580
})

__tests__/main.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ beforeEach(() => {
4848
process.env.INPUT_REQUIRED_CONTEXTS = 'false'
4949
process.env.INPUT_ALLOW_FORKS = 'true'
5050
process.env.GITHUB_REPOSITORY = 'corp/test'
51+
process.env.INPUT_GLOBAL_LOCK_FLAG = '--global'
5152
github.context.payload = {
5253
issue: {
5354
number: 123
@@ -203,7 +204,7 @@ test('runs the action in lock mode and fails due to bad permissions', async () =
203204
expect(setFailedMock).toHaveBeenCalledWith(permissionsMsg)
204205
})
205206

206-
test('successfully runs the action in lock mode', async () => {
207+
test('successfully runs the action in lock mode with a reason', async () => {
207208
jest.spyOn(validPermissions, 'validPermissions').mockImplementation(() => {
208209
return true
209210
})
@@ -683,7 +684,6 @@ test('runs the .help command successfully', async () => {
683684
})
684685

685686
test('runs the action in lock mode and fails due to an invalid environment', async () => {
686-
process.env.INPUT_GLOBAL_LOCK_FLAG = '--global'
687687
jest.spyOn(actionStatus, 'actionStatus').mockImplementation(() => {
688688
return undefined
689689
})

0 commit comments

Comments
 (0)