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
After testing I could not get powershell to set the outputs of the job so I wrote it in bash which worked for me.
Try to set them like this:
More information under https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
When the runner is executing commands in PowerShell, you’ll need to format the new output setting like this:
Note the $env: that’s missing from other examples.