docker / metadata-action

GitHub Action to extract metadata (tags, labels) from Git reference and GitHub events for Docker
https://github.com/marketplace/actions/docker-metadata-action
Apache License 2.0
892 stars 115 forks source link

Automatically Tag Latest Official Version with 'latest' in Docker Repository Based on Semantic Versioning #407

Open Gezi-lzq opened 4 months ago

Gezi-lzq commented 4 months ago

Feature Request

Problem Statement

Our current release process does not automatically adjust the latest tag to the most recent official version based on semantic versioning. This limitation arises from our unique git workflow, where:

Proposed Solution

  1. Detects when a release is triggered by a tag.
  2. Verifies that the tag follows the SemVer standard.
  3. Compares the tagged version against all existing versions in the repository to determine if it is the highest.
  4. If the tagged version is the highest based on SemVer, automatically tags the image with latest.
[Tag Release] ---> [Check if SemVer] ---> [Compare Versions] ---> [Is highest version?] ---> [Tag as 'latest']

(We have not found existing documentation or capabilities within our current toolset that meet this specific need.Additionally, I'm unsure if my idea above constitutes a valid requirement. I would appreciate some feedback on its viability. If deemed reasonable, I'm willing to implement this feature.)

crazy-max commented 3 months ago

Compares the tagged version against all existing versions in the repository to determine if it is the highest.

I wonder why you would need this at all? I guess you maintain n and n-1 versions of your project or more right? Such as v1.9.0 patch releases and v1.10.0. In such case you could just have an env in your workflow that would be the latest version digits like:

env:
  LATEST_VERSION: v1.10

And then you could just compare any tag to it by using semver comparison with https://github.com/npm/node-semver and https://github.com/actions/github-script in a dedicated step to set latest as new env for the metadata-action.

Or I guess this would be fine to create a new global expression to handle this and remove extra overhead in your workflow.

Gezi-lzq commented 2 months ago

Compares the tagged version against all existing versions in the repository to determine if it is the highest.

I wonder why you would need this at all? I guess you maintain n and n-1 versions of your project or more right? Such as v1.9.0 patch releases and v1.10.0. In such case you could just have an env in your workflow that would be the latest version digits like:

env:
  LATEST_VERSION: v1.10

And then you could just compare any tag to it by using semver comparison with https://github.com/npm/node-semver and https://github.com/actions/github-script in a dedicated step to set latest as new env for the metadata-action.

Or I guess this would be fine to create a new global expression to handle this and remove extra overhead in your workflow.

Thank you for your suggestion on setting an environment variable for the latest version and using semver comparison with GitHub-script in the workflow. However, I am looking for a solution that does not require manual updates to the workflow file each time a new version is released. To achieve this, I plan to use the following approach:

LATEST_TAG=$(git fetch --tags && git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)

This command will automatically fetch all tags, sort them in descending order according to semantic versioning, filter them to match the semantic versioning pattern, and then select the top one as the latest official version tag. ...