Skip to content

sha deployments #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
| `deploy_message_path` | `false` | `".github/deployment_message.md"` | The path to a markdown file which is used as a template for custom deployment messages. Example: `".github/deployment_message.md"` |
| `sticky_locks` | `false` | `"false"` | If set to `"true"`, locks will not be released after a deployment run completes. This applies to both successful, and failed deployments.Sticky locks are also known as ["hubot style deployment locks"](./docs/hubot-style-deployment-locks.md). They will persist until they are manually released by a user, or if you configure [another workflow with the "unlock on merge" mode](./docs/unlock-on-merge.md) to remove them automatically on PR merge. |
| `sticky_locks_for_noop` | `false` | `"false"` | If set to `"true"`, then sticky_locks will also be used for noop deployments. This can be useful in some cases but it often leads to locks being left behind when users test noop deployments. |
| `allow_sha_deployments` | `false` | `"false"` | If set to `"true"`, then you can deploy a specific sha instead of a branch. Example: `".deploy 1234567890abcdef1234567890abcdef12345678 to production"` - This is dangerous and potentially unsafe, [view the docs](docs/sha-deployments.md) to learn more |

## Outputs 📤

Expand Down Expand Up @@ -313,6 +314,7 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
| `global_lock_claimed` | The string "true" if the global lock was claimed |
| `global_lock_released` | The string "true" if the global lock was released |
| `unlocked_environments` | Only exposed when using the "unlock on merge" mode - This output variable will contain a comma separated list of the environments that were unlocked - See the [unlock on merge mode](docs/unlock-on-merge.md) documentation for more details |
| `sha_deployment` | If `allow_sha_deployments` is enabled, and a sha deployment is performed instead of a branch deployment, this output variable will contain the sha that was deployed. Otherwise, this output variable will be empty |

## Custom Deployment Messages ✏️

Expand Down
189 changes: 167 additions & 22 deletions __tests__/functions/environment-targets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ test('checks the comment body and does not find an explicit environment target',
target: 'production',
noop: false,
stable_branch_used: false,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -68,7 +69,8 @@ test('checks the comment body and finds an explicit environment target for devel
target: 'development',
noop: false,
stable_branch_used: false,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -92,7 +94,8 @@ test('checks the comment body and finds an explicit environment target for devel
target: 'development',
noop: false,
stable_branch_used: false,
params: 'something1 something2 something3'
params: 'something1 something2 something3',
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -107,6 +110,129 @@ test('checks the comment body and finds an explicit environment target for devel
)
})

test('checks the comment body and finds an explicit environment target and an explicit sha (sha1) for development with params', async () => {
expect(
await environmentTargets(
environment,
'.deploy 82c238c277ca3df56fe9418a5913d9188eafe3bc development | something1 something2 something3',
trigger,
noop_trigger,
stable_branch
)
).toStrictEqual({
environment: 'development',
environmentUrl: null,
environmentObj: {
target: 'development',
noop: false,
stable_branch_used: false,
params: 'something1 something2 something3',
sha: '82c238c277ca3df56fe9418a5913d9188eafe3bc'
}
})
expect(debugMock).toHaveBeenCalledWith(
'found environment target for branch deploy: development'
)
expect(infoMock).toHaveBeenCalledWith(
`🧮 detected parameters in command: ${COLORS.highlight}something1 something2 something3`
)
expect(setOutputMock).toHaveBeenCalledWith(
'params',
'something1 something2 something3'
)
})

test('checks the comment body and finds an explicit environment target and an explicit sha (sha1) for development with params on a noop command', async () => {
expect(
await environmentTargets(
environment,
'.noop 82c238c277ca3df56fe9418a5913d9188eafe3bc development | something1 something2 something3',
trigger,
noop_trigger,
stable_branch
)
).toStrictEqual({
environment: 'development',
environmentUrl: null,
environmentObj: {
target: 'development',
noop: true,
stable_branch_used: false,
params: 'something1 something2 something3',
sha: '82c238c277ca3df56fe9418a5913d9188eafe3bc'
}
})
expect(debugMock).toHaveBeenCalledWith(
'found environment target for noop trigger: development'
)
expect(infoMock).toHaveBeenCalledWith(
`🧮 detected parameters in command: ${COLORS.highlight}something1 something2 something3`
)
expect(setOutputMock).toHaveBeenCalledWith(
'params',
'something1 something2 something3'
)
})

test('checks the comment body and finds an explicit environment target and an explicit sha (sha1) for development with params on a noop command and the sha is a sha256 hash (64 characters)', async () => {
expect(
await environmentTargets(
environment,
'.noop f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b development | something1 something2 something3',
trigger,
noop_trigger,
stable_branch
)
).toStrictEqual({
environment: 'development',
environmentUrl: null,
environmentObj: {
target: 'development',
noop: true,
stable_branch_used: false,
params: 'something1 something2 something3',
sha: 'f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b'
}
})
expect(debugMock).toHaveBeenCalledWith(
'found environment target for noop trigger: development'
)
expect(infoMock).toHaveBeenCalledWith(
`🧮 detected parameters in command: ${COLORS.highlight}something1 something2 something3`
)
expect(setOutputMock).toHaveBeenCalledWith(
'params',
'something1 something2 something3'
)
})

test('checks the comment body and finds an explicit environment target and an explicit sha (sha1) on a noop command with trailing whitespace', async () => {
expect(
await environmentTargets(
environment,
'.noop 82c238c277ca3df56fe9418a5913d9188eafe3bc ',
trigger,
noop_trigger,
stable_branch
)
).toStrictEqual({
environment: 'production',
environmentUrl: null,
environmentObj: {
target: 'production',
noop: true,
stable_branch_used: false,
params: null,
sha: '82c238c277ca3df56fe9418a5913d9188eafe3bc'
}
})

expect(debugMock).toHaveBeenCalledWith('no parameters detected in command')
expect(debugMock).toHaveBeenCalledWith(
'using default environment for noop trigger'
)
})

test('checks the comment body and finds an explicit environment target for development to stable_branch with params and a custom separator', async () => {
expect(
await environmentTargets(
Expand All @@ -129,7 +255,8 @@ test('checks the comment body and finds an explicit environment target for devel
target: 'development',
noop: false,
stable_branch_used: true,
params: 'something1 | something2 something3'
params: 'something1 | something2 something3',
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand Down Expand Up @@ -160,7 +287,8 @@ test('checks the comment body and finds an explicit environment target for stagi
target: 'staging',
noop: true,
stable_branch_used: false,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -184,7 +312,8 @@ test('checks the comment body and finds an explicit environment target for stagi
target: 'staging',
noop: true,
stable_branch_used: true,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand Down Expand Up @@ -213,7 +342,8 @@ test('checks the comment body and finds an explicit environment target for stagi
target: 'staging',
noop: true,
stable_branch_used: false,
params: null
params: null,
sha: null
}
})
expect(infoMock).toHaveBeenCalledWith(
Expand Down Expand Up @@ -253,7 +383,8 @@ test('checks the comment body and finds an explicit environment target for stagi
target: 'staging',
noop: true,
stable_branch_used: true,
params: 'something1 something2 something3'
params: 'something1 something2 something3',
sha: null
}
})
expect(infoMock).toHaveBeenCalledWith(
Expand Down Expand Up @@ -293,7 +424,8 @@ test('checks the comment body and uses the default production environment target
target: 'production',
noop: false,
stable_branch_used: false,
params: null
params: null,
sha: null
}
})
expect(infoMock).toHaveBeenCalledWith(
Expand Down Expand Up @@ -333,7 +465,8 @@ test('checks the comment body and finds an explicit environment target for a pro
target: 'production',
noop: false,
params: null,
stable_branch_used: false
stable_branch_used: false,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand Down Expand Up @@ -367,7 +500,8 @@ test('checks the comment body and finds an explicit environment target for a pro
target: 'production',
stable_branch_used: false,
noop: false,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand Down Expand Up @@ -404,7 +538,8 @@ test('checks the comment body and finds an explicit environment target for a pro
target: 'production',
stable_branch_used: false,
noop: false,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand Down Expand Up @@ -433,7 +568,8 @@ test('checks the comment body and finds an explicit environment target for stagi
target: 'staging',
stable_branch_used: false,
noop: true,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -457,7 +593,8 @@ test('checks the comment body and finds a noop deploy to the stable branch and d
target: 'production',
stable_branch_used: true,
noop: true,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -481,7 +618,8 @@ test('checks the comment body and finds a noop deploy to the stable branch and d
target: 'production',
stable_branch_used: true,
noop: true,
params: 'foo=bar'
params: 'foo=bar',
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -505,7 +643,8 @@ test('checks the comment body and finds an explicit environment target for produ
target: 'production',
stable_branch_used: false,
noop: false,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -529,7 +668,8 @@ test('checks the comment body on a noop deploy and does not find an explicit env
target: 'production',
stable_branch_used: false,
noop: true,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -553,7 +693,8 @@ test('checks the comment body on a deployment and does not find any matching env
noop: null,
params: null,
stable_branch_used: null,
target: false
target: false,
sha: null
}
})

Expand Down Expand Up @@ -583,7 +724,8 @@ test('checks the comment body on a stable branch deployment and finds a matching
target: 'production',
stable_branch_used: true,
noop: false,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -607,7 +749,8 @@ test('checks the comment body on a stable branch deployment and finds a matching
target: 'production',
stable_branch_used: true,
noop: false,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -631,7 +774,8 @@ test('checks the comment body on a stable branch deployment and uses the default
target: 'production',
stable_branch_used: true,
noop: false,
params: null
params: null,
sha: null
}
})
expect(debugMock).toHaveBeenCalledWith(
Expand All @@ -655,7 +799,8 @@ test('checks the comment body on a stable branch deployment and does not find a
noop: null,
params: null,
stable_branch_used: null,
target: false
target: false,
sha: null
}
})

Expand Down
9 changes: 6 additions & 3 deletions __tests__/functions/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const defaultInputs = {
skipReviews: '',
draft_permitted_targets: '',
admins: 'false',
permissions: ['write', 'admin', 'maintain']
permissions: ['write', 'admin', 'maintain'],
allow_sha_deployments: false
}

test('successfully calls help with defaults', async () => {
Expand Down Expand Up @@ -75,7 +76,8 @@ test('successfully calls help with non-defaults', async () => {
skipReviews: 'development',
draft_permitted_targets: 'development',
admins: 'monalisa',
permissions: ['write', 'admin', 'maintain']
permissions: ['write', 'admin', 'maintain'],
allow_sha_deployments: true
}

expect(await help(octokit, context, 123, inputs))
Expand Down Expand Up @@ -106,7 +108,8 @@ test('successfully calls help with non-defaults', async () => {
skipReviews: 'development',
draft_permitted_targets: 'development',
admins: 'monalisa',
permissions: ['write', 'admin', 'maintain']
permissions: ['write', 'admin', 'maintain'],
allow_sha_deployments: false
}

expect(await help(octokit, context, 123, inputs))
Expand Down
Loading