【问题标题】:Python automatic versioning not happening while running in github actions在 github 操作中运行时不会发生 Python 自动版本控制
【发布时间】:2020-11-08 02:29:50
【问题描述】:

成功构建后,我试图将包从 CI 直接推送到 pypi。 我已经尝试了几个工具,比如“setuptools-scm”,一切正常,我可以根据我在本地的标签(如package-0.0.2.post11-py3-none-any.whl)自动更改版本。

当我将相同的代码作为 github 操作的一部分推送时(命令 Run python3 setup.py sdist bdist_wheel),我看不到版本正在更新,我总是得到 package-0.0.0-py3-none-any.whl

下面是setup.py的sn-p

setuptools.setup(
    name="package",
    use_scm_version=True,
    setup_requires=['setuptools_scm']

yml 文件:

 publish:
    name: Build and publish Python ???? distributions ???? to PyPI and TestPyPI
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.8
      uses: actions/setup-python@v2
      with:
        python-version: 3.8
    - name: Install scm version
      run: >-
        python -m
        pip install
        setuptools-scm==4.1.2        
    - name: Install wheel
      run: >-
        python -m
        pip install
        wheel==0.34.2
    - name: Build a binary wheel and a source tarball
      run: >-
        python3 setup.py sdist bdist_wheel
    - name: Publish distribution ???? to Test PyPI
      uses: pypa/gh-action-pypi-publish@master
      with:
        password: ${{ secrets.test_pypi_password }}
        repository_url: https://test.pypi.org/legacy/
    - name: Publish distribution ???? to PyPI
      if: startsWith(github.ref, 'refs/tags')
      uses: pypa/gh-action-pypi-publish@master
      with:
        password: ${{ secrets.pypi_password }}

pyproject.toml

# pyproject.toml
[build-system]
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"]
[tool.setuptools_scm]
write_to = "pkg/version.py"

我不清楚我在这里做错了什么,有人可以帮忙解决这个问题吗?

谢谢

【问题讨论】:

  • 您是否也将标签推送到 GitHub?您的操作是否配置为运行on.push.tags
  • 是的,我正在 GitHub 上发布标签。我可以通过网络看到它。我已配置为在 push 而不是 on.push.tags 上运行。这会有所作为吗?

标签: python setuptools pypi github-actions python-3.8


【解决方案1】:

正如kbk 所说,默认情况下会签出 repo 的浅拷贝(一次提交)。除非最后一次提交有标签,否则基于标签的自动版本控制工具无法使用。

由于 actions/checkout 合并了 Pull Request #258 Fetch all history for all tags and branches when fetch-depth=0,您可以使用 fetch-depth: 0 选项和 actions/checkout@v2 来获取完整的历史记录(包括标签)并启用 setuptools-scm 以正确推断版本名称。

  steps:
  - uses: actions/checkout@v2
    with:
      fetch-depth: 0
  - name: Set up Python 3.8
    uses: actions/setup-python@v2
      with:
        python-version: 3.8

不幸的是,对于大型存储库,这可能会很慢,actions/checkout #249 有一个未解决的问题来解决这个问题。

【讨论】:

    【解决方案2】:

    - uses: actions/checkout@v2 操作在签出时未获取标签。必须另外添加以下行以从 git 获取标签

    publish:
        name: Build and publish Python ? distributions ? to PyPI and TestPyPI
        runs-on: ubuntu-18.04
        steps:
        - uses: actions/checkout@v2
        - name: Fetch all history for all tags and branches
          run: git fetch --prune --unshallow
        - name: Set up Python 3.8
          uses: actions/setup-python@v2
          with:
            python-version: 3.8
        - name: Install scm version
          run: >-
            python -m
            pip install
            versiontag      
        - name: Install wheel
          run: >-
            python -m
            pip install
            wheel==0.34.2
    

    【讨论】:

      猜你喜欢
      • 2021-03-01
      • 2019-10-11
      • 2022-01-06
      • 2020-03-11
      • 1970-01-01
      • 2016-04-04
      • 1970-01-01
      • 2021-08-29
      • 2019-07-22
      相关资源
      最近更新 更多