如何仅在发布后另一个工作流程运行工作流?

发布于 2025-02-06 02:22:06 字数 697 浏览 1 评论 0 原文

我有这样的github工作流程:

name: publish

on:
  release:
    types: [published]
  workflow_run:
    workflows: [test]
    types: [completed]

jobs:
  on-success:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:
      - run: echo 'The test workflow passed'
     

  on-failure:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    steps:
      - run: echo 'The test workflow failed'

我想在发行版上运行发布工作流程,然后传递 test 之后。但是,在每个 test 完成后,它都会在每个推动下运行到 main

如何使发布仅在版本时运行?

I have github workflow like this:

name: publish

on:
  release:
    types: [published]
  workflow_run:
    workflows: [test]
    types: [completed]

jobs:
  on-success:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:
      - run: echo 'The test workflow passed'
     

  on-failure:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    steps:
      - run: echo 'The test workflow failed'

I want to run publish workflow on releases and after test is passed. But it runs on every push to main after every test completed.

How to make publish run only on release?

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

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

发布评论

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

评论(1

慵挽 2025-02-13 02:22:06

解决方案的问题是,使用使用多个事件导致每个事件触发自己的工作流程。因此,工作流程无法分别引用“测试完成”和“发行”条件。当前在GitHub动作中无法做到这一点。

最简单的选择是使您的测试工作流程在每个推送到MAIN和发行时运行,并添加最终作业,如果版本触发工作流程,该作业将运行。因此,您将其附加到您的测试工作流程中:

  on-test-success-and-release:
    runs-on: ubuntu-latest
    if: github.event.release.target_commitish == 'main'
    steps:
      - run: echo 'The test job passed and a release triggered this workflow'

每当创建发布时,这将具有重复测试作业的缺点,但是只要您的发行版不太频繁,这将可以忽略不计。

The issue with your solution is that using multiple events causes each event to trigger its own workflow. So the workflow run has no way of referencing both the "test complete" and the "on release" conditions separately. Currently there is no way of doing this in GitHub Actions.

The easiest option would be to make your testing workflow run on every push to main and on release, and add a final job that will run if a release triggered the workflow. So you would append this to your test workflow:

  on-test-success-and-release:
    runs-on: ubuntu-latest
    if: github.event.release.target_commitish == 'main'
    steps:
      - run: echo 'The test job passed and a release triggered this workflow'

This will have the downside of the testing job being repeated whenever a release is created, but this is negligible as long as your releases are not too frequent.

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