Skip to content

Commit

Permalink
Merge pull request #187 from github/lock-bug
Browse files Browse the repository at this point in the history
Lock bug
  • Loading branch information
GrantBirki authored Aug 16, 2023
2 parents 5e59914 + 735fe9f commit 13ae6c8
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ body:
id: logs
attributes:
label: Relevant Actions Log Output
description: Please copy and paste any relevant log output. If your Action's workflow is public, please provide a direct link to the logs
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!

- type: textarea
id: extra
Expand Down
52 changes: 26 additions & 26 deletions __tests__/functions/lock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ test('successfully obtains a deployment lock (non-sticky) by creating the branch
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
})

Expand All @@ -175,7 +175,7 @@ test('Determines that another user has the lock (GLOBAL) and exits - during a lo
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
expect(actionStatusSpy).toHaveBeenCalledWith(
context,
Expand Down Expand Up @@ -206,7 +206,7 @@ test('Determines that another user has the lock (non-global) and exits - during
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
expect(actionStatusSpy).toHaveBeenCalledWith(
context,
Expand Down Expand Up @@ -265,7 +265,7 @@ test('Determines that another user has the lock (GLOBAL) and exits - during a di
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: global-branch-deploy-lock`
`constructed lock branch name: global-branch-deploy-lock`
)
expect(actionStatusSpy).toHaveBeenCalledWith(
context,
Expand Down Expand Up @@ -323,7 +323,7 @@ test('Determines that another user has the lock (non-global) and exits - during
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
expect(actionStatusSpy).toHaveBeenCalledWith(
context,
Expand Down Expand Up @@ -376,7 +376,7 @@ test('Request detailsOnly on the lock file and gets lock file data successfully'
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
})

Expand Down Expand Up @@ -417,7 +417,7 @@ test('Request detailsOnly on the lock file and gets lock file data successfully
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
})

Expand Down Expand Up @@ -460,7 +460,7 @@ test('Request detailsOnly on the lock file and gets lock file data successfully
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
})

Expand Down Expand Up @@ -502,7 +502,7 @@ test('Request detailsOnly on the lock file and gets lock file data successfully
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: global-branch-deploy-lock`
`constructed lock branch name: global-branch-deploy-lock`
)
})

Expand Down Expand Up @@ -534,7 +534,7 @@ test('Request detailsOnly on the lock file and does not find a lock --global', a
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: global-branch-deploy-lock`
`constructed lock branch name: global-branch-deploy-lock`
)
})

Expand Down Expand Up @@ -577,7 +577,7 @@ test('Request detailsOnly on the lock file and gets lock file data successfully
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
})

Expand Down Expand Up @@ -605,7 +605,7 @@ test('Request detailsOnly on the lock file when the lock branch exists but no lo
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
})

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

Expand Down Expand Up @@ -668,7 +668,7 @@ test('Request detailsOnly on the lock file when no branch exists and hits an err
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
}
})
Expand All @@ -693,7 +693,7 @@ test('Determines that the lock request is coming from current owner of the lock
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
expect(infoMock).toHaveBeenCalledWith('monalisa is the owner of the lock')
})
Expand All @@ -718,7 +718,7 @@ test('Determines that the lock request is coming from current owner of the lock
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
expect(infoMock).toHaveBeenCalledWith('monalisa is the owner of the lock')
})
Expand Down Expand Up @@ -759,7 +759,7 @@ test('Determines that the lock request is coming from current owner of the lock
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: global-branch-deploy-lock`
`constructed lock branch name: global-branch-deploy-lock`
)
expect(infoMock).toHaveBeenCalledWith('octocat is the owner of the lock')
})
Expand All @@ -785,7 +785,7 @@ test('fails to decode the lock file contents', async () => {
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
}
})
Expand Down Expand Up @@ -814,7 +814,7 @@ test('Creates a lock when the lock branch exists but no lock file exists', async
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
expect(infoMock).toHaveBeenCalledWith('deployment lock obtained')
})
Expand All @@ -828,7 +828,7 @@ test('successfully obtains a deployment lock (sticky) by creating the branch and
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
expect(infoMock).toHaveBeenCalledWith('deployment lock obtained')
expect(infoMock).toHaveBeenCalledWith('deployment lock is sticky')
Expand All @@ -845,7 +845,7 @@ test('successfully obtains a deployment lock (sticky) by creating the branch and
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
expect(infoMock).toHaveBeenCalledWith('deployment lock obtained')
expect(infoMock).toHaveBeenCalledWith('deployment lock is sticky')
Expand All @@ -864,7 +864,7 @@ test('successfully obtains a deployment lock (sticky and global) by creating the
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: global-branch-deploy-lock`
`constructed lock branch name: global-branch-deploy-lock`
)
expect(infoMock).toHaveBeenCalledWith('global lock: true')
expect(infoMock).toHaveBeenCalledWith('deployment lock obtained')
Expand All @@ -885,7 +885,7 @@ test('successfully obtains a deployment lock (sticky and global) by creating the
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: global-branch-deploy-lock`
`constructed lock branch name: global-branch-deploy-lock`
)
expect(debugMock).toHaveBeenCalledWith('reason: because something is broken')
expect(infoMock).toHaveBeenCalledWith('global lock: true')
Expand All @@ -910,7 +910,7 @@ test('successfully obtains a deployment lock (sticky and global) by creating the
expect(debugMock).toHaveBeenCalledWith(`detected lock env: null`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: true`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: global-branch-deploy-lock`
`constructed lock branch name: global-branch-deploy-lock`
)
expect(infoMock).toHaveBeenCalledWith('global lock: true')
expect(infoMock).toHaveBeenCalledWith('deployment lock obtained')
Expand All @@ -930,7 +930,7 @@ test('successfully obtains a deployment lock (sticky) by creating the branch and
expect(debugMock).toHaveBeenCalledWith(`detected lock env: development`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: development-branch-deploy-lock`
`constructed lock branch name: development-branch-deploy-lock`
)
expect(debugMock).toHaveBeenCalledWith(
'reason: because something is broken badly'
Expand All @@ -951,7 +951,7 @@ test('successfully obtains a deployment lock (sticky) by creating the branch and
expect(debugMock).toHaveBeenCalledWith(`detected lock env: ${environment}`)
expect(debugMock).toHaveBeenCalledWith(`detected lock global: false`)
expect(debugMock).toHaveBeenCalledWith(
`constructed lock branch: ${environment}-branch-deploy-lock`
`constructed lock branch name: ${environment}-branch-deploy-lock`
)
expect(debugMock).toHaveBeenCalledWith('reason: because something is broken')
expect(infoMock).toHaveBeenCalledWith('global lock: false')
Expand Down
13 changes: 9 additions & 4 deletions __tests__/functions/trigger-check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,33 @@ import * as core from '@actions/core'

const setOutputMock = jest.spyOn(core, 'setOutput')
const infoMock = jest.spyOn(core, 'info')
const debugMock = jest.spyOn(core, 'debug')

beforeEach(() => {
jest.clearAllMocks()
jest.spyOn(core, 'setOutput').mockImplementation(() => {})
jest.spyOn(core, 'saveState').mockImplementation(() => {})
jest.spyOn(core, 'info').mockImplementation(() => {})
jest.spyOn(core, 'debug').mockImplementation(() => {})
})

test('checks a message and finds a standard trigger', async () => {
const body = '.deploy'
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(true)
expect(setOutputMock).toHaveBeenCalledWith('comment_body', '.deploy')
expect(infoMock).toHaveBeenCalledWith(
'✅ comment body starts with trigger: ".deploy"'
)
})

test('checks a message and does not find trigger', async () => {
const body = '.bad'
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(false)
expect(setOutputMock).toHaveBeenCalledWith('comment_body', '.bad')
expect(infoMock).toHaveBeenCalledWith(
'Trigger ".deploy" not found in the comment body'
expect(debugMock).toHaveBeenCalledWith(
'comment body does not start with trigger: ".deploy"'
)
})

Expand Down Expand Up @@ -69,7 +74,7 @@ test('checks a message and does not find global trigger', async () => {
'comment_body',
'I want to .ping a website'
)
expect(infoMock).toHaveBeenCalledWith(
'Trigger ".deploy" not found in the comment body'
expect(debugMock).toHaveBeenCalledWith(
'comment body does not start with trigger: ".deploy"'
)
})
4 changes: 2 additions & 2 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ beforeEach(() => {
process.env.INPUT_REQUIRED_CONTEXTS = 'false'
process.env.INPUT_ALLOW_FORKS = 'true'
process.env.GITHUB_REPOSITORY = 'corp/test'
process.env.INPUT_GLOBAL_LOCK_FLAG = '--global'
github.context.payload = {
issue: {
number: 123
Expand Down Expand Up @@ -203,7 +204,7 @@ test('runs the action in lock mode and fails due to bad permissions', async () =
expect(setFailedMock).toHaveBeenCalledWith(permissionsMsg)
})

test('successfully runs the action in lock mode', async () => {
test('successfully runs the action in lock mode with a reason', async () => {
jest.spyOn(validPermissions, 'validPermissions').mockImplementation(() => {
return true
})
Expand Down Expand Up @@ -683,7 +684,6 @@ test('runs the .help command successfully', async () => {
})

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

0 comments on commit 13ae6c8

Please sign in to comment.