In GitHub Actions, can I return back a value to be used as a condition later?

In addition to answer by peterevans, you still can use environment variables for conditions, as long they are set via ::set-env "command"

Example:

- run:   |
         if [ -f FileMightNotExists.txt ]; then
            echo ::set-env name=HAVE_FILE::true
         fi
  shell: bash

- run: echo "I have file!"
  if:  env.HAVE_FILE == 'true'

As mentioned, there is ::set-output already, so it's a matter of taste mostly.

What makes ::set-env easier to use (in my opinion) is that you don't need to set id for steps (less typing), referencing vars is much shorter (less typing again), all variables you added will be listed for each step (folded inside Run block, can be useful when trying to find bugs in workflow), and well... it's just regular variable in the end, it might be easier to work with, depends on shell.


I think you can set outputs from Powershell by just echoing them to the console. Powershell has an alias mapping echo to Write-Output.

jobs:
  windows-test:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v1
      - name: Set outputs
        id: vars
        shell: pwsh
        run: echo "::set-output name=production::true"
      - name: Check outputs
        shell: pwsh
        run: echo ${{ steps.vars.outputs.production }}

ref: https://help.github.com/en/github/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-output-parameter-set-output