【发布时间】:2022-01-10 05:13:30
【问题描述】:
一个工作流是否可能依赖于另一个工作流?
我的测试分支目前有 2 个工作流。第一个是由 pull_request 触发的 github_action_pull_test.yml。当测试分支上有 pull_request 时,工作流运行到 terragrunt 计划。第二个是 github_action_push_test.yml当我的测试分支合并时触发,工作流运行 terragrunt apply。
当前设置有一个负面影响: 我的 github_action_push_test.yml 包含 github_action_pull_test.yml 中的所有步骤。 有没有一种方法可以让我拥有一个包含所有步骤的工作流,但仅在 terragrunt 计划经过审查并合并到测试分支后才运行 terragrunt apply,这样我就可以避免重复
github_action_pull_test.yml
name: 'GitHub OIDC workflow'
on:
pull_request:
branches:
- test
env:
tf_version: 'latest'
tg_version: 'latest'
tf_working_dir: './testing'
permissions:
id-token: write
contents: read
jobs:
deploy:
name: 'Build and Deploy'
runs-on: ubuntu-latest
steps:
- name: 'checkout'
uses: actions/checkout@v2
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@master
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::123456789012:role/GitHubActions_Workflow_role
role-duration-seconds: 3600
- name: 'Terragrunt Init'
uses: the-commons-project/terragrunt-github-actions@master
with:
tf_actions_version: ${{ env.tf_version }}
tg_actions_version: ${{ env.tg_version }}
tf_actions_subcommand: 'init'
tf_actions_working_dir: ${{ env.tf_working_dir }}
tf_actions_comment: true
env:
TF_INPUT: false
- name: 'Terragrunt Validate'
uses: the-commons-project/terragrunt-github-actions@master
with:
tf_actions_version: ${{ env.tf_version }}
tg_actions_version: ${{ env.tg_version }}
tf_actions_binary: 'terraform'
tf_actions_subcommand: 'validate'
tf_actions_working_dir: ${{ env.tf_working_dir }}
tf_actions_comment: true
- name: 'Terragrunt Plan'
uses: the-commons-project/terragrunt-github-actions@master
with:
tf_actions_version: ${{ env.tf_version }}
tg_actions_version: ${{ env.tg_version }}
tf_actions_subcommand: 'plan'
tf_actions_working_dir: ${{ env.tf_working_dir }}
tf_actions_comment: true
github_action_push_test.yml
name: 'GitHub OIDC workflow'
on:
push:
branches:
- test
env:
tf_version: 'latest'
tg_version: 'latest'
tf_working_dir: './testing'
permissions:
id-token: write
contents: read
jobs:
deploy:
name: 'Build and Deploy'
runs-on: ubuntu-latest
steps:
- name: 'checkout'
uses: actions/checkout@v2
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@master
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::123456789012:role/GitHubActions_Workflow_role
role-duration-seconds: 3600
- name: 'Terragrunt Init'
uses: the-commons-project/terragrunt-github-actions@master
with:
tf_actions_version: ${{ env.tf_version }}
tg_actions_version: ${{ env.tg_version }}
tf_actions_subcommand: 'init'
tf_actions_working_dir: ${{ env.tf_working_dir }}
tf_actions_comment: true
env:
TF_INPUT: false
- name: 'Terragrunt Validate'
uses: the-commons-project/terragrunt-github-actions@master
with:
tf_actions_version: ${{ env.tf_version }}
tg_actions_version: ${{ env.tg_version }}
tf_actions_binary: 'terraform'
tf_actions_subcommand: 'validate'
tf_actions_working_dir: ${{ env.tf_working_dir }}
tf_actions_comment: true
- name: 'Terragrunt Plan'
uses: the-commons-project/terragrunt-github-actions@master
with:
tf_actions_version: ${{ env.tf_version }}
tg_actions_version: ${{ env.tg_version }}
tf_actions_subcommand: 'plan'
tf_actions_working_dir: ${{ env.tf_working_dir }}
tf_actions_comment: true
- name: 'Terragrunt Apply'
uses: the-commons-project/terragrunt-github-actions@master
with:
tf_actions_version: ${{ env.tf_version }}
tg_actions_version: ${{ env.tg_version }}
tf_actions_subcommand: 'apply'
tf_actions_working_dir: ${{ env.tf_working_dir }}
tf_actions_comment: true
【问题讨论】:
-
您是否研究过可重用的工作流程? github.blog/changelog/…
-
您还可以将两个工作流程合二为一,并在
apply步骤中添加if: github.ref == 'refs/head/test'。这个组合的工作流将在push上触发到任何分支。当然,除非您使用on: pull_request有特定原因,但是您仍然可以同时使用这两个触发器并使用if github.event...区分两者 -
非常感谢您的回答..它奏效了