Skip to content

Commit 8c60cc1

Browse files
committed
add deployment_confirmation and deployment_confirmation_timeout to the action inputs
1 parent d6a4a69 commit 8c60cc1

File tree

9 files changed

+92
-5
lines changed

9 files changed

+92
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
301301
| `enforced_deployment_order` | `false` | `""` | A comma separated list of environments that must be deployed in a specific order. Example: `"development,staging,production"`. If this is set then you cannot deploy to latter environments unless the former ones have a successful and active deployment on the latest commit first - See the [enforced deployment order docs](./docs/enforced-deployment-order.md) for more details |
302302
| `use_security_warnings` | `false` | `"true"` | Whether or not to leave security related warnings in log messages during deployments. Default is `"true"` |
303303
| `allow_non_default_target_branch_deployments` | `false` | `"false"` | Whether or not to allow deployments of pull requests that target a branch other than the default branch (aka stable branch) as their merge target. By default, this Action would reject the deployment of a branch named `feature-branch` if it was targeting `foo` instead of `main` (or whatever your default branch is). This option allows you to override that behavior and be able to deploy any branch in your repository regardless of the target branch. This option is potentially unsafe and should be used with caution as most default branches contain branch protection rules. Often times non-default branches do not contain these same branch protection rules. Follow along in this [issue thread](https://github.com/github/branch-deploy/issues/340) to learn more. |
304+
| `deployment_confirmation` | `false` | `"false"` | Whether or not to require an additional confirmation before a deployment can continue. Default is `"false"`. If your project requires elevated security, it is highly recommended to enable this option - especially in open source projects where you might be deploying forks. |
305+
| `deployment_confirmation_timeout` | `false` | `60` | The number of seconds to wait for a deployment confirmation before timing out. Default is `60` seconds (1 minute). |
304306

305307
## Outputs 📤
306308

__tests__/functions/help.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ const defaultInputs = {
5151
ignored_checks: [],
5252
enforced_deployment_order: [],
5353
use_security_warnings: true,
54-
allow_non_default_target_branch_deployments: false
54+
allow_non_default_target_branch_deployments: false,
55+
deployment_confirmation: false,
56+
deployment_confirmation_timeout: 60
5557
}
5658

5759
test('successfully calls help with defaults', async () => {
@@ -91,7 +93,8 @@ test('successfully calls help with non-defaults', async () => {
9193
commit_verification: false,
9294
enforced_deployment_order: [],
9395
use_security_warnings: false,
94-
allow_non_default_target_branch_deployments: false
96+
allow_non_default_target_branch_deployments: false,
97+
deployment_confirmation: true
9598
}
9699

97100
expect(await help(octokit, context, 123, inputs))

__tests__/main.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ test('successfully runs the action', async () => {
228228
)
229229
})
230230

231+
test('fails the action early on when it fails to parse an int input', async () => {
232+
process.env.INPUT_DEPLOYMENT_CONFIRMATION_TIMEOUT = 'not-an-int'
233+
234+
expect(await run()).toBe(undefined)
235+
expect(setFailedMock).toHaveBeenCalledWith(
236+
'Invalid value for deployment_confirmation_timeout: must be an integer'
237+
)
238+
expect(saveStateMock).toHaveBeenCalledWith('bypass', 'true')
239+
expect(infoMock).not.toHaveBeenCalledWith(
240+
`🧑‍🚀 commit sha to deploy: ${COLORS.highlight}${mock_sha}${COLORS.reset}`
241+
)
242+
expect(infoMock).not.toHaveBeenCalledWith(
243+
`🚀 ${COLORS.success}deployment started!${COLORS.reset}`
244+
)
245+
})
246+
231247
test('successfully runs the action with deployment confirmation', async () => {
232248
process.env.INPUT_DEPLOYMENT_CONFIRMATION = 'true'
233249

__tests__/schemas/action.schema.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,26 @@ inputs:
500500
default:
501501
type: string
502502
required: false
503+
deployment_confirmation:
504+
description:
505+
type: string
506+
required: true
507+
required:
508+
type: boolean
509+
required: true
510+
default:
511+
type: string
512+
required: false
513+
deployment_confirmation_timeout:
514+
description:
515+
type: string
516+
required: true
517+
required:
518+
type: boolean
519+
required: true
520+
default:
521+
type: string
522+
required: false
503523

504524
# outputs section
505525
outputs:

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ inputs:
193193
description: 'Whether or not to allow deployments of pull requests that target a branch other than the default branch (aka stable branch) as their merge target. By default, this Action would reject the deployment of a branch named "feature-branch" if it was targeting "foo" instead of "main" (or whatever your default branch is). This option allows you to override that behavior and be able to deploy any branch in your repository regardless of the target branch. This option is potentially unsafe and should be used with caution as most default branches contain branch protection rules. Often times non-default branches do not contain these same branch protection rules. Follow along in this issue thread to learn more https://github.com/github/branch-deploy/issues/340'
194194
required: false
195195
default: "false"
196+
deployment_confirmation:
197+
description: 'Whether or not to require an additional confirmation before a deployment can continue. Default is "false". If your project requires elevated security, it is highly recommended to enable this option - especially in open source projects where you might be deploying forks.'
198+
required: false
199+
default: "false"
200+
deployment_confirmation_timeout:
201+
description: 'The number of seconds to wait for a deployment confirmation before timing out. Default is "60" seconds (1 minute).'
202+
required: false
203+
default: "60"
196204
outputs:
197205
continue:
198206
description: 'The string "true" if the deployment should continue, otherwise empty - Use this to conditionally control if your deployment should proceed or not'

dist/index.js

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/help.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ export async function help(octokit, context, reactionId, inputs) {
230230
inputs.draft_permitted_targets
231231
}\` - ${draft_permitted_targets_message}
232232
- \`admins: ${inputs.admins}\` - ${admins_message}
233+
- \`deployment_confirmation: ${
234+
inputs.deployment_confirmation
235+
}\` - This Action will ${
236+
inputs.deployment_confirmation === true ? 'require' : 'not require'
237+
} additional confirmation before deploying
238+
- \`deployment_confirmation_timeout: ${
239+
inputs.deployment_confirmation_timeout
240+
}\` - The timeout (seconds) for the deployment confirmation
233241
- \`permissions: ${inputs.permissions.join(
234242
','
235243
)}\` - The acceptable permissions that this Action will require to run

src/functions/inputs.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ function validateInput(inputName, inputValue, validValues) {
1515
}
1616
}
1717

18+
// Helper function to parse and validate integer inputs
19+
// :param inputName: The name of the input being parsed (string)
20+
// :returns: The parsed integer value
21+
function getIntInput(inputName) {
22+
const value = parseInt(core.getInput(inputName), 10)
23+
if (isNaN(value)) {
24+
throw new Error(`Invalid value for ${inputName}: must be an integer`)
25+
}
26+
return value
27+
}
28+
1829
// Helper function to get all the inputs for the Action
1930
// :returns: An object containing all the inputs
2031
export function getInputs() {
@@ -62,7 +73,7 @@ export function getInputs() {
6273
const deployment_confirmation = core.getBooleanInput(
6374
'deployment_confirmation'
6475
)
65-
const deployment_confirmation_timeout = core.getInput(
76+
const deployment_confirmation_timeout = getIntInput(
6677
'deployment_confirmation_timeout'
6778
)
6879

0 commit comments

Comments
 (0)