Created
June 22, 2022 04:40
-
-
Save hongkongkiwi/6f25010ba19d1eeaa0197222ec0c3fea to your computer and use it in GitHub Desktop.
One liner to format a git tag / branch name appropriately for a docker tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Replace any non valid characters with dash | |
# 2. Remove any .- from start of name | |
# 3. Replace duplicate dash with a single one | |
# 3. Replace duplicate underscore with a single one | |
# 4. Replace duplicate dot with a single one | |
# 5. Truncate string to 128 chars (or less) | |
sed -e 's/[^[:alnum:]\.\_\-]/-/g' \ | |
-e 's|^[.-]\+||g' \ | |
-e 's|-\+|-|g' \ | |
-e 's|_\+|_|g' \ | |
-e 's|\.\+|.|g' \ | |
-e 's/^\(.\{128\}\).*/\1/' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment