手动触发的 Github Action 总是被跳过

Per*_*syl 5 github-actions

我有一个基于提交构建的工作 Github Action 文件。

我希望能够手动触发构建,因此我只添加了“workflow_dispatch”,并在 GUI 中看到了不错的选项按钮,我可以在其中选择要手动构建的分支。

但是当我选择一个分支(“dev”)并开始构建时,它总是被跳过?!

yml 文件位于我的“main”分支和所需的分支“dev”中

我的 yml 文件如下所示,“workflow_dispatch”是我唯一更改的内容:

name: Build for dev

on:
  workflow_dispatch:
  push:
    branches:
      - dev
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches:
      - dev

jobs:
  build_and_deploy_job:
    if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
    runs-on: ubuntu-latest
    name: Build and Deploy Job
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v0.0.1-preview
        with:
          app_build_command: "npm run build-dev"
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_XXXXX }}
          repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
          action: "upload"
          ###### Repository/Build Configurations - These values can be configured to match you app requirements. ######
          # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
          app_location: "/" # App source code path
          api_location: "api" # Api source code path - optional
          output_location: "dist" # Built app content directory - optional
          ###### End of Repository/Build Configurations ######
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

  close_pull_request_job:
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    runs-on: ubuntu-latest
    name: Close Pull Request Job
    steps:
      - name: Close Pull Request
        id: closepullrequest
        uses: Azure/static-web-apps-deploy@v0.0.1-preview
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_XXXXX }}
          action: "close"


Run Code Online (Sandbox Code Playgroud)

有谁知道为什么构建被跳过,或者我在哪里可以看到其原因?

更新:跳过构建的屏幕截图: 在此输入图像描述

更新!我自己找到了解决方案!我在“build_and_deploy_job”中有一个 if 语句,所以我需要将其更改为:

if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
Run Code Online (Sandbox Code Playgroud)

Wal*_*lly 4

我有同样的症状 - 我的手动运行工作流程被标记为“已跳过”。

就我而言,我对每项工作都有以下条件。仅当链中的前一个工作流程成功时,此条件才会运行作业:

if: ${{ github.event.workflow_run.conclusion == 'success' }}
Run Code Online (Sandbox Code Playgroud)

当工作流程手动启动时,上述情况并不满足。以下对我有用:

if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
Run Code Online (Sandbox Code Playgroud)

上面说,“如果手动启动父工作流程成功,则运行此作业。”