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

编辑推荐精选

TRAE编程

TRAE编程

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

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

热门AI工具生产力协作转型TraeAI IDE
蛙蛙写作

蛙蛙写作

AI小说写作助手,一站式润色、改写、扩写

蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。

AI助手AI工具AI写作工具AI辅助写作蛙蛙写作学术助手办公助手营销助手
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

聊天机器人AI助手热门AI工具AI对话
Transly

Transly

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

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

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

热门AI工具AI办公办公工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

模型训练热门AI工具内容创作智能问答AI开发讯飞星火大模型多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

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

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

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

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

下拉加载更多