Continuous integration github工作流中的'github.event'具有哪些属性?

Continuous integration github工作流中的'github.event'具有哪些属性?,continuous-integration,webhooks,github-actions,Continuous Integration,Webhooks,Github Actions,使用GitHub操作时,可以在表达式中访问。其中一个上下文是github上下文。它有一个属性github.event,它是一个对象 github.event对象有哪些属性?如何区分推送事件和标签创建事件?要区分不同的事件,您可以始终检查github.event\u name: jobs: test: runs-on: ubuntu-18.04 if: github.event_name == 'push' github.event的属性取决于触发的事件类型。它们记录在本手册

使用GitHub操作时,可以在表达式中访问。其中一个上下文是
github
上下文。它有一个属性
github.event
,它是一个对象


github.event
对象有哪些属性?如何区分推送事件和标签创建事件?

要区分不同的事件,您可以始终检查github.event\u name:

jobs:
  test:
    runs-on: ubuntu-18.04
    if: github.event_name == 'push'
github.event
的属性取决于触发的事件类型。它们记录在本手册的“事件类型和有效负载”一节中。“”文档的“Webhook事件”部分包含指向“Webhook事件负载”列中每个对象的链接

例子 您有一个事件,因此
github.event\u name==“create”
。您可以在
工作流.yml
中访问以下属性(如中所述)

  • ${{github.event.ref\u type}
  • ${{github.event.ref}}
  • ${{github.event.master_branch}}
  • ${{github.event.description}}
完整的工作流示例 这是一个单一的工作流,它运行不同的作业,具体取决于它是由推送还是标记创建事件触发的

  • 对推送和标记创建运行测试
  • 将应用程序打包到任何标记上
  • 当标签以
    v开始时部署应用程序
名称:CI
关于:
推送:
分支机构:
-主人
创建:
标签:
工作:
测试:
运行日期:ubuntu-18.04
步骤:
- 
地区:
运行日期:ubuntu-18.04
if:github.event_name=='create'
步骤:
- 
-名称:上传工件
用途:操作/上传-artifact@v1
与:
姓名:mypackage
路径:dist
部署:
需求:地区
运行日期:ubuntu-18.04
if:github.event_name='create'&&startsWith(github.ref'refs/tags/v')
#这是同样的:
#if:github.event\u name='create'&&github.event.ref\u type='tag'&&startsWith(github.event.ref,'v')
步骤:
-名称:下载工件
用途:操作/下载-artifact@v1
与:
姓名:mypackage
- 
请注意,
github.ref
github.event.ref
不同:

  • github.ref==“refs/tags/v1.2.5”
  • github.event.ref==“v1.2.5”

与webhook相同?我不知道这以前是否有效。但现在没有了
on.create.tags[]
不会捕获新的标记事件。例如,它在拉取请求上运行。您应该将其更改为.push.tags[]上的
。您还应该将
github.event\u name
更改为push。这样就行了。
name: CI

on:
  push:
    branches:
      - master
  create:
    tags:

jobs:

  test:
    runs-on: ubuntu-18.04

    steps:
      - <YOUR TESTSTEPS HERE>

  dist:
    runs-on: ubuntu-18.04
    if: github.event_name == 'create'

    steps:
      - <YOUR BUILDSTEPS HERE>
      - name: Upload artifact
        uses: actions/upload-artifact@v1
        with:
          name: mypackage
          path: dist

  deploy:
    needs: dist
    runs-on: ubuntu-18.04
    if: github.event_name == 'create' && startsWith(github.ref, 'refs/tags/v')
    # This does the same:
    # if: github.event_name == 'create' && github.event.ref_type == 'tag' && startsWith(github.event.ref, 'v')

    steps:
      - name: Download artifact
        uses: actions/download-artifact@v1
        with:
          name: mypackage
      - <YOUR DEPLOY STEPS HERE>