如何快速在现有仓库中添加 GitHub Action 工作流?
点击仓库的 Actions,若已增加过 Actions,会显示如下界面。
点击 New workflow
新增。
Actions 存放地址是固定的,统一为 /.github/workflows/xx.yml
。关于 YML
语法,可自行学习。
点你点击新增自定义 Action 时,默认展示:
# 这是一个基本的工作流程,可帮助你快速开始name: CI# 控制这个工作流啥时候触发on:# 当前设置为:推送 main 分支或对 main 分支的 PRpush:branches: [ main ]pull_request:branches: [ main ]# 允许从 Actions 选项卡手动运行此工作流workflow_dispatch:# 顺序或并行开始执行一个或多个作业流jobs:# 当前工作流只包含一个名为 buildbuild:# 运行环境runs-on: ubuntu-latest# 工作流步骤steps:# 在当前工作流环境,检出当前库- uses: actions/checkout@v2# 执行一条 shell 命令- name: Run a one-line scriptrun: echo Hello, world!# 执行多条 shell 命令- name: Run a multi-line scriptrun: |echo Add other actions to build,echo test, and deploy your project.
name
:自定义 Action 流程名称on
:Action 触发机制,参考uses
:使用其他 GitHub Action当你完成编写完成提交到主分支后,即可自动启用该 workflow,触发条件遵循 on 的定义。