GitHub 操作:sharing/referencing 工作流之间的作业

GitHub Actions: sharing/referencing jobs between workflows

正如所讨论的 here,在 GitHub 操作中,有一种很好的方法可以使用 need 关键字在其他 job 中引用 job,例如

name: Share data between jobs
on: [push]

jobs:
  job_1:
    name: Add 3 and 7
    runs-on: ubuntu-latest
    steps:
        # Steps

  job_2:
    name: Multiply by 9
    needs: job_1
    # The rest of the job

我在文档中找不到答案的问题是:有没有办法在其他工作流程中 reference/share jobs? (即单独的 yml 文件)

我的项目由几个独立的工作流组成,每个工作流都需要执行相同的初始 steps。我试图避免在不同的 workflow 之间复制粘贴相同的步骤。

目前,我认为指定工作流之间的依赖关系是不可能的。 GitHub 社区论坛对此进行了讨论:

How do I specify job dependency running in another workflow?

What you can do is to use the same workflow file and then use conditions to trigger or not a specific job.

If you want to run a job only when there is a push to master branch you can do it like this:

   deploy:
       if: github.event_name == 'push' && github.ref == 'refs/heads/master'