首页  >  All Categories  >  Notes  >  Github Action Workflow 触发运行分析

Github Action Workflow 触发运行分析

目标🔗

单个 (或多个) Workflow 之间触发运行逻辑,搞清楚究竟是按照什么样的顺序运行。

最直接 on.<push>🔗

When using the push and pull_request events, you can configure a workflow to run based on what file paths are changed. Path filters are not evaluated for pushes of tags.

Use the paths filter when you want to include file path patterns or when you want to both include and exclude file path patterns. Use the paths-ignore filter when you only want to exclude file path patterns. You cannot use both the paths and paths-ignore filters for the same event in a workflow. If you want to both include and exclude path patterns for a single event, use the paths filter prefixed with the ! character to indicate which paths should be excluded.

If at least one path matches a pattern in the paths filter, the workflow runs. For example, the following workflow would run anytime you push a JavaScript file (.js).

例如:

on:
  push:
    paths:
      - '**.js'

或者忽略,也就是说只有存在 docs 文件以外的文件的 push 才能触发 Workflow

on:
  push:
    paths-ignore:
      - 'docs/**'

设定固定周期运行🔗

单个工作流可以由多个 schedule 事件触发。您可以通过 github.event.schedule 上下文访问触发工作流的计划事件。此示例触发工作流在每周一至周四的 5:30 UTC 运行,但在周一和周三跳过该 Not on Monday or Wednesday 步骤。

on:
  schedule:
    - cron: '30 5 * * 1,3'
    - cron: '30 5 * * 2,4'

jobs:
  test_schedule:
    runs-on: ubuntu-latest
    steps:
      - name: Not on Monday or Wednesday
        if: github.event.schedule != '30 5 * * 1,3'
        run: echo "This step will be skipped on Monday and Wednesday"
      - name: Every time
        run: echo "This step will always run"

Workflow_run 进行控制🔗

When using the workflow_run event, you can specify what branches the triggering workflow must run on in order to trigger your workflow.

例如,仅当名为 Build 的工作流在 requested 时,才运行此工作流。其中,类型可以选择completed requested in_progress

on:
  workflow_run:
    workflows: ["Build"]
    types: [requested]

Note: You can’t use workflow_run to chain together more than three levels of workflows. For example, if you attempt to trigger five workflows (named B to F) to run sequentially after an initial workflow A has run (that is: A → B → C → D → E → F), workflows E and F will not be run.

只能满足最多三层链接

之前没有指定 types 导致连续运行三次。 before

看着就浪费资源,不能忍,必须排查。

看完官方文档,终于发现了,指定成了 completed 就正常了。 after

参考资料🔗

分类: Notes 
标签GithubWorkflowzola
发布于: