No support for Python packages versioning (PEP 440)
See original GitHub issueHi!
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:
- Created 2 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
@gdubicki @tillsteinbach You can test the
type=pep440
withcrazy-max/docker-metadata-action@pep440
. Doc: https://github.com/crazy-max/docker-metadata-action/tree/pep440#typepep440Ahrg! Yes, I was unconcentrated 😃 really nice work! Interestingly I did not notice my mistake because PyPi did the same correction to my version number 😄