Github actions is not overwriting project file contents

I have a github actions file that is supposed to overwrite the content of my with the current version specified in the env.semver
The box is running on windows-2019.

The write version file step takes place right before running the unit tests and after installing dependencies:

    runs-on: ${{ matrix.os }}
      fail-fast: false
        os: [windows-2019, macos-10.15]
          - os: windows-2019
            exe-extension: .exe
            short-name: win
            move-command: move
            echo-version: out-file -encoding utf8
          - os: macos-10.15
            exe-extension: .app
            short-name: osx
            move-command: mv
            echo-version: \>
    - uses: actions/checkout@v2
    - name: Set up Python ${{ env.python-version }}
      uses: actions/setup-python@v2
        python-version: ${{ env.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install -r requirements.txt
    - name: Write version file
      run: |
        get-content ./src/
        echo "version = '${{ env.semver }}'" ${{ matrix.echo-version }} ./src/
        get-content ./src/
    - name: Run Tests
      run: |
        python -m unittest discover -v

And here’s the output of the write version file:

  get-content ./src/
  echo "version = ''" out-file -encoding utf8 ./src/
  get-content ./src/
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
    python-version: 3.8
    KIVY_GL_BACKEND: angle_sdl2
    pythonLocation: C:\hostedtoolcache\windows\Python\3.8.8\x64
version = 'DEVELOPMENT'
version = ''
version = 'DEVELOPMENT'

I have a build test that verifies that DEVELOPMENT does not end up as the version, even though that is the one that is checked in to the code, and it is failing:
I am fairly confident the issue isn’t the environment variable, as that part was not altered with this change, and has been working to automatically name the built executables.

Project is located here: GitHub - n2qzshce/ham-radio-sync: A project to synchronize multiple different brands of radios to a common channel list.

Working branch is validation_version-alerts_rownums

I’ve read that it’s possible to write files on a Github actions box, and I am even doing it in other steps. What am I missing and why can I not overwrite my version file?

What appears to happen is that you echo several strings:

  • version = ''
  • out-file
  • -encoding
  • utf8
  • ./src/

Looking at your command, that is actually what you ask PowerShell to do:
echo "version = ''" out-file -encoding utf8 ./src/
The unquoted whitespace in the command is implicit string boundaries.

You missed the pipe operator | to make this write the version number to the file:
echo "version = ''" | out-file ...

In the linked repository, I see that you fixed this already:
${{ '|' }} out-file -encoding utf-8 ./src/

I have two recommendations:

  • Don’t work around YAML syntax using GitHub Actions expressions and instead use this:
    version-command: >-
      | out-file -encoding utf-8 ./src/
    version-command: >-
      > ./src/
    See for an interactive explanation.
  • As long as you use the default shell of Windows runners, which is PowerShell Core (pwsh), you can use the > operator like on macOS instead of | Out-File -Encoding utf-8 because UTF-8 is the default in pwsh unlike in classic PowerShell.