Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Actions $GITHUB_OUTPUT does not seem to be setting job output

I have been using Github Actions to deploy changes for a data engineering project. I have been getting warnings that set-output command is deprecated and am attempting to use $GITHUB_OUTPUT but I am not able to set the output of the job using this.

if_merged:
      runs-on: ubuntu-latest
      if: github.event.pull_request.merged == true
      name: check diff changed
      steps:
        - name: Checkout
          uses: actions/checkout@v3
          with:
            # Checkout as many commits as needed for the diff
            fetch-depth: 2
        
        - shell: pwsh
          id: check_file_changed
          run: |
            # Diff HEAD with the previous commit
            # filters out deleted files
            $diff = git diff --name-only --diff-filter=d HEAD^ HEAD
            
            # Check what files were in the diff
            echo $diff
            
            # Check if a file Pipfile.lock or Dockerfile has changed (added, modified, deleted)
            $BuildDiff = $diff | Where-Object { $_ -match 'Pipfile.lock' -or $_ -match 'Dockerfile'}
            $HasBuildDiff = $BuildDiff.Length -gt 0

            # Check if k8s job has changed
            $K8sDiff = $diff | Where-Object { $_ -match 'kubernetes_job.py'}
            $HasK8sDiff = $K8sDiff.Length -gt 0

            # Check if sql file has changed
            $SqlDiff = $diff | Where-Object { $_ -match '.sql'}
            $HasSqlDiff = $SqlDiff.Length -gt 0

            # Check if flow file has changed
            $FlowDiff = $diff | Where-Object { $_ -match 'flow.py'}
            $HasFlowDiff = $FlowDiff.Length -gt 0

            # Check value of matched object
            echo BuildDiff $BuildDiff ---
            echo K8sDiff $K8sDiff ---
            # echo DeploymentDiff $DeploymentDiff ---
            echo FlowDiff $FlowDiff ---

            # Set the outputs
            Write-Host "::set-output name=build_changed::$HasBuildDiff"
            Write-Host "::set-output name=k8s_changed::$HasK8sDiff"
            Write-Host "::set-output name=sql_changed::$HasSqlDiff"
            Write-Host "flow_changed=$HasFlowDiff" >> $GITHUB_OUTPUT
            # Write-Host "::set-output name=flow_changed::$HasFlowDiff"
      outputs:
        build_changed: ${{ steps.check_file_changed.outputs.build_changed }}
        k8s_changed: ${{ steps.check_file_changed.outputs.k8s_changed }}
        sql_changed: ${{ steps.check_file_changed.outputs.sql_changed }}
        flow_changed: ${{ steps.check_file_changed.outputs.flow_changed }}

I commented out one portion of the Set the outputs step and updated it to $GITHUB_OUTPUT. However, when the job runs the flow_changed output is not set. I cant post images, but if I look at the complete job section after the action runs with $GITHUB_OUTPUT flow_changed is not set. It is set when I use the old set-output command.

like image 743
nac123456 Avatar asked Feb 22 '26 07:02

nac123456


1 Answers

When the runner is executing commands in PowerShell, you'll need to format the new output setting like this:

echo "flow_changed=$flow_changed" >> $env:GITHUB_OUTPUT

Note the $env: that's missing from other examples.

like image 111
ordinarycobbler Avatar answered Feb 24 '26 22:02

ordinarycobbler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!