You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions中if条件致Artifact下载步骤被跳过的问题排查

GitHub Actions中if条件控制Artifact下载步骤被跳过的问题解决

你的问题出在**if条件判断中的工作流名称未加引号**。由于工作流名称(Smoke Test Staging、Smoke Test Preview)包含空格,在GitHub Actions的表达式语法里,这类字符串必须用单引号或双引号包裹,否则会被解析为无效语法,导致条件判断不成立,对应的下载步骤因此被跳过。

修正后的配置代码

name: 'Deploy Playwright Reports'

on:
  workflow_run:
    workflows: [ Smoke Test Staging, Smoke Test Preview ]
    types:
      - completed

jobs:
  deploy:
    name: Deploy Playwright Reports
    runs-on: ubuntu-latest
    if: always()
    permissions:
      actions: read
      contents: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          ref: gh-pages

      - name: Setup GitHub CLI
        run: gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"

      - name: Download Staging Artifact
        if: github.event.workflow_run.workflow == 'Smoke Test Staging'
        run: |
          gh run download ${{ github.event.workflow_run.id }} \
          -p "playwright-staging-report-*" \
          -D playwright-staging-reports
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Download Preview Artifact
        if: github.event.workflow_run.workflow == 'Smoke Test Preview'
        run: |
          gh run download ${{ github.event.workflow_run.id }} \
            -p "playwright-preview-report-*" \
            -D playwright-preview-reports
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

关键修正点

  • 将if: github.event.workflow_run.workflow == Smoke Test Staging改为if: github.event.workflow_run.workflow == 'Smoke Test Staging'
  • 将if: github.event.workflow_run.workflow == Smoke Test Preview改为if: github.event.workflow_run.workflow == 'Smoke Test Preview'

添加引号后,GitHub Actions才能正确识别带空格的工作流名称,条件判断会正常生效,对应的下载步骤就会在触发的工作流匹配时执行。

内容的提问来源于stack exchange,提问作者Libin Thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 18:45:00