github动作开始工作流程,请求多个分支多环境

发布于 2025-02-02 11:25:04 字数 1213 浏览 3 评论 0原文

我正在尝试使用以下条件开始github操作工作流程作业,每个条件都会启动一个单独的作业:

  1. 如果有新的拉力请求将DEV分支机构 -
  2. 如果将代码合并到DEV分支机构 - 将基础结构与Dev Environal部署到DEV环境 - 将基础结构部署到UAT环境
  3. 如果有新的拉力请求到主分支机构 -
  4. 如果将代码合并到主要分支机构,则将
on:   
  push:
    branches:
      - dev
      - main   
  pull_request:
    types: [opened, reopened]
    branches:
      - dev
      - main   
  workflow_dispatch:
        
    jobs:
        
          DeployDev:
            name: Deploy to dev
            if: ${{github.ref == 'refs/heads/dev' && github.event_name == 'pull_request'}}
            runs-on: ubuntu-latest
            environment: dev
            more steps follows ......


基础架构部署到分期环境, -在其他匹配条件下,将基础架构部署到生产环境(要运行的单独工作),我正在使用

部署:部署:

if: ${{github.ref == 'refs/heads/dev' && github.event_name == 'push'}}

部署:

if: ${{github.ref == 'refs/heads/main' && github.event_name == 'pull_request'}}

decloveprod:

${{github.ref == 'refs/heads/main' && github.event_name == 'push'}}

合并代码时似乎运行正常,但是当创建拉动请求时没有运行。

有人可以指向我我在做什么错吗?我尝试删除行类型:[打开,重新打开],但没有任何区别。

I am trying to start Github actions workflow jobs with the following conditions, with each condition initiating a separate job:

  1. If there is a new pull request to dev branch - deploy infrastructure to dev environment
  2. If the code is merged to dev branch - deploy infrastructure to uat environment
  3. If there is a new pull request to main branch - deploy infrastructure to staging environment
  4. If the code is merged to main branch - deploy infrastructure to production environment
on:   
  push:
    branches:
      - dev
      - main   
  pull_request:
    types: [opened, reopened]
    branches:
      - dev
      - main   
  workflow_dispatch:
        
    jobs:
        
          DeployDev:
            name: Deploy to dev
            if: ${{github.ref == 'refs/heads/dev' && github.event_name == 'pull_request'}}
            runs-on: ubuntu-latest
            environment: dev
            more steps follows ......


similarly for other matching conditions (separate jobs to run), I am using

DeployUat:

if: ${{github.ref == 'refs/heads/dev' && github.event_name == 'push'}}

DeployStaging:

if: ${{github.ref == 'refs/heads/main' && github.event_name == 'pull_request'}}

DeployProd:

${{github.ref == 'refs/heads/main' && github.event_name == 'push'}}

Workflow jobs seems to be running ok when code is merged, but not when a pull request is created.

Can someone point me what am I doing wrong ? I tried removing the line types: [opened, reopened], but does not makes any difference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑忘罢 2025-02-09 11:25:05

我想我找到了答案。

而不是
如果:$ github.ref =='refs/heads/dev'&& github.event_name =='pull_request'

应该是
如果:$ github.event.pull_request.base.ref =='dev'&& github.event_name =='pull_request'

I think I found the answer.

Instead of
if: $github.ref == 'refs/heads/dev' && github.event_name == 'pull_request'

It should be
if: $github.event.pull_request.base.ref == 'dev' && github.event_name == 'pull_request'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文