【问题标题】:Github actions is not overwriting project file contentsGithub 操作不会覆盖项目文件内容
【发布时间】:2021-06-29 15:32:40
【问题描述】:

我有一个 github 操作文件,它应该用 env.semver 中指定的当前版本覆盖我的 version.py 的内容 盒子在windows-2019上运行。

写入版本文件步骤发生在运行单元测试之前和安装依赖项之后:

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

这是写入版本文件的输出:

  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'

我有一个构建测试来验证DEVELOPMENT 最终不是作为版本,即使这是签入代码的版本,但它失败了: AssertionError: 'DEVELOPMENT' == 'DEVELOPMENT' 我相当确信问题不在于环境变量,因为该部分并未因此更改而改变,并且一直在努力自动命名构建的可执行文件。

项目位于:https://github.com/n2qzshce/ham-radio-sync

工作分支是validation_version-alerts_rownums

我读到可以在 Github 操作框中写入文件,我什至在其他步骤中这样做。我遗漏了什么,为什么我不能覆盖我的版本文件?

【问题讨论】:

    标签: bash powershell github-actions


    【解决方案1】:

    只需写入标准输出,然后将其重定向到文件。 This answer 提供了一个简单的方法来帮助您在 PowerShell 中执行此操作;在 Unix 上它是直截了当的。

    您必须为两个 shell 正确定义重定向:

    # 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 }}
    

    【讨论】:

    • 谢谢。管道的输出方式与我在本地完成的方式在 powershell 中工作正常,但在远程机器上却没有。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    • 2020-07-09
    • 1970-01-01
    • 2019-10-05
    • 2017-09-20
    • 2011-08-29
    • 2021-12-28
    相关资源
    最近更新 更多