Skip to content

Commit 0336ed7

Browse files
committed
add allow_non_default_target_branch_deployments as a new input option
1 parent 8ee0839 commit 0336ed7

File tree

9 files changed

+56
-7
lines changed

9 files changed

+56
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
300300
| `skip_successful_deploy_labels_if_approved` | `false` | `"false"` | Whether or not the post run logic should skip adding successful deploy labels if the pull request is approved. This can be useful if you add a label such as "ready-for-review" after a `.deploy` completes but want to skip adding that label in situations where the pull request is already approved. |
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"` |
303+
| `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. |
303304

304305
## Outputs 📤
305306

__tests__/functions/help.test.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ const defaultInputs = {
5050
commit_verification: true,
5151
ignored_checks: [],
5252
enforced_deployment_order: [],
53-
use_security_warnings: true
53+
use_security_warnings: true,
54+
allow_non_default_target_branch_deployments: false
5455
}
5556

5657
test('successfully calls help with defaults', async () => {
@@ -89,7 +90,8 @@ test('successfully calls help with non-defaults', async () => {
8990
ignored_checks: ['lint', 'format'],
9091
commit_verification: false,
9192
enforced_deployment_order: [],
92-
use_security_warnings: false
93+
use_security_warnings: false,
94+
allow_non_default_target_branch_deployments: false
9395
}
9496

9597
expect(await help(octokit, context, 123, inputs))
@@ -127,7 +129,8 @@ test('successfully calls help with non-defaults again', async () => {
127129
ignored_checks: ['lint'],
128130
commit_verification: false,
129131
enforced_deployment_order: ['development', 'staging', 'production'],
130-
use_security_warnings: false
132+
use_security_warnings: false,
133+
allow_non_default_target_branch_deployments: false
131134
}
132135

133136
expect(await help(octokit, context, 123, inputs))
@@ -176,7 +179,8 @@ test('successfully calls help with non-defaults and unknown update_branch settin
176179
checks: 'required',
177180
ignored_checks: ['lint'],
178181
enforced_deployment_order: [],
179-
use_security_warnings: false
182+
use_security_warnings: false,
183+
allow_non_default_target_branch_deployments: true
180184
}
181185

182186
expect(await help(octokit, context, 123, inputs))
@@ -197,4 +201,9 @@ test('successfully calls help with non-defaults and unknown update_branch settin
197201
expect(debugMock).toHaveBeenCalledWith(
198202
expect.stringMatching(/not use security warnings/)
199203
)
204+
expect(debugMock).toHaveBeenCalledWith(
205+
expect.stringMatching(
206+
/will allow the deployments of pull requests that target a branch other than the default branch/
207+
)
208+
)
200209
})

__tests__/main.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ beforeEach(() => {
9090
process.env.INPUT_COMMIT_VERIFICATION = 'false'
9191
process.env.INPUT_IGNORED_CHECKS = ''
9292
process.env.INPUT_USE_SECURITY_WARNINGS = 'true'
93+
process.env.INPUT_ALLOW_NON_DEFAULT_TARGET_BRANCH_DEPLOYMENTS = 'false'
9394

9495
github.context.payload = {
9596
issue: {

__tests__/schemas/action.schema.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,16 @@ inputs:
490490
default:
491491
type: string
492492
required: false
493+
allow_non_default_target_branch_deployments:
494+
description:
495+
type: string
496+
required: true
497+
required:
498+
type: boolean
499+
required: true
500+
default:
501+
type: string
502+
required: false
493503

494504
# outputs section
495505
outputs:

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ inputs:
189189
description: 'Whether or not to leave security related warnings in log messages during deployments. Default is "true"'
190190
required: false
191191
default: "true"
192+
allow_non_default_target_branch_deployments:
193+
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.'
194+
required: false
195+
default: "false"
192196
outputs:
193197
continue:
194198
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: 13 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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ export async function help(octokit, context, reactionId, inputs) {
236236
- \`allow_sha_deployments: ${
237237
inputs.allow_sha_deployments
238238
}\` - ${sha_deployment_message}
239+
- \`allow_non_default_target_branch_deployments: ${
240+
inputs.allow_non_default_target_branch_deployments
241+
}\` - This Action will ${
242+
inputs.allow_non_default_target_branch_deployments === true
243+
? 'allow'
244+
: 'not allow'
245+
} the deployments of pull requests that target a branch other than the default branch (aka stable branch)
239246
240247
---
241248

src/functions/inputs.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export function getInputs() {
5656
const commit_verification = core.getBooleanInput('commit_verification')
5757
const ignored_checks = stringToArray(core.getInput('ignored_checks'))
5858
const use_security_warnings = core.getBooleanInput('use_security_warnings')
59+
const allow_non_default_target_branch_deployments = core.getBooleanInput(
60+
'allow_non_default_target_branch_deployments'
61+
)
5962

6063
// validate inputs
6164
validateInput('update_branch', update_branch, ['disabled', 'warn', 'force'])
@@ -106,6 +109,8 @@ export function getInputs() {
106109
enforced_deployment_order: enforced_deployment_order,
107110
commit_verification: commit_verification,
108111
ignored_checks: ignored_checks,
109-
use_security_warnings: use_security_warnings
112+
use_security_warnings: use_security_warnings,
113+
allow_non_default_target_branch_deployments:
114+
allow_non_default_target_branch_deployments
110115
}
111116
}

0 commit comments

Comments
 (0)