如何使用GitHub操作从另一个工作流程触发工作流程?

发布于 2025-01-23 02:31:30 字数 2082 浏览 3 评论 0原文

我想从文件中读取版本,并使用工作流创建标签为v11.0.5.1.aws。然后,我想在Docker图像中使用该标签。 为此,我创建了一个分支为DevOps。

首先创建一个版本文件作为

1.1.3 20 Apr, 2022

创建一个工作流程为repartion-version.yml

name: Release Version
on:
  push:
    branches:
      - devops
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Bump version and push tag
    uses: melheffe/version_release_composer@master
    env:
      PREPEND: 'v'
      APPEND: '.aws' # must include '.' or it will append without separation
      DRAFT: 'false'
      PRERELEASE: 'true'
      TOKEN: ${{ secrets.AUTH_TOKEN }}
      TRIGGER: ${{ github.event.pull_request.base.ref }} # can use the triggering branch or define a     fixed one like this: 'master'
      REPO_OWNER: rohit
      VERSION_FILE_NAME: 'VERSION'

然后创建另一个工作流程为ci.yml,该工作流将从repartion-version workflow中获取标签,

name: CI

# Only trigger, when the build workflow succeeded
on:
  workflow_run:
    workflows: ["Release Version"]
    types:
      - completed

jobs:
  # This workflow contains a single job called "build"
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

  DeployDev:
    # Steps represent a sequence of tasks that will be executed as part of the job
    name: Deploy to Dev
    needs: [Build]
    runs-on: ubuntu-latest
    environment:
      name: Dev

    steps:
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.AUTH_TOKEN }}

      - name: Build, tag, and push image to Amazon ECR
        id: build-image
        #env:
        #  IMAGE_TAG: ${{ github.sha }}
        run: |
          # Build a docker container and push it to ECR so that it can
          # be deployed to ECS.
          echo "$GITHUB_REF_NAME"
          docker build -t ${{secrets.ECR_REPO_URI}}/${{secrets.REPO_NAME}}:$GITHUB_REF_NAME .
          docker push ${{secrets.ECR_REPO_URI}}/${{secrets.REPO_NAME}}:$GITHUB_REF_NAME
          

我可以在更改DevOps分支后触发版本版本工作流,但是CI Workflow在触发释放后,不会触发。 任何建议都会对我有所帮助。

I want to read version from a file and create tag as v11.0.5.1.aws using the workflow . Then I want to use that tag in the docker image.
For that, I have created a branch as devops.

First created a VERSION file as

1.1.3 20 Apr, 2022

Created a workflow as release-version.yml

name: Release Version
on:
  push:
    branches:
      - devops
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Bump version and push tag
    uses: melheffe/version_release_composer@master
    env:
      PREPEND: 'v'
      APPEND: '.aws' # must include '.' or it will append without separation
      DRAFT: 'false'
      PRERELEASE: 'true'
      TOKEN: ${{ secrets.AUTH_TOKEN }}
      TRIGGER: ${{ github.event.pull_request.base.ref }} # can use the triggering branch or define a     fixed one like this: 'master'
      REPO_OWNER: rohit
      VERSION_FILE_NAME: 'VERSION'

Then created another workflow as ci.yml which will get tag from release-version workflow

name: CI

# Only trigger, when the build workflow succeeded
on:
  workflow_run:
    workflows: ["Release Version"]
    types:
      - completed

jobs:
  # This workflow contains a single job called "build"
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

  DeployDev:
    # Steps represent a sequence of tasks that will be executed as part of the job
    name: Deploy to Dev
    needs: [Build]
    runs-on: ubuntu-latest
    environment:
      name: Dev

    steps:
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.AUTH_TOKEN }}

      - name: Build, tag, and push image to Amazon ECR
        id: build-image
        #env:
        #  IMAGE_TAG: ${{ github.sha }}
        run: |
          # Build a docker container and push it to ECR so that it can
          # be deployed to ECS.
          echo "$GITHUB_REF_NAME"
          docker build -t ${{secrets.ECR_REPO_URI}}/${{secrets.REPO_NAME}}:$GITHUB_REF_NAME .
          docker push ${{secrets.ECR_REPO_URI}}/${{secrets.REPO_NAME}}:$GITHUB_REF_NAME
          

I'm able to trigger release version workflow after making changes on devops branch but ci workflow is not getting triggered after triggering the release-version.
Any suggestion will be helpful for me.

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

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

发布评论

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

评论(2

千纸鹤带着心事 2025-01-30 02:31:30

如果workflow_run触发器无法正常工作,则还有另外两种实现您想要的方法(从另一个工作流触发工作流程,从第一个参数发送第一个输入参数以在第二个方面使用)。

该文档对如何使用它们非常好,但是我将在这里添加一些参考文献也可以有所帮助:

如您所见,您可以在一个步骤中直接使用GitHub API触发这些事件(使用卷曲请求)或使用GitHub市场上执行相同操作的某些动作。

事件之间的区别(因为它们相似,而卷曲有效载荷差异可能会造成混淆)

  • 下面的答案还解释了两个 -to-run-workflow-dispatch-ingithub-action/69930019#69930019“>使用客户端付费的正确请求,以运行workflow_dispatch在github action中

我还将在此处添加一个示例,该示例可用于理解如何使用repository_dispatch事件从另一个工作流程接收回调到第一个工作流程:

请注意,您还需要使用A 使用调度事件触发工作流程。

If the workflow_run trigger isn't working as expected, there are two other ways to achieve what you want (triggering a workflow from another workflow, sending an input parameter from the first one to use in the second one).

The documentation is very good about how to use them, but I'll add here some references that can help as well:

As you can see, you can trigger those events using directly the Github API in a step (with a CURL request) or using some actions from the Github Marketplace that perform the same operation.

The answer below also explains the difference between both events (as they are similar, and CURL payload differences may be confusing)

I'll also add here an example that can be useful to understand how to use the repository_dispatch event to receive a callback from the other workflow to the first one:

Note that you will also need to use a PAT to trigger a workflow using a dispatch event.

方觉久 2025-01-30 02:31:30

github的文档workflow_run

您不能使用Workflow_run将超过三个级别的工作流程链接在一起。例如,如果您尝试触发五个工作流(命名b to f)在初始工作流程 a 已运行之后依次运行(那就是:abcde e →f),工作流<代码> e 和f将不会运行。

也许您有一个超过三个工作流程的连锁店?

There is an important Note in GitHub's documentation on workflow_run:

You can't use workflow_run to chain together more than three levels of workflows. For example, if you attempt to trigger five workflows (named B to F) to run sequentially after an initial workflow A has run (that is: ABCDEF), workflows E and F will not be run.

Perhaps you have a chain with more than three levels of workflows?

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