跳到主要内容

触发事件

事件概述

Event 是流水线启动的源动力。当仓库中发生特定操作时,系统产生对应事件,触发匹配 on 配置的 Workflow。

支持的事件类型

事件说明典型配置
push代码推送on: push: branches: [main]
pull_requestPR 事件on: pull_request: branches: [main]
pull_request_targetPR 安全事件on: pull_request_target: branches: [main]
issue_commentIssue 评论on: issue_comment: types: [created]
pull_request_commentPR 评论on: pull_request_comment: types: [created]
workflow_dispatch手动触发on: workflow_dispatch: inputs: {...}
workflow_call可重用调用on: workflow_call: inputs: {...}
schedule定时触发on: schedule: - cron: '0 2 * * *'

重要区别pull_request 使用 PR 源分支代码运行,pull_request_target 使用 base 分支代码运行且拥有仓库写权限。Fork 场景推荐使用 pull_request_target

多事件组合

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: