Skip to content

Commit 82c238c

Browse files
authored
Merge pull request #209 from github/production-environments
Support Multiple Production Environments
2 parents bfd31c1 + b3290f0 commit 82c238c

File tree

9 files changed

+31
-31
lines changed

9 files changed

+31
-31
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
268268
| `environment_urls` | `false` | `""` | Optional target environment URLs to use with deployments. This input option is a mapping of environment names to URLs and the environment names **must** match the `environment_targets` input option. This option is a comma separated list with pipes (`\|`) separating the environment from the URL. Note: `disabled` is a special keyword to disable an environment url if you enable this option. Format: `"<environment1>\|<url1>,<environment2>\|<url2>,etc"` Example: `"production\|https://myapp.com,development\|https://dev.myapp.com,staging\|disabled"` - See the [environment urls](#environment-urls) section for more details |
269269
| `draft_permitted_targets` | `false` | `""` | Optional environments which can allow "draft" pull requests to be deployed. By default, this input option is empty and no environments allow deployments sourced from a pull request in a "draft" state. Examples: `"development,staging"` |
270270
| `environment_url_in_comment` | `false` | `"true` | If the `environment_url` detected in the deployment should be appended to the successful deployment comment or not. Examples: `"true"` or `"false"` - See the [environment urls](#environment-urls) section for more details |
271-
| `production_environment` | `false` | `production` | The name of the production environment. Example: "production". By default, GitHub will set the "production_environment" to "true" if the environment name is "production". This option allows you to override that behavior so you can use "prod", "prd", "main", etc. as your production environment name. |
271+
| `production_environments` | `false` | `production` | A comma separated list of environments that should be treated as "production". GitHub defines "production" as an environment that end users or systems interact with. Example: "production,production-eu". By default, GitHub will set the "production_environment" to "true" if the environment name is "production". This option allows you to override that behavior so you can use "prod", "prd", "main", "production-eu", etc. as your production environment name. ref: [#208](https://github.com/github/branch-deploy/issues/208) |
272272
| `stable_branch` | `false` | `main` | The name of a stable branch to deploy to (rollbacks). Example: "main" |
273273
| `update_branch` | `false` | `warn` | Determine how you want this Action to handle "out-of-date" branches. Available options: "disabled", "warn", "force". "disabled" means that the Action will not care if a branch is out-of-date. "warn" means that the Action will warn the user that a branch is out-of-date and exit without deploying. "force" means that the Action will force update the branch. Note: The "force" option is not recommended due to Actions not being able to re-run CI on commits originating from Actions itself |
274274
| `required_contexts` | `false` | `"false"` | Manually enforce commit status checks before a deployment can continue. Only use this option if you wish to manually override the settings you have configured for your branch protection settings for your GitHub repository. Default is "false" - Example value: "context1,context2,context3" - In most cases you will not need to touch this option |

__tests__/functions/help.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const defaultInputs = {
3030
stable_branch: 'main',
3131
noop_trigger: '.noop',
3232
lock_trigger: '.lock',
33-
production_environment: 'production',
33+
production_environments: 'production',
3434
environment_targets: 'production,staging,development',
3535
unlock_trigger: '.unlock',
3636
help_trigger: '.help',
@@ -62,7 +62,7 @@ test('successfully calls help with non-defaults', async () => {
6262
stable_branch: 'main',
6363
noop_trigger: '.noop',
6464
lock_trigger: '.lock',
65-
production_environment: 'production',
65+
production_environments: 'production',
6666
environment_targets: 'production,staging,development',
6767
unlock_trigger: '.unlock',
6868
help_trigger: '.help',
@@ -93,7 +93,7 @@ test('successfully calls help with non-defaults', async () => {
9393
stable_branch: 'main',
9494
noop_trigger: '.noop',
9595
lock_trigger: '.lock',
96-
production_environment: 'production',
96+
production_environments: 'production,production-eu,production-ap',
9797
environment_targets: 'production,staging,development',
9898
unlock_trigger: '.unlock',
9999
help_trigger: '.help',

__tests__/main.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ beforeEach(() => {
3939
process.env.INPUT_ENVIRONMENT_TARGETS = 'production,development,staging'
4040
process.env.INPUT_ENVIRONMENT_URLS = ''
4141
process.env.INPUT_PARAM_SEPARATOR = '|'
42-
process.env.INPUT_PRODUCTION_ENVIRONMENT = 'production'
42+
process.env.INPUT_PRODUCTION_ENVIRONMENTS = 'production'
4343
process.env.INPUT_STABLE_BRANCH = 'main'
4444
process.env.INPUT_NOOP_TRIGGER = '.noop'
4545
process.env.INPUT_LOCK_TRIGGER = '.lock'

__tests__/schemas/action.schema.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ inputs:
100100
default:
101101
type: string
102102
required: true
103-
production_environment:
103+
production_environments:
104104
description:
105105
type: string
106106
required: true

action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ inputs:
3333
description: 'If the environment_url detected in the deployment should be appended to the successful deployment comment or not. Examples: "true" or "false"'
3434
required: false
3535
default: "true"
36-
production_environment:
37-
description: 'The name of the production environment. Example: "production". By default, GitHub will set the "production_environment" to "true" if the environment name is "production". This option allows you to override that behavior so you can use "prod", "prd", "main", etc. as your production environment name.'
36+
production_environments:
37+
description: 'A comma separated list of environments that should be treated as "production". GitHub defines "production" as an environment that end users or systems interact with. Example: "production,production-eu". By default, GitHub will set the "production_environment" to "true" if the environment name is "production". This option allows you to override that behavior so you can use "prod", "prd", "main", "production-eu", etc. as your production environment name. ref: https://github.com/github/branch-deploy/issues/208'
3838
required: false
3939
default: "production"
4040
reaction:

dist/index.js

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/help.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export async function help(octokit, context, reactionId, inputs) {
122122
123123
- \`${inputs.environment}\` - The default environment for this Action
124124
- \`${
125-
inputs.production_environment
126-
}\` - The environment that is considered "production"
125+
inputs.production_environments
126+
}\` - The environments that are considered "production"
127127
- \`${
128128
inputs.environment_targets
129129
}\` - The list of environments that can be targeted for deployment

src/main.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export async function run() {
3535
const stable_branch = core.getInput('stable_branch')
3636
const noop_trigger = core.getInput('noop_trigger')
3737
const lock_trigger = core.getInput('lock_trigger')
38-
const production_environment = core.getInput('production_environment')
38+
const production_environments = await stringToArray(
39+
core.getInput('production_environments')
40+
)
3941
const environment_targets = core.getInput('environment_targets')
4042
const draft_permitted_targets = core.getInput('draft_permitted_targets')
4143
const unlock_trigger = core.getInput('unlock_trigger')
@@ -169,7 +171,7 @@ export async function run() {
169171
stable_branch: stable_branch,
170172
noop_trigger: noop_trigger,
171173
lock_trigger: lock_trigger,
172-
production_environment: production_environment,
174+
production_environments: production_environments,
173175
environment_targets: environment_targets,
174176
unlock_trigger: unlock_trigger,
175177
global_lock_flag: global_lock_flag,
@@ -553,12 +555,10 @@ export async function run() {
553555
})
554556
}
555557

556-
// Check if the environment is a production_environment
557-
var productionEnvironment = false
558-
if (environment === production_environment.trim()) {
559-
productionEnvironment = true
560-
}
561-
core.debug(`production_environment: ${productionEnvironment}`)
558+
// Check if the environment is a production environment
559+
const isProductionEnvironment =
560+
production_environments.includes(environment)
561+
core.debug(`production_environment: ${isProductionEnvironment}`)
562562

563563
// if update_branch is set to 'disabled', then set auto_merge to false, otherwise set it to true
564564
const auto_merge = update_branch === 'disabled' ? false : true
@@ -573,7 +573,7 @@ export async function run() {
573573
environment: environment,
574574
// description: "",
575575
// :description note: Short description of the deployment.
576-
production_environment: productionEnvironment,
576+
production_environment: isProductionEnvironment,
577577
// :production_environment note: specifies if the given environment is one that end-users directly interact with. Default: true when environment is production and false otherwise.
578578
payload: {
579579
type: 'branch-deploy'

0 commit comments

Comments
 (0)