Visitar URL original
Increasing short commit hash length is a breaking change · Issue #479 · docker/metadata-action · GitHub
Skip to content

Increasing short commit hash length is a breaking change #479

Closed

Description

@RobinDaugherty

Contributing guidelines

I've found a bug, and:

  • The documentation does not mention anything about my problem
  • There are no open or closed issues that are related to my problem

Description

#467 increased the default length of the commit hash created by the sha directive

This was released in v5.6.0 which made it immediately apply to everyone whose workflow specified release v5 in their actions.

This change unfortunately broke my workflows, because other parts of our workflows were hard-coded to match the size of the tags created by this action.

Please consider pulling this release and re-releasing it as v6.

Expected behaviour

v5 creates short "sha" tags with 7-character commit hash

Actual behaviour

v5 suddenly creates short "sha" tags with 12-character commit hash

Repository URL

No response

Workflow run URL

No response

YAML workflow

- name: Docker image metadata
  id: metadata
  uses: docker/metadata-action@v5
  with:
    images: |
      ${{ steps.ghcr_image_name.outputs.name }}
    tags: |
      type=ref,event=branch
      type=ref,event=pr
      type=semver,pattern={{major}}.{{minor}}.{{patch}}
      type=sha

- name: Get deployment tag
  id: get_deployment_tag
  # The following variables are made available to subsequent jobs to be used to find the specific Docker image that was built and pushed by this job.
  run: |
    echo "deployment_tag=sha-$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
    echo "build_image=${{ steps.ghcr_image_name.outputs.name }}:sha-$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT

Workflow logs

No response

BuildKit logs


Additional info

No response

Activity

  1. housejester commented on Nov 19, 2024

    @housejester

    Came here to post the same. Good news is that there is the ENV you can set to get it working again, but feels like it could have kept the default until a more major version bump.

    Workaround is to add the env to the action:

            env:
              DOCKER_METADATA_SHORT_SHA_LENGTH: 7
    
  2. crazy-max commented on Nov 19, 2024

    @crazy-max
    Member

    This change unfortunately broke my workflows,

    Please consider pulling this release and re-releasing it as v6.

    I guess in your case it breaks for deployment_tag and build_image because you rely on github.sha instead of metadata outputs. I don't think this is a breaking change as you don't rely on metadata outputs imo.

    You can either enforce commit sha length with DOCKER_METADATA_SHORT_SHA_LENGTH env var:

    - name: Docker image metadata
      id: metadata
      uses: docker/metadata-action@v5
      with:
        images: |
          ${{ steps.ghcr_image_name.outputs.name }}
        tags: |
          type=ref,event=branch
          type=ref,event=pr
          type=semver,pattern={{major}}.{{minor}}.{{patch}}
          type=sha
      env:
        DOCKER_METADATA_SHORT_SHA_LENGTH: 7

    Or rely on the actual metadata outputs https://github.com/docker/metadata-action?tab=readme-ov-file#outputs to get a usable tag like version with ${{ steps.metadata.outputs.version }}

  3. housejester commented on Nov 19, 2024

    @housejester

    This change unfortunately broke my workflows,

    Please consider pulling this release and re-releasing it as v6.

    I guess in your case it breaks for deployment_tag and build_image because you rely on github.sha instead of metadata outputs. I don't think this is a breaking change as you don't rely on metadata outputs imo.

    You can either enforce commit sha length with DOCKER_METADATA_SHORT_SHA_LENGTH env var:

    • name: Docker image metadata
      id: metadata
      uses: docker/metadata-action@v5
      with:
      images: |
      ${{ steps.ghcr_image_name.outputs.name }}
      tags: |
      type=ref,event=branch
      type=ref,event=pr
      type=semver,pattern={{major}}.{{minor}}.{{patch}}
      type=sha
      env:
      DOCKER_METADATA_SHORT_SHA_LENGTH: 7

    Or rely on the actual metadata outputs https://github.com/docker/metadata-action?tab=readme-ov-file#outputs to get a usable tag like version with ${{ steps.metadata.outputs.version }}

    In my case, i use a different action for rendering k8s yamls (skaffold...and yeah, i don't like skaffold), and for that tool, I cannot (easily) configure/pass in the sha...it has its own internal opinion about what a short sha is. I get that probably isn't common, but wanted the team to be aware it /is/ breaking peoples flows, and a safer approach would have been to not change a default in a non-major version bump.

  4. crazy-max commented on Nov 19, 2024

    @crazy-max
    Member

    The previous version relying on hardcoded short commit sha to length 7 is a bug on its own as it would be unreliable for huge repositories.

    As stated in git documentation: https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---shortltlengthgt

    The minimum length is 4, the default is the effective value of the core.abbrev configuration variable

    core.abbrev: If unspecified or set to "auto", an appropriate value is computed based on the approximate number of packed objects in your repository, which hopefully is enough for abbreviated object names to stay unique for some time.

    So it defaults to 4 but based on repo size can be higher.

    We choose 12 as it seems a good defaults which is what Go modules use when computing untagged dependencies.

  5. crazy-max commented on Nov 19, 2024

    @crazy-max
    Member

    I'm going to set the defaults back to 7 but keep the environment variable for people who want to rely on a higher value.

  6. crazy-max commented on Nov 19, 2024

    @crazy-max
    Member

    Should be good with latest patch release. Let us know if that fixes the issue on your side 🙏

  7. housejester commented on Nov 19, 2024

    @housejester

    Thanks @crazy-max . I've tested and can confirm the latest works w/o the ENV. (i'm planning to keep the ENV specified moving forward, fwiw).

  8. RobinDaugherty commented on Nov 20, 2024

    @RobinDaugherty
    Author

    Thank you @crazy-max!

    I agree that increasing the default from 7-characters is desirable. In my case we don't really need the shortened hash, so I took the opportunity to switch to the full length, using:

    type=sha,format=long
    
  9. added this to the v6 milestone on Nov 4, 2025
  10. crazy-max commented on Nov 4, 2025

    @crazy-max
    Member

    Will make commit hash length to 12 the default on next major v6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions