Skip to content

Commit

Permalink
update tests and bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Oct 5, 2023
1 parent 47182c1 commit b16a087
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
43 changes: 43 additions & 0 deletions __tests__/functions/prechecks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,49 @@ test('runs prechecks on a custom deploy comment with a custom variable at the en
)
})

test('runs prechecks when an exact sha is set, but the sha deployment feature is not enabled', async () => {
data.inputs.allow_sha_deployments = false
data.environmentObj.sha = '82c238c277ca3df56fe9418a5913d9188eafe3bc'

expect(
await prechecks(
context, // event context
octokit, // octokit instance
data // data object
)
).toStrictEqual({
message: `### ⚠️ Cannot proceed with deployment\n\n- allow_sha_deployments: \`${data.inputs.allow_sha_deployments}\`\n\n> sha deployments have not been enabled`,
status: false
})
})

test('runs prechecks when an exact sha is set, and the sha deployment feature is enabled', async () => {
data.inputs.allow_sha_deployments = true
data.environmentObj.sha = '82c238c277ca3df56fe9418a5913d9188eafe3bc'

expect(
await prechecks(
context, // event context
octokit, // octokit instance
data // data object
)
).toStrictEqual({
message: `✅ deployment requested using an exact ${COLORS.highlight}sha${COLORS.reset}`,
noopMode: false,
ref: data.environmentObj.sha,
status: true,
sha: data.environmentObj.sha
})

expect(infoMock).toHaveBeenCalledWith(
`✅ deployment requested using an exact ${COLORS.highlight}sha${COLORS.reset}`
)

expect(warningMock).toHaveBeenCalledWith(
`⚠️ sha deployments are ${COLORS.warning}unsafe${COLORS.reset} as they bypass all checks - read more here: https://github.com/github/branch-deploy/issues/213`
)
})

test('runs prechecks and finds that skip_ci is set and now reviews are defined', async () => {
octokit.graphql = jest.fn().mockReturnValue({
repository: {
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 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.

10 changes: 9 additions & 1 deletion src/functions/prechecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export async function prechecks(context, octokit, data) {
// ... this style of deployment is not recommended and should only be used in very specific situations. Read more here:
// https://github.com/github/branch-deploy/issues/213
} else if (
data.allow_sha_deployments === true &&
data.inputs.allow_sha_deployments === true &&
data.environmentObj.sha !== null
) {
message = `✅ deployment requested using an exact ${COLORS.highlight}sha${COLORS.reset}`
Expand All @@ -284,6 +284,14 @@ export async function prechecks(context, octokit, data) {
sha = data.environmentObj.sha
ref = data.environmentObj.sha

// If allow_sha_deployments are not enabled and a sha was provided, exit
} else if (
data.inputs.allow_sha_deployments === false &&
data.environmentObj.sha !== null
) {
message = `### ⚠️ Cannot proceed with deployment\n\n- allow_sha_deployments: \`${data.inputs.allow_sha_deployments}\`\n\n> sha deployments have not been enabled`
return {message: message, status: false}

// If update_branch is not "disabled", check the mergeStateStatus to see if it is BEHIND
} else if (
(commitStatus === 'SUCCESS' ||
Expand Down

0 comments on commit b16a087

Please sign in to comment.