在成功构建之后,我尝试将包从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的代码片段
setuptools.setup(
name="package",
use_scm_version=True,
setup_requires=['setuptools_scm']ymlfile:
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"我不清楚我做错了什么,有人能帮我解决这个问题吗?
谢谢
发布于 2020-07-19 18:54:11
检出时,操作- 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-08-27 21:02:18
正如kbk所说,默认情况下会签出存储库的浅拷贝(一次提交)。除非最后一次提交有标记,否则基于标记的自动版本控制工具将无法使用。
由于actions/checkout合并了拉取请求#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有一个开放的问题来解决这个问题。
https://stackoverflow.com/questions/62968271
复制相似问题