Skip to content

Commit

Permalink
Merge pull request #209 from github/production-environments
Browse files Browse the repository at this point in the history
Support Multiple Production Environments
  • Loading branch information
GrantBirki authored Sep 15, 2023
2 parents bfd31c1 + b3290f0 commit 82c238c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
| `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 |
| `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"` |
| `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 |
| `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. |
| `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) |
| `stable_branch` | `false` | `main` | The name of a stable branch to deploy to (rollbacks). Example: "main" |
| `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 |
| `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 |
Expand Down
6 changes: 3 additions & 3 deletions __tests__/functions/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const defaultInputs = {
stable_branch: 'main',
noop_trigger: '.noop',
lock_trigger: '.lock',
production_environment: 'production',
production_environments: 'production',
environment_targets: 'production,staging,development',
unlock_trigger: '.unlock',
help_trigger: '.help',
Expand Down Expand Up @@ -62,7 +62,7 @@ test('successfully calls help with non-defaults', async () => {
stable_branch: 'main',
noop_trigger: '.noop',
lock_trigger: '.lock',
production_environment: 'production',
production_environments: 'production',
environment_targets: 'production,staging,development',
unlock_trigger: '.unlock',
help_trigger: '.help',
Expand Down Expand Up @@ -93,7 +93,7 @@ test('successfully calls help with non-defaults', async () => {
stable_branch: 'main',
noop_trigger: '.noop',
lock_trigger: '.lock',
production_environment: 'production',
production_environments: 'production,production-eu,production-ap',
environment_targets: 'production,staging,development',
unlock_trigger: '.unlock',
help_trigger: '.help',
Expand Down
2 changes: 1 addition & 1 deletion __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ beforeEach(() => {
process.env.INPUT_ENVIRONMENT_TARGETS = 'production,development,staging'
process.env.INPUT_ENVIRONMENT_URLS = ''
process.env.INPUT_PARAM_SEPARATOR = '|'
process.env.INPUT_PRODUCTION_ENVIRONMENT = 'production'
process.env.INPUT_PRODUCTION_ENVIRONMENTS = 'production'
process.env.INPUT_STABLE_BRANCH = 'main'
process.env.INPUT_NOOP_TRIGGER = '.noop'
process.env.INPUT_LOCK_TRIGGER = '.lock'
Expand Down
2 changes: 1 addition & 1 deletion __tests__/schemas/action.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ inputs:
default:
type: string
required: true
production_environment:
production_environments:
description:
type: string
required: true
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ inputs:
description: 'If the environment_url detected in the deployment should be appended to the successful deployment comment or not. Examples: "true" or "false"'
required: false
default: "true"
production_environment:
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.'
production_environments:
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'
required: false
default: "production"
reaction:
Expand Down
22 changes: 11 additions & 11 deletions 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.

4 changes: 2 additions & 2 deletions src/functions/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export async function help(octokit, context, reactionId, inputs) {
- \`${inputs.environment}\` - The default environment for this Action
- \`${
inputs.production_environment
}\` - The environment that is considered "production"
inputs.production_environments
}\` - The environments that are considered "production"
- \`${
inputs.environment_targets
}\` - The list of environments that can be targeted for deployment
Expand Down
18 changes: 9 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export async function run() {
const stable_branch = core.getInput('stable_branch')
const noop_trigger = core.getInput('noop_trigger')
const lock_trigger = core.getInput('lock_trigger')
const production_environment = core.getInput('production_environment')
const production_environments = await stringToArray(
core.getInput('production_environments')
)
const environment_targets = core.getInput('environment_targets')
const draft_permitted_targets = core.getInput('draft_permitted_targets')
const unlock_trigger = core.getInput('unlock_trigger')
Expand Down Expand Up @@ -169,7 +171,7 @@ export async function run() {
stable_branch: stable_branch,
noop_trigger: noop_trigger,
lock_trigger: lock_trigger,
production_environment: production_environment,
production_environments: production_environments,
environment_targets: environment_targets,
unlock_trigger: unlock_trigger,
global_lock_flag: global_lock_flag,
Expand Down Expand Up @@ -553,12 +555,10 @@ export async function run() {
})
}

// Check if the environment is a production_environment
var productionEnvironment = false
if (environment === production_environment.trim()) {
productionEnvironment = true
}
core.debug(`production_environment: ${productionEnvironment}`)
// Check if the environment is a production environment
const isProductionEnvironment =
production_environments.includes(environment)
core.debug(`production_environment: ${isProductionEnvironment}`)

// if update_branch is set to 'disabled', then set auto_merge to false, otherwise set it to true
const auto_merge = update_branch === 'disabled' ? false : true
Expand All @@ -573,7 +573,7 @@ export async function run() {
environment: environment,
// description: "",
// :description note: Short description of the deployment.
production_environment: productionEnvironment,
production_environment: isProductionEnvironment,
// :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.
payload: {
type: 'branch-deploy'
Expand Down

0 comments on commit 82c238c

Please sign in to comment.