How to assign a global environment variable using a ternary expression?

I have the following global environment variable:

env:
  NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages

which works for all Linux / macOS runners using Linux paths but doesn’t seem to work as expected on Windows.

Ideally there’s a function to make a path that takes into account the runner os, but that doesn’t exist, so my next idea is to use a ternary expression that checks the runner os, but I can’t find any mention of ternary expressions either.

How can I do this?

If you call this environment variable in command lines, there are some notes need to pay attention:

  • If you do not specify shell, Windows runners use PowerShell to run command lines by default, and Linux/macOS runners use Bash by default.
  • If call the environment variable in command lines, the syntaxes are different with different shells.

So, you may need to check if the syntax you used on Windows runners is correct.