如何使用GitHub操作从另一个工作流程触发工作流程?
我想从文件中读取版本,并使用工作流创建标签为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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
workflow_run
触发器无法正常工作,则还有另外两种实现您想要的方法(从另一个工作流触发工作流程,从第一个参数发送第一个输入参数以在第二个方面使用)。该文档对如何使用它们非常好,但是我将在这里添加一些参考文献也可以有所帮助:
workflow_dispatch
来自github api?gh
cli 触发github工作流,如您所见,您可以在一个步骤中直接使用GitHub API触发这些事件(使用卷曲请求)或使用GitHub市场上执行相同操作的某些动作。
事件之间的区别(因为它们相似,而卷曲有效载荷差异可能会造成混淆)
我还将在此处添加一个示例,该示例可用于理解如何使用
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:
workflow_dispatch
from Github API?gh
CLIAs 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 acallback
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.
github的文档
workflow_run
:也许您有一个超过三个工作流程的连锁店?
There is an important Note in GitHub's documentation on
workflow_run
:Perhaps you have a chain with more than three levels of workflows?