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

GitHub Actions工作流任务条件运行实现方案——解决set-output弃用后的跨任务状态传递问题

Got it, the perfect solution here is using GitHub's official GITHUB_OUTPUT environment file as a replacement for the deprecated set-output command. This method lets you pass outputs between jobs directly, so your deploy job can still conditionally run based on the check result without any extra download steps (which is exactly what you need).

Here's your updated workflow using the supported syntax:

jobs:
  check_date:
    id: should_run
    continue-on-error: true
    name: check latest commit is less than 24 hours
    if: ${{ github.event_name == 'schedule' }}
    runs-on: ubuntu-latest
    steps:
      - name: Check commit age and set output
        run: |
          # Check if there are commits newer than 24 hours
          if git rev-list --after="24 hours" ${{ github.sha }} | grep -q .; then
            echo "should_run=false" >> $GITHUB_OUTPUT
          fi

  deploy:
    needs: check_date
    if: ${{ needs.check_date.outputs.should_run != 'false' }}
    name: Build container image
    runs-on: ubuntu-latest
    steps:
      # Add your actual deploy/build steps here
      - name: Example deploy step
        run: echo "Running deployment..."

Breakdown of the changes:

  • Replaced ::set-output with GITHUB_OUTPUT: Instead of the old ::set-output command, we write the output directly to the $GITHUB_OUTPUT file. This registers the should_run output for the check_date job, making it accessible to downstream jobs like deploy.
  • No extra steps in deploy: The deploy job uses the same conditional check (needs.check_date.outputs.should_run != 'false') as before. It doesn't need any artifact downloads or additional setup—just the needs keyword to depend on the check job, and the conditional to skip if needed.
  • Officially supported: This is the method GitHub recommends to replace set-output, so you won't run into deprecation issues like you would with the old command.

This keeps your workflow lean, efficient, and aligned with GitHub's current Actions standards, while meeting your requirement of avoiding unnecessary steps in the deploy job.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.27 13:42:48