2

I have a github actions file that is supposed to overwrite the content of my version.py 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:

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [windows-2019, macos-10.15]
        include:
          - 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: \>
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ env.python-version }}
      uses: actions/setup-python@v2
      with:
        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/radio_sync_version.py
        echo "version = '${{ env.semver }}'" ${{ matrix.echo-version }} ./src/radio_sync_version.py
        get-content ./src/radio_sync_version.py
    - name: Run Tests
      run: |
        python -m unittest discover -v

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

  get-content ./src/radio_sync_version.py
  echo "version = '1.6.1.202'" out-file -encoding utf8 ./src/radio_sync_version.py
  get-content ./src/radio_sync_version.py
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
  env:
    semver: 1.6.1.202
    python-version: 3.8
    KIVY_GL_BACKEND: angle_sdl2
    pythonLocation: C:\hostedtoolcache\windows\Python\3.8.8\x64
version = 'DEVELOPMENT'
version = '1.6.1.202'
out-file
-encoding
utf8
./src/radio_sync_version.py
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: AssertionError: 'DEVELOPMENT' == 'DEVELOPMENT' 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: https://github.com/n2qzshce/ham-radio-sync

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?

Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45
n2qzshce
  • 23
  • 4

1 Answers1

1

Simply write to standard output and then redirect it to a file. This answer provides a simple recipe to help you do this in PowerShell; on Unix it's straight-forward.

You have to define the redirection properly for both shells:

# Windows
# echo-version: out-file -encoding utf-8 ./src/radio_sync_version.py
# ...
# Mac
# echo-version: ./src/radio_sync_version.py
# ...
- name: Write version file
  run: |
    echo "version = '${{ env.semver }}'" | ${{ matrix.echo-version }}
Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45
  • Thank you. The pipe'd output the way I had done it locally was working fine in powershell, but not on the remote box. – n2qzshce Apr 08 '21 at 22:02