Actions completely stops working: "The directory name is invalid" after vcvars setup

I have an action that I use to build my CMake/Ninja project on Windows. Because CMake needs the compilers and tools provided by Visual Studio, I have added the following to my env (with shell: bash) to run before my CMake and Ninja steps:

    VSPATH="$("C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -property installationPath | tr -d '\r\n')"
    exec cmd.exe /c "\"$VCVARS\" x64 & powershell"

This finds vcvarsall.bat and replaces bash with a PowerShell environment already set up with the necessary environment variables. (I know about Visual Studio’s Developer PowerShell, but at the moment that sets up the environment variables for the x86 tools.)

I have tested this setup on my own computer in Git Bash, and this works fine. However, when it runs in my action, I get an error. All of the other steps in my action run fine, but here the last two steps (and the only two that use the dev shell):

- name: 'Build'
  working-directory: ${{ github.workspace }}
  shell: bash
  run: |
    ${{ env.DEVSHELL }}
    cmake ...

- name: 'Compile and Link'
  working-directory: ${{ github.workspace }}/build
  shell: bash
  run: |
    ${{ env.DEVSHELL }}

The “Build” step runs without error. However, the “Compile and Link” step immediately fails with the (somewhat cryptic) error message Error: The directory name is invalid.

I initially thought it was an error setting up the dev shell, and so I replaced the entire run section to simply run echo "test". The action still gives the error message, before “test” is even printed. This leads me to believe that there is a problem setting up the bash shell.

However, even if I (leaving the single echo command) change the shell powershell, I still get the error. It seems like something about my dev shell setup fundamentally breaks the GitHub Actions runner and I have no idea why.