英文:
Trigger a Github workflow to run after specified time elapses?
问题
我有两个工作流 A.yml
和 B.yml
。当 A.yml
成功完成时,是否有一种方法可以触发 B.yml
运行,但只在经过 N
分钟后才运行?我知道有 workflow_run
触发器,但似乎会在 A.yml
完成后立即触发。
为了解释问题的背景:目前,工作流 A 构建 iOS 应用程序并将其上传到 TestFlight,然后阻止等待提交出现在 App Store Connect 中。如果要分发给外部测试人员,就没有办法避免阻塞。这意味着我需要支付昂贵的 macos
runner 费用,而它却像这样阻塞。我考虑将其拆分为两个工作流:一个仅构建并上传应用程序而不提交审核,另一个在稍后运行(平均构建出现在 ASC 中的时间为5-10分钟)。
英文:
I have two workflows A.yml
and B.yml
. When A.yml
finishes successfully, is there a way to trigger B.yml
to run, but only after N
minutes elapse? I know there's workflow_run
trigger, but it sounds like that would be triggered immediately upon A.yml
's completion.
To explain the background for the question: currently workflow A builds the iOS app and uploads it to testflight and then blocks waiting for the submission to appear in the App Store Connect. There is no way around blocking if you want to distribute to external testers. This means that I'm paying for an expensive macos
runner while it blocks like this. I though about splitting this into two workflows: one that just builds and uploads the app without submitting for review and another that runs 5-10 mins later (average time for build to appear in ASC).
答案1
得分: 2
根据您的约束,一个可能的解决方案是使用由A工作流指定的时间,使用schedule
事件来执行B:
-
A.yml
- 上传...
- 根据当前的UTC时间计算B所需的时间
- 在B中配置它(例如,使用
date
和yq
)并提交一个提交 - 启用B(
gh workflow enable B
) - 确保在其他工作流中针对
push
忽略B
-
B.yml
- 使用
on.schedule
配置它 - A将更新B的
cron
值 - 它将按计划运行并执行其工作
- 查看其文档以了解不能按计划运行的情况
- 完成后,禁用自身(
gh workflow disable ${{ github.workflow }}
)
- 使用
参考文献:
英文:
Given your constraints, one possible solution could be to use schedule
event for B with the time specified by A workflow:
-
A.yml
- Upload...
- Calculate required time for B given the current UTC time
- Configure it in B (e.g. using
date
andyq
) and push a commit - Enable B (
gh workflow enable B
) - Make sure to ignore B in other workflows against
push
-
B.yml
- Configure it with
on.schedule
- A will update B's
cron
value - It'll run and perform its work as scheduled
- Check its docs to have an idea about when it cannot run as scheduled
- After completion, disable itself (
gh workflow disable ${{ github.workflow }}
)
- Configure it with
References:
答案2
得分: 0
这是要添加到 A.yml 工作流程末尾的部分代码:
Windows:
- name: 等待 60 秒
run: Start-Sleep -s 60
shell: powershell
Linux:
- name: 等待 60 秒
run: sleep 60s
shell: bash
英文:
You could add this at the end of A.yml workflow :
Windows :
- name: Sleep for 60 seconds
run: Start-Sleep -s 60
shell: powershell
Linux :
- name: Sleep for 60 seconds
run: sleep 60s
shell: bash
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论