Setting environment variable for windows using power shell

Hello,
I define an environment variable at the top of my yaml file, and then I would like to change it on one of the job steps, and allow subsequent steps to see the changed value. However, the code below does not work. How can I fix this ? The $generator variable gets set correctly, but the github environment variable GENERATOR_PLATFORM remains empty for the next steps.

env:
  GENERATOR_PLATFORM:

 steps:
    - name: windows-dependencies
      if: startsWith(matrix.os, 'windows')
      run: |
         $generator= "-DCMAKE_GENERATOR_PLATFORM=x64"
        echo "Generator: ${generator}"
        echo "GENERATOR_PLATFORM=$generator" >> $GITHUB_ENV

   - name: Configure CMake
      shell: bash
      working-directory: ${{github.workspace}}/build
      run: cmake $GITHUB_WORKSPACE $GENERATOR_PLATFORM

You actually never overwrite the environment variable GENERATOR_PLATFORM with the following command:

echo "GENERATOR_PLATFORM=$generator" >> $GITHUB_ENV

You don’t specify a shell for that step, so it will be pwsh for a Windows runner. In PowerShell, you need to write $Env:GITHUB_ENV to access the GITHUB_ENV environment variable. $GITHUB_ENV isn’t defined, so the output ends up nowhere or perhaps in some file that does nothing. This should do the trick:

      run: |
        $generator = "-DCMAKE_GENERATOR_PLATFORM=x64"
        echo "Generator: ${generator}"
        echo "GENERATOR_PLATFORM=$generator" >> $Env:GITHUB_ENV

In your second step, you specify bash as shell, therefore you can access the environment variable with $GENERATOR_PLATFORM. If this was also PowerShell, then you would need to use $Env:GENERATOR_PLATFORM.