Skip to content

Option to add hash to Slugs #173

@hexa2k9

Description

@hexa2k9

Is your feature request related to a problem? Please describe.

We rely on slugs a lot for various use cases (Docker Image Tags, FS Directories, branch names for automation, ...) but with the current implementation (we rely on GITHUB_REF_POINT most of the time) the sluggified version can lead to collisions in naming.

Describe the solution you'd like

I would love to see an input to optionally append a hash into the final slugged string so something like feature/some-random-branch-name-with-some-very-long-name-which-will-be-sluggified could become feature-some-random-branch-name-with-some-very-long-nam-cd4df5 instead of "just cutting it" into feature-some-random-branch-name-with-some-very-long-name-which.

Hash length could be defaulting to 8 characters taking sha1 into consideration it should be safe enough eventually.

Describe alternatives you've considered

I'm currently using the following workaround which feels a bit hacky and doesn't really do the job for short branch names (eg. main) as appending the hash isn't really required for those (it'll consistently result in main-19b01681 but it's not required):

- name: Slugify GitHub Environment Variables
  uses: rlespinasse/github-slug-action@v5
  with:
    prefix: 'CI_'
    slug-maxlength: '54'

- name: Append hash to CI_GITHUB_REF_POINT
id: hashed_head_ref
run: |
  if [[ $(echo ${{ env.CI_GITHUB_REF_POINT_SLUG }} | wc -c | awk '{print $1}') -ge 54 ]]; then
    echo hashed_head_ref="${{ env.CI_GITHUB_REF_POINT_SLUG }}-$(echo ${{ env.CI_GITHUB_REF_POINT }} | sha1sum | cut -c 1-8)" >> $GITHUB_OUTPUT
  else
    echo hashed_head_ref="${{ env.CI_GITHUB_REF_POINT_SLUG }}" >> $GITHUB_OUTPUT
  fi

(edited for clarity/workaround improvements)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions