question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No support for Python packages versioning (PEP 440)

See original GitHub issue

Hi!

Thanks for the cool action! It works like a charm …as long as you are using semver.

Unfortunately in my case I wanted to use it for a Python package, which is versioned according to a pythonic standard - PEP440 - which is not semver-compatible.

I couldn’t just use type=match as in the case of the pre-release versions we should not add any other tags than the one with just the version itself.

Initially I wanted to create a PR to add support for PEP 440 to this project, but I don’t really know Typescript, so I ended up with writing it in, well, Python.

I would like to share this solution here for other people with such problem to find it and use this as a workaround and/or for someone to consider rewriting this in Typescript and making that PR. 😃

Anyway: happy hacking!

name: publish 🐳 Docker image

on:
  push:
    tags:
      - "v*"

jobs:

  build-and-push-image:

    runs-on: ubuntu-latest

    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Get tags
        shell: python
        run: |
          import re
          from packaging.version import parse

          version = "${{ github.ref }}".replace("refs/tags/v", "")
          image = "ghcr.io/${{ github.repository }}"

          tags = set()

          # full version
          tags.add(f"{image}:{version}")

          if not parse(version).is_prerelease:
              # only final and post-releases should get the tags
              # used for automatic use of latest *stable* version

              # major_version
              major_version = re.search(r'(\d+?)\.', version).group(1)
              tags.add(f"{image}:{major_version}")

              # major_version.minor_version
              major_and_minor_version = re.search(r'(\d+?\.\d+?)\.', version).group(1)
              tags.add(f"{image}:{major_and_minor_version}")

              tags.add(f"{image}:latest")

          tags = ",".join(sorted(list(tags)))

          print(f"::set-output name=tags::{tags}")

        id: tags

      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: .
          platforms: linux/amd64
          push: true
          tags: ${{ steps.tags.outputs.tags }}

(source: https://github.com/voxpupuli/puppetboard/commit/924bb55f02d06a4bcc1fd326449503170b412c97 + https://github.com/voxpupuli/puppetboard/commit/94052a0330b1e73963504a2a2fff9dbab52b2a87)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
crazy-maxcommented, Jul 6, 2021

@gdubicki @tillsteinbach You can test the type=pep440 with crazy-max/docker-metadata-action@pep440. Doc: https://github.com/crazy-max/docker-metadata-action/tree/pep440#typepep440

1reaction
tillsteinbachcommented, Jul 6, 2021

Ahrg! Yes, I was unconcentrated 😃 really nice work! Interestingly I did not notice my mistake because PyPi did the same correction to my version number 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 440 – Version Identification and Dependency Specification
This PEP describes a scheme for identifying versions of Python software distributions, and declaring dependencies on particular versions. This document ...
Read more >
python and PEP 440 - how serious is this warning about ...
It basically means that there is a module to identify version numbers (which ones are more recent, etc.) for tracking dependencies for PyPi...
Read more >
PEP 440 parse exception on packages in /usr/lib/python3/dist ...
I am on the latest Poetry version. I have searched the issues of this repo and believe that this is not a duplicate....
Read more >
5 Best Practices for Versioning Your Python Packages
Python's version identification and dependency specification (PEP 440) was created to support the existing versioning schemes and unify them ...
Read more >
pep440 - PyPI
A simple package with utils to check whether versions number match PEP 440.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found