branch-deploy

branch-deploy

基于IssueOps的GitHub分支部署自动化Action

branch-deploy是一个GitHub Action,通过IssueOps实现分支部署自动化。它可检测PR评论中的命令并触发部署,支持noop模式、多环境部署和部署锁定。该Action遵循仓库的分支保护规则,提供自定义命令语法,并自动创建GitHub部署。它有效简化了分支部署流程,提升了开发效率和安全性。

GitHub Actions分支部署IssueOps持续集成自动化部署Github开源项目

Branch Deploy Action 🚀

CodeQL test package-check lint actions-config-validation coverage

A GitHub Action to enable branch deployments using IssueOps!

ship-it

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
  • 🚀 Triggers GitHub deployments for you with simple configuration
  • 🔓 Deploy locks to prevent multiple deployments from clashing

Available Commands 💬

  • .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 Action

These 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

Demo 🎥

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

Turbo Quickstart ⚡

A quick section to get you started with this Action

Usage 📝

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"

Example 📚

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

About 💡

Before we get into details, let's first define a few key terms below:

  • 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

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:

# 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:

  1. Check the comment which invoked the workflow for the trigger: phrase (.deploy) defined here
  2. If the trigger phrase is found, it will proceed with a deployment
  3. It will start by reacting to your message to let you know it is running
  4. The Action will post a comment with a link to the running Actions workflow for you to follow its progress
  5. 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
  6. Outputs will be exported by this job for later reference in other jobs as well
# 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 continue
  • steps.branch-deploy.outputs.noop == 'true' - The noop variable is only set to true when a noop deployment should be run

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

Inputs 📥

InputRequired?DefaultDescription
github_tokentrue${{ github.token }}The GitHub token used to create an authenticated client - Provided for you by default!
statustrue${{ job.status }}The status of the GitHub Actions - For use in the post run workflow - Provided for you by default!
reactionfalseeyesIf set, the specified emoji "reaction" is put on the comment to indicate that the trigger was detected. For example, "rocket" or "eyes"
triggerfalse.deployThe string to look for in comments as an IssueOps trigger. Example: ".deploy"
noop_triggerfalse.noopThe string to look for in comments as an IssueOps noop trigger. Example: ".noop" - The usage would then be ".noop"
lock_triggerfalse.lockThe string to look for in comments as an IssueOps lock trigger. Used for locking branch deployments on a specific branch. Example: ".lock"
unlock_triggerfalse.unlockThe string to look for in comments as an IssueOps unlock trigger. Used for unlocking branch deployments. Example: ".unlock"
help_triggerfalse.helpThe string to look for in comments as an IssueOps help trigger. Example: ".help"
lock_info_aliasfalse.wcidAn 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")
permissionstruewrite,maintain,adminThe allowed GitHub permissions an actor can have to invoke IssueOps commands - Example: "write,maintain,admin"
param_separatorfalse|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_flagfalse--globalThe flag to pass into the lock command to lock all environments. Example: "--global"
environmentfalseproductionThe name of the default environment to deploy to. Example: by default, if you type .deploy, it will assume "production" as the default environment
environment_targetsfalseproduction,development,stagingOptional (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_urlsfalse""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_targetsfalse""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_commentfalse"trueIf 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_environmentsfalseproductionA 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_branchfalsemainThe name of a stable branch to deploy to (rollbacks). Example: "main"
update_branchfalsewarnDetermine how you want this Action to

编辑推荐精选

潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
商汤小浣熊

商汤小浣熊

最强AI数据分析助手

小浣熊家族Raccoon,您的AI智能助手,致力于通过先进的人工智能技术,为用户提供高效、便捷的智能服务。无论是日常咨询还是专业问题解答,小浣熊都能以快速、准确的响应满足您的需求,让您的生活更加智能便捷。

imini AI

imini AI

像人一样思考的AI智能体

imini 是一款超级AI智能体,能根据人类指令,自主思考、自主完成、并且交付结果的AI智能体。

Keevx

Keevx

AI数字人视频创作平台

Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。

下拉加载更多