A GitHub Action to enable branch deployments using IssueOps!
This Action does the heavy lifting for you to enable branch deployments:
.deploy
- Deploy a pull request.noop
- Deploy a pull request in noop mode.deploy to <environment>
- Deploy a pull request to a specific environment.deploy <stable_branch>
- Trigger a rollback deploy to your stable branch (main, master, etc).lock
- Create a deployment lock for the default environment.lock --reason <text>
- Create a deployment lock for the default environment with a custom reason.lock --details
- View details about a deployment lock.lock <environment>
- Create a deployment lock for a specific environment.lock --global
- Create a global deployment lock.unlock
- Remove a deployment lock.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 ActionThese commands are all fully customizable and are just an example using this Action's defaults
For the full command usage, check out the usage document
Alternate command syntax and shortcuts can be found at the bottom of this readme here
A video demo showing how IssueOps on a pull request works using this Action
https://github.com/github/branch-deploy/assets/23362539/887cb1d3-e600-4d4c-ae0a-959b206e4513
A quick section to get you started with this Action
Basic usage assuming all defaults:
- name: branch-deploy id: branch-deploy uses: github/branch-deploy@vX.X.X
Advanced usage with custom configuration:
- name: branch-deploy id: branch-deploy uses: github/branch-deploy@vX.X.X with: trigger: ".deploy" noop_trigger: ".noop" reaction: "eyes" environment: "production" stable_branch: "main"
Check out a super simple workflow example using this Action to quickly get up and running with branch deployments
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: ${{ github.event.issue.pull_request }} # only run on pull request comments runs-on: ubuntu-latest steps: # Execute IssueOps branch deployment logic, hooray! # This will be used to "gate" all future steps below and conditionally trigger steps/deployments - uses: github/branch-deploy@vX.X.X id: branch-deploy with: trigger: ".deploy" # Run your deployment logic for your project here - examples seen below # Checkout your projects repository based on the ref provided by the branch-deploy step - uses: actions/checkout@v4 with: ref: ${{ steps.branch-deploy.outputs.ref }} # 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"
Keep reading to learn more about this Action! Even further details about how this Action works can be found below as well
You can check out further examples by checking out our examples documentation
Before we get into details, let's first define a few key terms below:
.deploy
on a pull requestmain
or master
- More on this belowThe 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 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:
Note: The
main
branch is considered the base repository branch for all examples below
main
branch is always considered to be a stable and deployable branchmain
branchmain
branchnoop
deployments should not make changes but rather report what they "would" have doneTo 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
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:
# 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
# Permissions needed for reacting and adding comments for IssueOps commands permissions: 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
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.
jobs: demo: if: ${{ github.event.issue.pull_request }} # only run on pull request comments runs-on: ubuntu-latest steps: # Checkout your projects repository - uses: actions/checkout@v4
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
# Execute IssueOps branch deployment logic, hooray! - uses: github/branch-deploy@vX.X.X id: branch-deploy with: trigger: ".deploy"
Note: It is important to set an
id:
for this job so we can reference its outputs in subsequent steps
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:
trigger:
phrase (.deploy
) defined here# 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"
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:
steps.branch-deploy.outputs.continue == 'true'
- The continue
variable is only set to true when a deployment should continuesteps.branch-deploy.outputs.noop == 'true'
- The noop
variable is only set to true when a noop deployment should be runExample: You comment
.noop
on a pull request. A noop deployment is detected so this action outputs thenoop
variable totrue
. You also have the correct permissions to execute the IssueOps command so the action also outputs thecontinue
variable totrue
. This will allow the "fake noop deploy" step seen above to run and the "fake regular deploy" step will be skipped
Input | Required? | Default | Description |
---|---|---|---|
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" |
noop_trigger | false | .noop | The string to look for in comments as an IssueOps noop trigger. Example: ".noop" - The usage would then be ".noop" |
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") |
permissions | true | write,maintain,admin | The allowed GitHub permissions an actor can have to invoke IssueOps commands - Example: "write,maintain,admin" |
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 for additional details |
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 |
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 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 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 |
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 |
AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
AI小说写作助手,一站式润色、改写、扩写
蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。
全能AI智能助手,随时解答生活与工作的多样问题
问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。
实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。