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-outputwithGITHUB_OUTPUT: Instead of the old::set-outputcommand, we write the output directly to the$GITHUB_OUTPUTfile. This registers theshould_runoutput for thecheck_datejob, making it accessible to downstream jobs likedeploy. - No extra steps in
deploy: Thedeployjob 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 theneedskeyword 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
相关产品推荐
相关产品推荐

