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

Dynamic Versioning is not taking the tag in GitHub Actions #78

Closed
estyxx opened this issue May 17, 2022 · 9 comments
Closed

Dynamic Versioning is not taking the tag in GitHub Actions #78

estyxx opened this issue May 17, 2022 · 9 comments
Labels
question Further information is requested

Comments

@estyxx
Copy link

estyxx commented May 17, 2022

Hi

This is an amazing project and I would like to integrate in my little package, everything is working fine locally but when I run with GitHub actions it is taking the placeholder version 0.0.0...
I don't understand what I'm doing wrong... :(

this is the pyproject.toml

[tool.poetry]
name = "oktagon-python"
version = "0.0.0" # placeholder
...
[tool.poetry.dependencies]
...
poetry-dynamic-versioning = "^0.17.0" # <- also added here... 


...

[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "semver"

[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning"]
build-backend = "poetry.core.masonry.api"

The ci:

name: CI

on:
  push:
    branches:
      - main
  pull_request:
    branches: [main]

jobs:
  ...

  test-publish:
    name: Publish on test PyPI
    runs-on: ubuntu-latest
    needs: tests
    steps:

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

      - name: ✨ Install Poetry
        uses: abatilo/actions-poetry@v2.0.0
        with:
          poetry-version: "1.1.11"

      - name: 🐍 Install dependencies
        run: |
          pip install poetry-dynamic-versioning
          poetry install
        
      - name: 📦 Build package
        run: poetry build

      - name: Metadata
        id: metadata
        run: |
          echo '::echo::on'
          set +e
          echo $(poetry run dunamai from git --no-metadata --style semver)
          echo "::set-output name=commit::$(make hash)"

      - name: Publish release version on Test PyPI
        id: release
        env:
          OKTAGON_TEST_PYPI_TOKEN: ${{ secrets.OKTAGON_TEST_PYPI_TOKEN }}
        run: |
          echo '::echo::on'
          set +e
          make pre-release
          make build
          make publish-test
      
      - name: Create
        uses: peter-evans/create-or-update-comment@v1
        if: steps.check_release.outputs.release == ''
        with:
          issue-number: ${{ github.event.number }}
          body: |
            # Pre-release
            :wave:
            Pre-release **${{ steps.release.outputs.version }}** [${{ steps.metadata.outputs.commit }}] has been released on Test PyPi! :rocket:
            You can try it by doing:
            ```shell
            pip install --extra-index-url https://test.pypi.org/simple/ oktagon-python==${{ steps.release.outputs.version }}
            ```

but it will build the package with 0.0.0:

 poetry version 0.0.0-post.1+85f8701.dev.1652785204
Bumping version from 0.0.0-post.1+85f8701 to 0.0.0-post.1+85f8701.dev.1652785204
poetry build
Building oktagon-python (0.0.0-post.1+85f8701)
  - Building sdist
  - Built oktagon-python-0.0.0.post1+85f8701.tar.gz
  - Building wheel
  - Built oktagon_python-0.0.0.post1+85f8701-py3-none-any.whl

Can you help me understand why is not taking correctly the version from the tag that is 0.0.16 atm?

@mtkennerly
Copy link
Owner

Hi! By default, the workflow only downloads the latest commit without the rest of the history. That also means it won't know about any tags, unless the latest commit has one.

You can fix this by setting the following option:

- uses: actions/checkout@v2
  with:
    fetch-depth: 0

@estyxx
Copy link
Author

estyxx commented May 17, 2022

Mmmm, it's still 0.0.0....
The last commit doesn't have the tag and that could be the issue.... I wasn't expecting this to be a problem as there are tags on the repo the last tag on main branch is 0.0.16...
Should I create a tag for the prerelease in the GitHub action before building maybe?

Because this is the workflow that publishes on test PyPI, in the official release workflow I expect it to run when a tag is pushed, so in that case, it should be fine... 🤔

@estyxx
Copy link
Author

estyxx commented May 17, 2022

    * [new tag]         test                                     -> test
   * [new tag]         v0.0.10                                  -> v0.0.10
   * [new tag]         v0.0.11                                  -> v0.0.11
   * [new tag]         v0.0.12                                  -> v0.0.12
   * [new tag]         v0.0.13                                  -> v0.0.13
   * [new tag]         v0.0.14                                  -> v0.0.14
   * [new tag]         v0.0.15                                  -> v0.0.15
   * [new tag]         v0.0.16                                  -> v0.0.16
   * [new tag]         v0.0.8                                   -> v0.0.8
   * [new tag]         v0.0.9                                   -> v0.0.9

It has fetched the tag now, but still the version output is 0.0.0 🤔

@mtkennerly
Copy link
Owner

Could you share a link to the repository and branch? I took a guess and checked the oktagon-python branch improve-pipeline, but I don't see fetch-depth added there.

Also, with fetch-depth added, what's the exact version number you get? I'm particularly interested in the -post.N part.

@estyxx
Copy link
Author

estyxx commented May 18, 2022

Yeah sorry, I removed the changes yesterday to have something working for the time being.
I created a new PR here https://github.com/madedotcom/oktagon-python/pull/20 with the dynamic version tool :)

@mtkennerly
Copy link
Owner

mtkennerly commented May 18, 2022

Thanks, that makes more sense now. poetry version prerelease (triggered by your make pre-release) is reading the placeholder 0.0.0 version from pyproject.toml and then bumping the placeholder. When using this plugin, you should just run poetry build directly and let it update the version automatically, without using poetry version first.

@estyxx
Copy link
Author

estyxx commented May 18, 2022

I changed now, here and put everything into the GitHub action now, but still is trying to push 0.0.0 package somehow... 🤔

@mtkennerly
Copy link
Owner

Hmm, I see you're using pipx to install Poetry. I haven't tested it before, but based on the documentation, I think you'll need to run pipx inject poetry poetry-dynamic-versioning instead of the regular pip install poetry-dynamic-versioning. Basically, pipx installs Poetry in an isolated virtual environment, so you have to make sure the plugin gets installed in the same venv.

@mtkennerly
Copy link
Owner

mtkennerly commented May 19, 2022

Looks like switching to pip install got the dynamic version working 🎉

In regards to the new error from Poetry:

HTTP Error 400: '0.0.16.post45+4eaae2b' is an invalid value for Version. Error: Can't use PEP 440 local versions. See https://packaging.python.org/specifications/core-metadata for more information.

You can set metadata: false to exclude the +4eaae2b local segment.

Also, this may be intentional, but just in case: Since you're using the Semantic Versioning output, you have a .post segment and no .dev segment, which means that it would be considered a stable release and would be the default for Pip to install (e.g., Pip prefers 0.0.16.post1 over 0.0.16). If you'd like to keep 0.0.16 as the default install until 0.0.17 comes out, you could set style: "pep440" (the default), giving you 0.0.16.post45.dev0, and optionally also bump: true, giving you 0.0.17.dev45, which are both pre-releases and would require Pip's --pre flag.

@mtkennerly mtkennerly added the question Further information is requested label May 19, 2022
weiji14 added a commit to weiji14/zen3geo that referenced this issue Jun 7, 2022
Change from semver to PEP440 and remove the git hash part of the version string when uploading to TestPyPI. Based on mtkennerly/poetry-dynamic-versioning#78 (comment). Prevents errors like `'0.0.0.post15+f899e49' is an invalid value for Version. Error: Can't use PEP 440 local versions. See https://packaging.python.org/specifications/core-metadata for more information`.
weiji14 added a commit to weiji14/zen3geo that referenced this issue Jun 7, 2022
Building the binary wheel and source tarball packages with `poetry build` and publishing to TestPyPI and PyPI via GitHub Actions.

* 📦 Publish to TestPyPI and PyPI using GitHub Actions

Automating the binary wheel and source tarball publishing to TestPyPI and PyPI. Based on https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows but using `poetry` to do the build.

* 💚 Fix version string to be PEP440 compliant for TestPyPI

Change from semver to PEP440 and remove the git hash part of the version string when uploading to TestPyPI. Based on mtkennerly/poetry-dynamic-versioning#78 (comment). Prevents errors like `'0.0.0.post15+f899e49' is an invalid value for Version. Error: Can't use PEP 440 local versions. See https://packaging.python.org/specifications/core-metadata for more information`.

* 💬 Include TestPyPI installation instructions

So that people can get the latest development package from https://test.pypi.org/project/zen3geo. Also centering the title on the webpage.

* 💬 Update dev status from 1 planning to 3 alpha

Jumping two steps ahead, why drive when you can fly?
eigenein added a commit to kpn/cachetory that referenced this issue Feb 2, 2023
eigenein added a commit to kpn/cachetory that referenced this issue Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants