branch-deploy/README.md

666 строки
43 KiB
Markdown
Исходник Обычный вид История

2022-04-30 21:19:04 +03:00
# Branch Deploy Action 🚀
2022-04-28 16:51:27 +03:00
2023-03-28 14:04:52 +03:00
[![CodeQL](https://github.com/github/branch-deploy/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/github/branch-deploy/actions/workflows/codeql-analysis.yml) [![test](https://github.com/github/branch-deploy/actions/workflows/test.yml/badge.svg)](https://github.com/github/branch-deploy/actions/workflows/test.yml) [![package-check](https://github.com/github/branch-deploy/actions/workflows/package-check.yml/badge.svg)](https://github.com/github/branch-deploy/actions/workflows/package-check.yml) [![lint](https://github.com/github/branch-deploy/actions/workflows/lint.yml/badge.svg)](https://github.com/github/branch-deploy/actions/workflows/lint.yml) [![actions-config-validation](https://github.com/github/branch-deploy/actions/workflows/actions-config-validation.yml/badge.svg)](https://github.com/github/branch-deploy/actions/workflows/actions-config-validation.yml) [![coverage](./badges/coverage.svg)](./badges/coverage.svg)
2022-05-03 23:51:26 +03:00
2022-04-30 21:19:04 +03:00
A GitHub Action to enable branch deployments using IssueOps!
2022-04-28 16:51:27 +03:00
2023-03-09 19:37:56 +03:00
![ship-it](docs/assets/ship-it.jpg)
2022-04-30 21:49:46 +03:00
This Action does the heavy lifting for you to enable branch deployments:
- 🔍 Detects when IssueOps commands are used on a pull request
- ✏️ Configurable - Choose your command syntax, environment, noop trigger, base branch, reaction, and more
- ✔️ Respects your branch protection settings configured for the repo
- 🗨️ Comments and reacts to your IssueOps commands
2022-05-03 22:42:16 +03:00
- 🚀 Triggers GitHub deployments for you with simple configuration
2022-06-17 00:58:52 +03:00
- 🔓 Deploy locks to prevent multiple deployments from clashing
2022-04-30 21:49:46 +03:00
2022-06-17 01:19:07 +03:00
## Available Commands 💬
- `.deploy` - Deploy a pull request
2023-07-18 15:14:05 +03:00
- `.noop` - Deploy a pull request in noop mode
2022-06-27 19:32:42 +03:00
- `.deploy to <environment>` - Deploy a pull request to a specific environment
2022-09-29 19:45:59 +03:00
- `.deploy <stable_branch>` - Trigger a rollback deploy to your stable branch (main, master, etc)
2023-03-12 01:54:33 +03:00
- `.lock` - Create a deployment lock for the default environment
- `.lock --reason <text>` - Create a deployment lock for the default environment with a custom reason
2022-06-17 01:19:07 +03:00
- `.lock --details` - View details about a deployment lock
2023-03-12 01:54:33 +03:00
- `.lock <environment>` - Create a deployment lock for a specific environment
- `.lock --global` - Create a global deployment lock
2022-06-17 01:19:07 +03:00
- `.unlock` - Remove a deployment lock
2023-03-12 01:54:33 +03:00
- `.unlock <environment>` - Remove a deployment lock for a specific environment
- `.unlock --global` - Remove a global deployment lock
- `.help` - Get help with IssueOps commands with this Action
2022-06-17 01:19:07 +03:00
> These commands are all fully customizable and are just an example using this Action's defaults
2023-03-12 01:54:33 +03:00
For the full command usage, check out the [usage document](docs/usage.md)
2023-02-01 04:32:54 +03:00
Alternate command syntax and shortcuts can be found at the bottom of this readme [here](#alternate-command-syntax)
2022-09-13 00:23:52 +03:00
2022-05-04 08:06:03 +03:00
## Demo 🎥
A video demo showing how IssueOps on a pull request works using this Action
2023-08-20 17:38:28 +03:00
<https://github.com/github/branch-deploy/assets/23362539/887cb1d3-e600-4d4c-ae0a-959b206e4513>
2022-05-04 08:06:03 +03:00
2022-04-30 21:49:46 +03:00
## Turbo Quickstart ⚡
2022-05-04 22:45:40 +03:00
A quick section to get you started with this Action
### Usage 📝
Basic usage assuming all defaults:
```yaml
- name: branch-deploy
id: branch-deploy
2022-06-17 20:48:32 +03:00
uses: github/branch-deploy@vX.X.X
2022-05-04 22:45:40 +03:00
```
Advanced usage with custom configuration:
```yaml
- name: branch-deploy
id: branch-deploy
2022-06-17 20:48:32 +03:00
uses: github/branch-deploy@vX.X.X
2022-05-04 22:45:40 +03:00
with:
trigger: ".deploy"
2023-07-28 12:40:33 +03:00
noop_trigger: ".noop"
2022-05-04 22:45:40 +03:00
reaction: "eyes"
environment: "production"
stable_branch: "main"
```
### Example 📚
Check out a super simple workflow example using this Action to quickly get up and running with branch deployments
2022-04-30 21:49:46 +03:00
```yaml
name: "branch deploy demo"
# The workflow to execute on is comments that are newly created
on:
issue_comment:
types: [created]
# Permissions needed for reacting and adding comments for IssueOps commands
permissions:
pull-requests: write
2022-05-03 00:02:54 +03:00
deployments: write
2022-06-17 20:16:59 +03:00
contents: write
checks: read
statuses: read
2022-04-30 21:49:46 +03:00
jobs:
demo:
if: ${{ github.event.issue.pull_request }} # only run on pull request comments
2022-04-30 21:49:46 +03:00
runs-on: ubuntu-latest
steps:
# Execute IssueOps branch deployment logic, hooray!
2022-05-03 20:55:58 +03:00
# This will be used to "gate" all future steps below and conditionally trigger steps/deployments
2022-06-17 20:48:32 +03:00
- uses: github/branch-deploy@vX.X.X
2022-05-03 20:55:58 +03:00
id: branch-deploy
2022-04-30 21:49:46 +03:00
with:
trigger: ".deploy"
2022-05-03 20:55:58 +03:00
# Run your deployment logic for your project here - examples seen below
2022-04-30 21:49:46 +03:00
2022-05-03 23:08:08 +03:00
# Checkout your projects repository based on the ref provided by the branch-deploy step
2023-10-06 07:50:24 +03:00
- uses: actions/checkout@v4
2022-05-03 23:08:08 +03:00
with:
ref: ${{ steps.branch-deploy.outputs.ref }}
2022-05-03 20:55:58 +03:00
# Do some fake "noop" deployment logic here
# conditionally run a noop deployment
- name: fake noop deploy
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop == 'true' }}
run: echo "I am doing a fake noop deploy"
# Do some fake "regular" deployment logic here
# conditionally run a regular deployment
- name: fake regular deploy
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop != 'true' }}
run: echo "I am doing a fake regular deploy"
2022-04-30 21:49:46 +03:00
```
2022-04-30 22:23:57 +03:00
> Keep reading to learn more about this Action! Even further details about how this Action works can be found below as well
2022-04-30 21:49:46 +03:00
2022-08-30 00:46:33 +03:00
You can check out further examples by checking out our [examples](docs/examples.md) documentation
2022-04-30 21:19:04 +03:00
## About 💡
2022-04-28 16:51:27 +03:00
2022-04-30 21:19:04 +03:00
Before we get into details, let's first define a few key terms below:
2022-04-28 16:51:27 +03:00
2022-04-30 21:19:04 +03:00
- **IssueOps** - Its like ChatOps but instead of using a chat bot, commands are invoked by commenting on a pull request (PRs are issues under the hood) - Example: commenting `.deploy` on a pull request
- **Branch Deployment** - A branch deploy is a deployment methodology that enables you to deploy a branch (or pull request) to a desired environment before merging to `main` or `master` - More on this below
- **PR** - Short for pull request
### IssueOps 🗨️
The best way to define IssueOps is to compare it to something similar, ChatOps. You may be familiar with the concept ChatOps already but in case you aren't here is a quick definition below:
> ChatOps is the process of interacting with a chat bot to execute commands directly in a chat platform. For example, with ChatOps you might do something like `.ping example.org` to check the status of a website
IssueOps adopts the same mindset but through a different medium. Rather than using a chat service to invoke the commands we use comments on a GitHub Issue or Pull Request. GitHub Actions is the runtime which executes our desired logic
### Branch Deployments 🌲
Branch deployments are a battle tested way of deploying your changes to a given environment for a variety of reasons. Branch deployments allow you to do the following:
- Deploy your changes to production **before** merging
- Deploy changes to a staging, QA, or non-production environment
#### Branch Deployment Core Concepts ⭐
> Note: The `main` branch is considered the base repository branch for all examples below
- The `main` branch is always considered to be a stable and deployable branch
- All changes are deployed to production before they are merged to the `main` branch
- To roll back a branch deployment, you deploy the `main` branch
- `noop` deployments should not make changes but rather report what they "would" have done
#### Why use branch deployments?
> To put the *merge -> deploy* model in the past!
What if your changes are bad and you broke production with the *merge -> deploy* model? Well now you have to revert your PR, get passing CI/builds, and then re-merge your changes to get back to a stable environment. With the **branch deploy** model, this is almost never the case. The `main` branch is considered to be always safe and stable
2022-04-28 16:51:27 +03:00
2022-04-30 22:46:24 +03:00
## How does it work? 📚
> This section will go into detail about how this Action works and hopefully inspire you on ways you can leverage it in your own projects
Let's walk through a GitHub Action workflow using this Action line by line:
```yaml
# The name of the workflow, it can be anything you wish
name: "branch deploy demo"
# The workflow to execute on is comments that are newly created
on:
issue_comment:
types: [created]
```
It is important to note that the workflow we want to run IssueOps on is `issue_comment` and `created`. This means we will not run under any other contexts for this workflow. You can edit this as you wish but it does change how this model ultimately works. For example, `issue_comment` workflows **only** use files found on `main` to run. If you do something like `on: pull_request` you could open yourself up to issues as a user could alter a file in a PR and exfil your secrets for example. Only using `issue_comment` is the suggested workflow type
```yaml
# Permissions needed for reacting and adding comments for IssueOps commands
permissions:
2022-06-17 20:16:59 +03:00
pull-requests: write # Required for commenting on PRs
deployments: write # Required for updating deployment statuses
contents: write # Required for reading/writing the lock file
checks: read # Required for checking if the CI checks have passed in order to deploy the PR
statuses: read # Required for checking if all commit statuses are "success" in order to deploy the PR
2022-04-30 22:46:24 +03:00
```
2024-03-24 03:20:14 +03:00
These are the minimum permissions you need to run this Action. If you need further assistance with permissions within GitHub Actions, please review the following [documentation](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token).
2022-04-30 22:46:24 +03:00
```yaml
jobs:
demo:
if: ${{ github.event.issue.pull_request }} # only run on pull request comments
2022-04-30 22:46:24 +03:00
runs-on: ubuntu-latest
steps:
# Checkout your projects repository
2023-10-06 07:50:24 +03:00
- uses: actions/checkout@v4
2022-04-30 22:46:24 +03:00
```
Sets up your `demo` job, uses an ubuntu runner, and checks out your repo - Just some standard setup for a general Action. We also add an `if:` statement here to only run this workflow on pull request comments to make it a little cleaner
> Note: The Action will check the context for us anyways but this can save us a bit of CI time by using the `if:` condition
2022-04-30 22:46:24 +03:00
```yaml
# Execute IssueOps branch deployment logic, hooray!
2022-06-17 20:48:32 +03:00
- uses: github/branch-deploy@vX.X.X
2022-05-03 20:55:58 +03:00
id: branch-deploy
2022-04-30 22:46:24 +03:00
with:
trigger: ".deploy"
```
2022-05-03 20:55:58 +03:00
> Note: It is important to set an `id:` for this job so we can reference its outputs in subsequent steps
2022-04-30 22:46:24 +03:00
The core of this Action takes place here. This block of code will trigger the branch deploy action to run. It will do the following:
1. Check the comment which invoked the workflow for the `trigger:` phrase (`.deploy`) defined here
1. If the trigger phrase is found, it will proceed with a deployment
1. It will start by reacting to your message to let you know it is running
1. The Action will post a comment with a link to the running Actions workflow for you to follow its progress
1. A deployment will be started and attached to your pull request - You'll get a nice little yellow rocket which tells you a deployment is in progress
1. Outputs will be exported by this job for later reference in other jobs as well
```yaml
2022-05-03 20:55:58 +03:00
# Do some fake "noop" deployment logic here
# conditionally run a noop deployment
- name: fake noop deploy
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop == 'true' }}
run: echo "I am doing a fake noop deploy"
# Do some fake "regular" deployment logic here
# conditionally run a regular deployment
- name: fake regular deploy
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop != 'true' }}
run: echo "I am doing a fake regular deploy"
2022-04-30 22:46:24 +03:00
```
2022-05-03 20:55:58 +03:00
As seen above, we have two steps. One for a noop deploy, and one for a regular deploy. For example, the noop deploy could trigger a `terraform plan` and the regular deploy could be a `terraform apply`. These steps are conditionally gated by two variables:
2022-04-30 22:46:24 +03:00
2022-05-03 20:55:58 +03:00
- `steps.branch-deploy.outputs.continue == 'true'` - The `continue` variable is only set to true when a deployment should continue
- `steps.branch-deploy.outputs.noop == 'true'` - The `noop` variable is only set to true when a noop deployment should be run
2022-04-30 22:46:24 +03:00
2023-07-18 15:14:05 +03:00
> Example: You comment `.noop` on a pull request. A noop deployment is detected so this action outputs the `noop` variable to `true`. You also have the correct permissions to execute the IssueOps command so the action also outputs the `continue` variable to `true`. This will allow the "fake noop deploy" step seen above to run and the "fake regular deploy" step will be skipped
2022-04-30 22:46:24 +03:00
2022-06-08 02:21:26 +03:00
## Inputs 📥
2022-05-03 00:14:23 +03:00
| Input | Required? | Default | Description |
| ----- | --------- | ------- | ----------- |
2023-03-12 15:34:35 +03:00
| `github_token` | `true` | `${{ github.token }}` | The GitHub token used to create an authenticated client - Provided for you by default! |
| `status` | `true` | `${{ job.status }}` | The status of the GitHub Actions - For use in the post run workflow - Provided for you by default! |
| `reaction` | `false` | `eyes` | If set, the specified emoji "reaction" is put on the comment to indicate that the trigger was detected. For example, "rocket" or "eyes" |
| `trigger` | `false` | `.deploy` | The string to look for in comments as an IssueOps trigger. Example: ".deploy" |
2023-07-17 18:42:26 +03:00
| `noop_trigger` | `false` | `.noop` | The string to look for in comments as an IssueOps noop trigger. Example: ".noop" - The usage would then be ".noop" |
2023-03-12 15:34:35 +03:00
| `lock_trigger` | `false` | `.lock` | The string to look for in comments as an IssueOps lock trigger. Used for locking branch deployments on a specific branch. Example: ".lock" |
| `unlock_trigger` | `false` | `.unlock` | The string to look for in comments as an IssueOps unlock trigger. Used for unlocking branch deployments. Example: ".unlock" |
| `help_trigger` | `false` | `.help` | The string to look for in comments as an IssueOps help trigger. Example: ".help" |
| `lock_info_alias` | `false` | `.wcid` | An alias or shortcut to get details about the current lock (if it exists) Example: ".info" - Hubbers will find the ".wcid" default helpful ("where can I deploy") |
2023-06-09 23:50:10 +03:00
| `permissions` | `true` | `write,maintain,admin` | The allowed GitHub permissions an actor can have to invoke IssueOps commands - Example: "write,maintain,admin" |
2023-06-01 20:41:59 +03:00
| `param_separator` | `false` | `\|` | The separator to use for parsing parameters in comments in deployment requests. Parameters will are saved as outputs and can be used in subsequent steps - See [Parameters](docs/parameters.md) for additional details |
2023-03-12 15:34:35 +03:00
| `global_lock_flag` | `false` | `--global` | The flag to pass into the lock command to lock all environments. Example: "--global" |
| `environment` | `false` | `production` | The name of the default environment to deploy to. Example: by default, if you type `.deploy`, it will assume "production" as the default environment |
| `environment_targets` | `false` | `production,development,staging` | Optional (or additional) target environments to select for use with deployments. Example, "production,development,staging". Example usage: `.deploy to development`, `.deploy to production`, `.deploy to staging` |
2023-03-16 21:06:35 +03:00
| `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"` |
2024-09-19 21:36:17 +03:00
| `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_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) |
2023-03-12 15:34:35 +03:00
| `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 |
2024-02-01 19:37:01 +03:00
| `outdated_mode` | `false` | `"strict"` | The mode to use for determining if a branch is up-to-date or not before allowing deployments. This option is closely related to the `update_branch` input option above. There are three available modes to choose from: `pr_base`, `default_branch`, or `strict`. The default is `strict` to help ensure that deployments are using the most up-to-date code. Please see the [documentation](docs/outdated_mode.md) for more details. |
2023-03-12 15:34:35 +03:00
| `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 |
| `skip_ci` | `false` | `""` | A comma separated list of environments that will not use passing CI as a requirement for deployment. Use this option to explicitly bypass branch protection settings for a certain environment in your repository. Default is an empty string `""` - Example: `"development,staging"` |
2024-02-18 00:31:04 +03:00
| `checks` | `false` | `"all"` | This input defines how the branch-deploy Action will handle the status of CI checks on your PR/branch before deployments can continue. `"all"` requires that all CI checks must pass in order for a deployment to be triggered. `"required"` only waits for required CI checks to be passing. View the [documentation](docs/checks.md) for more details. |
2023-03-12 15:34:35 +03:00
| `skip_reviews` | `false` | `""` | A comma separated list of environment that will not use reviews/approvals as a requirement for deployment. Use this options to explicitly bypass branch protection settings for a certain environment in your repository. Default is an empty string `""` - Example: `"development,staging"` |
| `allow_forks` | `false` | `"true"` | Allow branch deployments to run on repository forks. If you want to harden your workflows, this option can be set to false. Default is "true" |
| `admins` | `false` | `"false"` | A comma separated list of GitHub usernames or teams that should be considered admins by this Action. Admins can deploy pull requests without the need for branch protection approvals. Example: "monalisa,octocat,my-org/my-team" |
| `admins_pat` | `false` | `"false"` | A GitHub personal access token with "read:org" scopes. This is only needed if you are using the "admins" option with a GitHub org team. For example: "my-org/my-team" |
| `merge_deploy_mode` | `false` | `"false"` | Advanced configuration option for operations on merge commits. See the [merge commit docs](#merge-commit-workflow-strategy) below |
2023-06-02 01:41:54 +03:00
| `unlock_on_merge_mode` | `false` | `"false"` | Advanced configuration option for automatically releasing locks associated with a pull request when that pull request is merged. See the [unlock on merge mode](docs/unlock-on-merge.md) documentation for more details |
2023-03-12 15:34:35 +03:00
| `skip_completing` | `false` | `"false"` | If set to "true", skip the process of completing a deployment. You must manually create a deployment status after the deployment is complete. Default is "false" |
| `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"` |
2023-09-02 01:38:58 +03:00
| `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. |
2023-10-06 00:10:27 +03:00
| `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 |
2023-10-06 02:20:54 +03:00
| `disable_naked_commands` | `false` | `"false"` | If set to `"true"`, then naked commands will be disabled. Example: `.deploy` will not trigger a deployment. Instead, you must use `.deploy to production` to trigger a deployment. This is useful if you want to prevent accidental deployments from happening. View the [docs](docs/naked-commands.md) to learn more |
2024-06-28 21:26:37 +03:00
| `successful_deploy_labels` | `false` | `""` | A comma separated list of labels to add to the pull request when a deployment is successful. Example: `"deployed,success"` |
| `successful_noop_labels` | `false` | `""` | A comma separated list of labels to add to the pull request when a noop deployment is successful. Example: `"noop,success"` |
| `failed_deploy_labels` | `false` | `""` | A comma separated list of labels to add to the pull request when a deployment fails. Example: `"failed,deploy-failed"` |
| `failed_noop_labels` | `false` | `""` | A comma separated list of labels to add to the pull request when a noop deployment fails. Example: `"failed,noop-failed"` |
| `skip_successful_noop_labels_if_approved` | `false` | `"false"` | Whether or not the post run logic should skip adding successful noop labels if the pull request is approved. This can be useful if you add a label such as "ready-for-review" after a `.noop` completes but want to skip adding that label in situations where the pull request is already approved. |
| `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. |
2024-09-20 03:25:51 +03:00
| `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 |
2022-05-03 00:14:23 +03:00
2022-06-08 02:21:26 +03:00
## Outputs 📤
2022-05-03 00:14:23 +03:00
| Output | Description |
| ------ | ----------- |
| `continue` | The string "true" if the deployment should continue, otherwise empty - Use this to conditionally control if your deployment should proceed or not - ⭐ The main output you should watch for when determining if a deployment shall carry on |
| `fork` | The string "true" if the pull request is a fork, otherwise "false" |
2023-03-12 15:34:35 +03:00
| `triggered` | The string "true" if the trigger was found, otherwise the string "false" |
| `comment_body` | The comment body |
| `issue_number` | The issue number of the pull request (or issue) that was commented on |
2023-06-09 23:33:32 +03:00
| `actor` | The GitHub handle of the actor that invoked the IssueOps command |
2023-03-12 15:34:35 +03:00
| `environment` | The environment that has been selected for a deployment |
2023-06-05 04:08:56 +03:00
| `params` | The raw parameters that were passed into the deployment command (see param_separator) - Further [documentation](docs/parameters.md) |
2023-03-12 15:34:35 +03:00
| `noop` | The string "true" if the noop trigger was found, otherwise the string "false" - Use this to conditionally control whether your deployment runs as a noop or not |
| `sha` | The sha of the branch to be deployed |
| `default_branch_tree_sha` | The sha of the default branch tree (useful for subsequent workflow steps if they need to do commit comparisons) |
2023-03-12 15:34:35 +03:00
| `ref` | The ref (branch or sha) to use with deployment |
2023-09-01 20:49:07 +03:00
| `base_ref` | The base ref that the pull request is merging into |
2023-03-12 15:34:35 +03:00
| `comment_id` | The comment id which triggered this deployment |
| `deployment_id` | The ID of the deployment created by running this action |
2023-03-16 18:32:24 +03:00
| `environment_url` | The environment URL detected and used for the deployment (sourced from the environment_urls input) |
| `type` | The type of trigger that was detected (examples: deploy, lock, unlock, lock-info-alias, help) |
2023-03-12 15:34:35 +03:00
| `fork_ref` | The true ref of the fork |
| `fork_label` | The API label field returned for the fork |
| `fork_checkout` | The console command presented in the GitHub UI to checkout a given fork locally |
| `fork_full_name` | The full name of the fork in "org/repo" format |
| `initial_reaction_id` | The reaction id for the initial reaction on the trigger comment |
| `initial_comment_id` | The comment id for the "Deployment Triggered 🚀" comment created by the action |
2023-03-12 15:34:35 +03:00
| `actor_handle` | The handle of the user who triggered the action |
2023-03-13 02:20:34 +03:00
| `global_lock_claimed` | The string "true" if the global lock was claimed |
| `global_lock_released` | The string "true" if the global lock was released |
2023-06-02 01:41:54 +03:00
| `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 |
| `review_decision` | The pull request review status. Can be one of a few values - examples: `APPROVED`, `skip_reviews`, `REVIEW_REQUIRED`, `null` |
| `is_outdated` | The string `"true"` if the branch is out-of-date, otherwise `"false"` |
| `merge_state_status` | The status of the merge state. Can be one of a few values - examples: `"DIRTY"`, `"DRAFT"`, `"CLEAN"`, etc |
| `commit_status` | The status of the commit. Can be one of a few values - examples: `"SUCCESS"`, `null`, `"skip_ci"`, `"PENDING"`, `"FAILURE"` etc |
| `approved_reviews_count` | The number of approved reviews on the pull request |
2024-09-20 03:25:51 +03:00
| `needs_to_be_deployed` | A comma separated list of environments that need successful and active deployments before the current environment (that was requested) can be deployed. This output is tied to the `enforced_deployment_order` input option - See the [enforced deployment order docs](./docs/enforced-deployment-order.md) for more details |
2022-05-03 00:14:23 +03:00
2022-05-03 22:35:05 +03:00
## Custom Deployment Messages ✏️
For documentation on how to customize the deployment messages, see the [custom deployment messages docs](./docs/custom-deployment-messages.md).
2022-05-03 22:35:05 +03:00
2022-05-04 20:52:38 +03:00
## About Environments 🌎
> If you are using environment rather than repo secrets, this section will be of interest to you
For those familiar with GitHub Actions, you have probably used environments before to store secrets and trigger deployments. The syntax for doing so is very simple and usually looks like this:
```yaml
jobs:
deploy:
environment: production # right here we use an environment
runs-on: ubuntu-latest
steps:
- name: deployment
run: terraform apply -auto-approve
```
However, this has a few limitations:
- When workflows finish, so does the deployment to that environment - This means that the little green rocket doesn't "stick" to your pull request
- It is tricky to tune in environment protection rules with a single environment when using IssueOps + branch-deployments
2023-02-17 21:52:51 +03:00
To get around these limitations with this branch-deploy action and IssueOps, we can use two different environments. One to store our environnement secrets and another to use in our branch deployments.
2022-05-04 20:52:38 +03:00
> Yes this isn't the most elegant solution, but it works and is very easy to accomplish
Here is a proper example for using two environments with this action:
```yaml
jobs:
deploy:
if: ${{ github.event.issue.pull_request }} # only run on pull request comments
2022-05-04 23:06:26 +03:00
environment: production-secrets # custom environment for storing secrets
2022-05-04 20:52:38 +03:00
runs-on: ubuntu-latest
steps:
2022-06-17 20:48:32 +03:00
- uses: github/branch-deploy@vX.X.X
2022-05-04 20:52:38 +03:00
id: branch-deploy
with:
trigger: ".deploy"
environment: production # the environment for the actual deployment
# Your deployment steps go here...
```
This allows you to achieve the following:
- Fine grained control over your environment secrets in the `production-secrets` environment
- A "sticky" green rocket to your PR that doesn't disappear when the workflow finishes
2022-05-04 20:53:40 +03:00
- Access to all the environment secrets stored in the `production-secrets` environment
2022-05-04 20:52:38 +03:00
2022-06-27 19:37:11 +03:00
### Environment Targets
2022-06-27 19:32:42 +03:00
With this Action, you can also choose the environment you wish to deploy to. This is useful if you have multiple environments and want to deploy to a specific environment.
This can be achieved with the `environment_targets` input
2022-06-27 19:37:11 +03:00
With this option, you can specify a comma separated list of environments that you can deploy to besides just the default with `.deploy`
2022-06-27 19:32:42 +03:00
2023-03-16 19:39:39 +03:00
The defaults that are used are: [`production,development,staging`](https://github.com/github/branch-deploy/blob/e3cbb8f0137bfd7933492f12616c0cf91c7cf051/action.yml#L23). However, you can configure this to be whatever you like!
2022-06-27 19:32:42 +03:00
To use a deployment with a specific environment, you would invoke your commands like so:
- `.deploy production`
- `.deploy to production`
- `.deploy to <environment>`
This also works with noop commands as well
2023-07-18 15:14:05 +03:00
- `.noop production`
- `.noop to production`
- `.noop to <environment>`
2022-06-27 19:32:42 +03:00
YAML input example:
```yaml
- uses: github/branch-deploy@vX.X.X
id: branch-deploy
with:
trigger: ".deploy"
environment: production # the default environment
environment_targets: "production,development,staging" # the environments that you can deploy to with explicit commands
```
2023-03-12 01:54:33 +03:00
You can view additional details about the `environment_targets` input option in the [`action.yml`](action.yml) section above
2023-03-16 19:43:14 +03:00
### Environment URLs
2023-06-05 04:08:56 +03:00
Environment URLs can be configured and mapped to matching `environment_targets` using the `environment_urls` input.
2023-03-16 19:43:14 +03:00
This input option is a mapping of environment names to URLs and the environment names **must** match the [`environment_targets`](https://github.com/github/branch-deploy#environment-targets) input option. This option is a comma separated list with pipes (`|`) separating the environment from the URL.
2023-03-16 21:06:35 +03:00
Note: `disabled` is a special keyword to disable an environment url if you enable this option but not all environments have a url.
2023-03-16 19:43:14 +03:00
Format: `"<environment1>|<url1>,<environment2>|<url2>,etc"`
2023-03-16 21:06:35 +03:00
Example: `"production|https://myapp.com,development|https://dev.myapp.com,staging|disabled"`
2023-03-16 19:43:14 +03:00
> This option is especially useful when your deployment targets are services with a URL (website, API, etc)
By enabling this option, you will get a "clickable" link on success (non-noop) deployment messages on pull requests. You will also be able to click the "View deployment" button in your repository's deployments page and be taken to the URL of the environment you deployed to.
2023-06-05 04:08:56 +03:00
If you wish to disable the "clickable" link on the successful deployment message, you can set the `environment_url_in_comment` input to `"false"`.
2023-03-16 21:06:35 +03:00
2022-09-29 19:45:59 +03:00
## Rollbacks 🔄
This Action supports rollback deployments out of the box. This is useful when you run a branch deployment (`.deploy`) and something goes wrong and you need to rollback to a previous known working state.
This can be achieved by using the `.deploy <stable_branch>` command
> See the [inputs](#inputs-) section above for more information on how to configure the stable branch
The `<stable_branch>` can be any branch you like but it is highly recommended that you use a branch that is protected and only has stable code in it. An example would be using `main` or `master` as your stable branch and enforcing strict branch protection rules on it to ensure that only stable code is merged into it
2022-05-04 20:52:38 +03:00
## Security 🔒
The IssueOps + branch-deploy model is significantly more secure than a traditional "deploy on merge" or "run on commit" model. Let's reference the workflow trigger that the branch-deploy model uses:
```yaml
on:
issue_comment:
types: [created]
```
Unlike the `on: pull_request` trigger, the `on: issue_comment` trigger only uses Actions workflow files from the default branch in GitHub. This means that a bad actor cannot open a PR with a malicious workflow edit and dump secrets, trigger bad deployments, or cause other issues. This means that any changes to the workflow files can be protected with branch protection rules to ensure only verified changes make it into your default branch.
To further harden your workflow files, it is strongly suggested to include the base permissions that this Action needs to run:
```yaml
permissions:
pull-requests: write
deployments: write
contents: write
checks: read
statuses: read
2022-05-04 20:52:38 +03:00
```
Permissions Explained:
- `pull-requests`: `write` - Required to add comments to pull requests with deployment results
- `deployments`: `write` - Required to update repository deployment statuses
- `contents`: `write` - Write access is required for this Action to create "lock" branches for deployments
- `checks`: `read` - Only read access is needed for this Action to get the status of other CI checks
- `statuses`: `read` - Only read access is needed for this Action to get the commit statuses of commits in the PR
2022-06-17 00:58:52 +03:00
It should also be noted that this Action has built in functions to check the permissions of a user who invokes a IssueOps command. If the user does not have `write` or greater permissions to the repository, their command will be rejected
2022-06-27 08:45:41 +03:00
### Admins 👩‍🔬
This Action supports a configurable input called `admins` which can be used to specify a list of individual GitHub users or teams that should have elevated permissions when using this Action
2023-02-17 21:52:51 +03:00
The `admins` input option takes a comma separated list of GitHub handles or GitHub org teams which can bypass branch protection rules related to approvals for deployments. For example, if you give the option `admins: monalisa`, the `monalisa` user will be able to deploy without needing approval on their pull requests. CI checks will still need to pass however.
2022-06-27 08:45:41 +03:00
It should be noted that if you do not have pull request approvals enabled in your branch protection rules, then this option will not make a difference either way
Here is a simple example using only handles below (the monalisa and octocat users will be treated as admins):
```yaml
- uses: github/branch-deploy@vX.X.X
id: branch-deploy
with:
admins: monalisa,octocat
```
Here is an example using a mix of GitHub handles and a GitHub org team below:
```yaml
- uses: github/branch-deploy@vX.X.X
id: branch-deploy
with:
admins: monalisa,octocat,octo-awesome-org/octo-awesome-team
admins_pat: ${{ secrets.BRANCH_DEPLOY_ADMINS_PAT }}
```
In this case, all users (and future users) in the `octo-awesome-org/octo-awesome-team` team will be treated as admins in addition to the monalisa and octocat users
It should be noted if you choose to use GitHub org teams for admin definitions, you **will** need a [GitHub Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) with the `read:org` scope. This is because the Action will need to make API calls on behalf of an authenticated user in the org to retrieve team memberships. If you choose to only use GitHub handles for admin definitions, then the `admins_pat` input is not required
> Note: You can read more about the `admin` option under the **inputs** section in this readme
2022-05-09 21:23:25 +03:00
## Actions Stability 🔧
In order to ensure your usage of this action is stable, it is highly recommended that you use either pin your action to a SHA or use a specific release tag
### Actions Tag Pinning
You can easily select the exact version you want on the GitHub Actions marketplace seen in the screenshot below:
![Screenshot from 2022-05-09 12-12-06](https://user-images.githubusercontent.com/23362539/167471509-71ca2cf9-7b8f-4709-acee-67a679869fa6.png)
### Actions SHA Pinning
You can also pin to an exact commit SHA as well using a third party tool such as [mheap/pin-github-action](https://github.com/mheap/pin-github-action)
2023-02-17 21:52:51 +03:00
> GitHub Actions security hardening and stability docs available here: [docs](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-third-party-actions)
2022-05-09 21:23:25 +03:00
2022-06-17 01:15:53 +03:00
## Deployment Locks and Actions Concurrency 🔓
2022-05-09 21:23:25 +03:00
For full details about how this Action handles deployment locks and concurrency, please see the [deployment locks and concurrency](docs/locks.md) documentation
2023-03-12 01:54:33 +03:00
> This linked document also contains usage, setup details, and examples
2022-11-01 21:00:42 +03:00
2023-02-01 04:32:54 +03:00
## Merge Commit Workflow Strategy
2023-02-01 04:30:57 +03:00
Checkout the [merge commit workflow strategy](docs/merge-commit-strategy.md) for more information on how to use this Action with a merge commit workflow strategy.
2023-02-01 04:30:57 +03:00
2023-02-27 14:16:23 +03:00
## Manual Deployment Control
If you need more fine tuned control over when the deployment status is set to `success` you can use the `skip_completing` option to prevent this Action from setting your deployment status to `success` after it completes.
When using this option, you will need to manually set your deployment status depending on if you deployment succeeds or fails.
An example workflow using this option can be found [here](https://github.com/github/branch-deploy/blob/main/docs/examples.md#multiple-jobs)
## Saving on Actions Compute
If you are looking to save on Actions compute time, here is a helpful tip! You can use the `if` conditional to only run this Action when a specific comment is made on a pull request. This can help you save on Actions compute time by only running this Action when it should truly be invoked.
Here is an example workflow demonstrating the `if` conditional:
```yaml
name: "branch deploy demo"
# The workflow to execute on is comments that are newly created
on:
issue_comment:
types: [created]
# Permissions needed for reacting and adding comments for IssueOps commands
permissions:
pull-requests: write
deployments: write
contents: write
checks: read
statuses: read
jobs:
demo:
if: # only run on pull request comments and very specific comment body string as defined in our branch-deploy settings - this will save on Actions compute time
${{ github.event.issue.pull_request &&
(startsWith(github.event.comment.body, '.deploy') ||
startsWith(github.event.comment.body, '.noop') ||
startsWith(github.event.comment.body, '.lock') ||
startsWith(github.event.comment.body, '.help') ||
startsWith(github.event.comment.body, '.wcid') ||
startsWith(github.event.comment.body, '.unlock')) }}
runs-on: ubuntu-latest
steps:
- uses: github/branch-deploy@vX.X.X # replace with the latest version
id: branch-deploy
with:
trigger: ".deploy"
noop_trigger: ".noop"
lock_trigger: ".lock"
unlock_trigger: ".unlock"
help_trigger: ".help"
lock_info_alias: ".wcid"
# these are all the command definitions that we want to listen for (above) ^
# Run your deployment logic for your project below...
```
2022-08-29 23:39:53 +03:00
## Examples
This section contains real world examples of how this Action can be used
2022-08-30 00:38:36 +03:00
- [Terraform](docs/examples.md#terraform)
- [Heroku](docs/examples.md#heroku)
- [Railway](docs/examples.md#railway)
- [SSH](docs/examples.md#ssh)
- [Cloudflare Pages](docs/examples.md#cloudflare-pages)
- [Cloudflare Workers](docs/examples.md#cloudflare-workers)
2023-03-20 14:29:44 +03:00
- [Hugo](docs/examples.md#multiple-jobs-with-gitHub-pages-and-hugo)
- [Astro](docs/examples.md#multiple-jobs-with-gitHub-pages-and-astro)
- [Multiple Jobs](docs/examples.md#multiple-jobs) (advanced)
2022-08-29 23:39:53 +03:00
> Checkout the [examples document](docs/examples.md) for more examples
Remember, these are just examples and you can quite literally configure this Action for **any** deployment target you want!
### Live Examples 📸
2022-06-17 01:22:30 +03:00
What to see live examples of this Action in use?
Check out some of the links below to see how others are using this Action in their projects:
- [github/entitlements-config](https://github.com/github/entitlements-config/blob/076a1f0f9e8cc1f5acb8a0b8e133b0a1300c8191/.github/workflows/branch-deploy.yml)
- [the-hideout/cloudflare](https://github.com/the-hideout/cloudflare/blob/f3b189b54f278d7e7844e5cc2fcdbb6f5afd3467/.github/workflows/branch-deploy.yml)
- [the-hideout/tarkov-api](https://github.com/the-hideout/tarkov-api/blob/be645d7750a0e440794229ce56aefeb4648b8892/.github/workflows/branch-deploy.yml)
- [the-hideout/stash](https://github.com/the-hideout/stash/blob/4aabf7565fda933f8e40ae9c60cde9f03e549b3b/.github/workflows/branch-deploy.yml)
- [GrantBirki/blog](https://github.com/GrantBirki/blog/blob/25a51aff28c066e378844992c20afc6c58131e26/.github/workflows/branch-deploy.yml)
2022-06-17 01:22:30 +03:00
2022-08-29 23:39:53 +03:00
> Are you using this Action in a cool new way? Open a pull request to this repo to have your workflow added to the list above!
2022-06-09 23:39:29 +03:00
## Suggestions 🌟
This section will cover a few suggestions that will help you when using this Action
1. Suggest Updating Pull Request Branches - You should absolutely use this option when using the `branch-deploy` Action. This option can be found in your repository's `/settings` page
![branch-setting](https://user-images.githubusercontent.com/23362539/172939811-a8816db8-8e7c-404a-b12a-11ec5bc6e93d.png)
2. Enable Branch Protection Settings - It is always a good idea to enable branch protection settings for your repo, especially when using this Action
2023-02-01 04:32:54 +03:00
## Alternate Command Syntax
2022-07-09 21:07:44 +03:00
Here are a few alternate ways you can invoke commands:
2023-07-18 15:14:05 +03:00
- `.noop staging` - Invoke a "noop" deployment to the staging environment
2022-12-20 18:37:49 +03:00
- `.deploy development` - Invoke a deployment to the development environment (notice how you can omit the "to" keyword)
- `.deploy to development` - Invoke a deployment to the development environment (with the "to" keyword)
2022-07-09 21:07:44 +03:00
- `.deploy` - Uses the default environment (usually "production")
2023-03-12 01:54:33 +03:00
- `.wcid` - Alias for `.lock --details` meaning "where can I deploy?"
Check out the [usage guide](docs/usage.md) for more information
2022-07-09 21:07:44 +03:00
2022-05-05 00:52:30 +03:00
---
## Contributing 💻
All contributions are welcome from all!
Check out the [contributing guide](CONTRIBUTING.md) to learn more
2023-11-02 22:28:45 +03:00
If you are a maintainer of this Action, please see the [maintainer guide](docs/maintainer-guide.md) for more information