【问题标题】:Only run GitHub Actions step if not a pull request如果不是拉取请求,则仅运行 GitHub Actions 步骤
【发布时间】:2021-02-15 18:16:51
【问题描述】:

我有一个需要在推送或拉取请求上执行的工作流,除了将包推送到 NuGet 的最后一步(我不希望这发生在拉取请求上,即使是掌握) .

如果工作流是从拉取请求触发的,我如何防止“发布 NuGet”步骤运行?

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.101
    - name: Install dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Test
      run: dotnet test --no-restore --verbosity normal
    - name: Publish NuGet
      uses: brandedoutcast/publish-nuget@v2.5.2
      with:
        PROJECT_FILE_PATH: "Orleans.Sagas/Orleans.Sagas.csproj"
        NUGET_KEY: ${{secrets.NUGET_KEY}}

【问题讨论】:

    标签: github-actions


    【解决方案1】:

    您可以检查包含触发工作流运行的事件名称的github.event_name context variable。 (例如,pull_requestpush

    在这种情况下,您可以针对名称不是 pull_request 的所有事件运行一个步骤,并以您的步骤为条件使用 github.event_name != 'pull_request'

    例如:

     - name: Publish NuGet
       uses: brandedoutcast/publish-nuget@v2.5.2
       with:
         PROJECT_FILE_PATH: "Orleans.Sagas/Orleans.Sagas.csproj"
         NUGET_KEY: ${{secrets.NUGET_KEY}}
       if: github.event_name != 'pull_request'
    

    【讨论】:

      猜你喜欢
      • 2020-12-28
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-16
      • 2020-01-16
      • 2020-01-11
      • 2022-07-24
      相关资源
      最近更新 更多