Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tox -e build does not find version number in GitHub actions #732

Closed
rkingsbury opened this issue Aug 22, 2023 · 2 comments
Closed

tox -e build does not find version number in GitHub actions #732

rkingsbury opened this issue Aug 22, 2023 · 2 comments
Labels
waiting response/feedback Blocked while waiting information/feeback from the issue/PR/discussion author.

Comments

@rkingsbury
Copy link

Description of your problem

I can run tox -e build locally and it correctly builds wheels with the correct package version number. However, when I use GitHub actions to build my package, it does not identify the version number, instead resulting in version number such as 0.0.post1.dev1+g0d1df5e, which prevents subsequent publishing to PyPi. See example run

Clearly I have missed an important step when configuring my build environment on GitHub actions, but I can't figure out what it is. Help appreciated!

Contents of release.yml defining the GitHub action

name: release

on:
  release:
    types: [published]

  workflow_dispatch:

jobs:
  # https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes

  deploy:
    name: Upload release to PyPI
    runs-on: ubuntu-latest
    environment:
      name: publish
      url: https://pypi.org/p/pyEQL

    permissions:
      id-token: write  # IMPORTANT: this permission is mandatory for trusted publishing

    steps:
    - uses: actions/checkout@v3

    - uses: actions/setup-python@v4
      with:
        python-version: "3.10"


    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools setuptools_scm wheel tox

    - name: Build packages for distribution
      run: |
        pipx run tox -e clean,build

    - name: Upload to PyPi
      uses: pypa/gh-action-pypi-publish@v1.8.8

**relevant sections of tox.ini **

# Tox configuration file
# Read more under https://tox.readthedocs.org/
# THIS SCRIPT IS SUPPOSED TO BE AN EXAMPLE. MODIFY IT ACCORDING TO YOUR NEEDS!

[tox]
minversion = 3.15
envlist = {py38,py39,py310,py11}-{linux,windows,macos}


[testenv]
description = invoke pytest to run automated tests
isolated_build = True
setenv =
    TOXINIDIR = {toxinidir}
passenv =
    HOME
extras =
    testing
commands =
    pytest {posargs}


[testenv:{clean,build}]
description =
    Build (or clean) the package in isolation according to instructions in:
    https://setuptools.readthedocs.io/en/latest/build_meta.html#how-to-use-it
    https://github.com/pypa/pep517/issues/91
    https://github.com/pypa/build
# NOTE: build is still experimental, please refer to the links for updates/issues
skip_install = True
changedir = {toxinidir}
deps =
    build: build[virtualenv]
commands =
    clean: python -c 'from shutil import rmtree; rmtree("build", True); rmtree("dist", True)'
    build: python -m build .
# By default `build` produces wheels, you can also explicitly use the flags `--sdist` and `--wheel`

# # To run `tox -e lint` you need to make sure you have a
# # `.pre-commit-config.yaml` file. See https://pre-commit.com
[testenv:lint]
description = Perform static analysis and style checks
skip_install = True
deps = pre-commit
passenv =
    HOMEPATH
    PROGRAMDATA
commands =
    pre-commit run --all-files #{posargs:--show-diff-on-failure}

Please provide the full traceback using the --very-verbose flag.
See GitHub action failed run

Versions and main components

  • PyScaffold Version: 4.5
  • Python Version: 3.10
  • How did you install PyScaffold: pip
@abravalheri
Copy link
Collaborator

abravalheri commented Aug 22, 2023

Hi @rkingsbury, I wonder if you need to specify fetch-tags: true of fetch-depth: 0 for the actions/checkout step so that setuptools-scm can use the VCS information to infer the version... Have you tried that?

You can have a look on https://github.com/pyscaffold/pyscaffold/blob/master/src/pyscaffold/templates/github_ci_workflow.template to see how we do that in the Github Actions template.

@abravalheri abravalheri added the waiting response/feedback Blocked while waiting information/feeback from the issue/PR/discussion author. label Aug 22, 2023
@rkingsbury
Copy link
Author

Hi @rkingsbury, I wonder if you need to specify fetch-tags: true of fetch-depth: 0 for the actions/checkout step so that setuptools-scm can use the VCS information to infer the version... Have you tried that?

You can have a look on https://github.com/pyscaffold/pyscaffold/blob/master/src/pyscaffold/templates/github_ci_workflow.template to see how we do that in the Github Actions template.

Thank you @abravalheri , this seems to have fixed it! Although actually the tag-fetching behavior of actions/checkout is the subject of an active issue: actions/checkout#701 , and setting fetch-tags: true by itself did not work. So in the end, I just set fetch-depth: 0

steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting response/feedback Blocked while waiting information/feeback from the issue/PR/discussion author.
Projects
None yet
Development

No branches or pull requests

2 participants