Environmental files on Windows

Recently, we noticed the warnings regarding set-env and suggestion to migrate to environmental files.
Some of our builds are run on windows machines. I noticed, that I am unable to reproduce the

- name: export yellow
  run: echo "action_state=yellow" >> $GITHUB_ENV

and later

- name: read yellow
  run: echo $action_state

example, not to mention exporting GITHUB_TOKEN. Shouldn’t this setup work on windows? Or should we keep env for our builds?

1 Like

Only echo ::set-env name={name}::{value} is deprecated. You can use env: as before.

In GitHub’s virtual Windows environments, the default shell is PowerShell (Core). You need to set shell: bash if you want to use echo "action_state=yellow" >> $GITHUB_ENV

The PowerShell equivalent is:

echo "action_state=yellow" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append

And in cmd:

echo action_state=yellow >> %GITHUB_ENV%

(cmd in GitHub runners uses UTF-8 by default. In other Windows environments you may need to run chcp 65001 first)

@Simran-B
Thank you very much for your answer!

I guess I got confused by all the warnings I have been receiving on my builds and thought that env somehow calls set-env under the hood. I will stick to env then.

Many actions rely on @actions/core, but use an outdated version which still uses ::set-env instead of environment files. actions/checkout is a popular example: https://github.com/actions/checkout/pull/361