13

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.

3 Answers 3

22

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I have tested this and even on ubuntu-latest you need to use $env:
Great answer , thanks !
0

Try to set them like this:

echo "build_changed=$HasBuildDiff" >> $GITHUB_OUTPUT
echo "k8s_changed=$HasK8sDiff" >> $GITHUB_OUTPUT
echo "sql_changed=$HasSqlDiff" >> $GITHUB_OUTPUT
echo "flow_changed=$HasFlowDiff" >> $GITHUB_OUTPUT

More information under https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs

8 Comments

Thank you for the response @jwpol. I just tested the action with those changes and I am not getting any output from the job. When I look at the complete job Evaluate and set job outputs is empty. I also moved the outputs section right after runs-on section but that doesn't seem to have any effect.
After testing it appears that $GITHUB_OUTPUT does not work for a powershell. I was able to set the output with bash
You can add and accept your own answer if you found a solution
it doesn't appear to set steps.step1.outputs.test for me github.com/tuxecure/clickable/actions/runs/3378555568/jobs/… am i missing something?
@Fuseteam if you look at the output $DOCKER_VERSION is empty. Where is that set? I know you can run docker -v to get the version, maybe try that?
|
0

After testing I could not get powershell to set the outputs of the job so I wrote it in bash which worked for me.

# Diff HEAD with the previous commit
# filters out deleted files
git_diff=$(git diff --name-only --diff-filter=d HEAD^ HEAD)
            
# Check what files were in the diff
echo "$git_diff"

# set output variables to false
flow_changed="False"
build_changed="False"
sql_changed="False"
k8s_changed="False"
            
for f in ${git_diff[@]};
do
    if [[ $f =~ "flow.py" ]]; then
         flow_changed="True"
    fi

    if [[ $f =~ "Dockerfile" ]] || [[ $f =~ "Pipfile.lock" ]]; then
         build_changed="True"
    fi

    if [[ $f =~ ".sql" ]]; then
         sql_changed="True"
    fi

    if [[ $f =~ "kubernetes_job.py" ]]; then
         k8s_changed="True"
    fi
done

# Set the outputs
echo "build_changed=$build_changed" >> $GITHUB_OUTPUT
echo "k8s_changed=$k8s_changed" >> $GITHUB_OUTPUT
echo "sql_changed=$sql_changed" >> $GITHUB_OUTPUT
echo "flow_changed=$flow_changed" >> $GITHUB_OUTPUT

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.