Skip to content

Commit

Permalink
fix: Include branch in generate-metadata version (#23)
Browse files Browse the repository at this point in the history
* Convert to lowercase when normalizing branch/ref names
* Fix inconsistent indent
* fix: set version = tag. Reduce confusion on values

Co-authored-by: Jason Greathouse <[email protected]>
  • Loading branch information
remoun and jgreat authored Dec 2, 2022
1 parent 5128782 commit 84c58dc
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions util/metadata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ export TMPDIR=".tmp"

is_set()
{
var_name="${1}"
var_name="${1}"

if [[ -z "${!var_name}" ]]; then
echo "${var_name} is not set." >&2
exit 1
fi
if [[ -z "${!var_name}" ]]; then
echo "${var_name} is not set." >&2
exit 1
fi
}

normalize_ref_name()
{
# Remove prefix, convert delimiters to dashes, and strip trailing dashes.
echo "${1}" | sed -Ee 's!^(feature|release)/!!' | sed -e 's![._/]!-!g' | sed -e 's!-*$!!'
# Remove prefix, convert delimiters to dashes, lowercase, and strip trailing dashes.
echo "${1}" | \
sed -Ee 's!^(feature|release)/!!' | \
sed -e 's![._/]!-!g' | \
tr '[:upper:]' '[:lower:]' | \
sed -e 's!-*$!!'
}

base_prefix()
Expand Down Expand Up @@ -122,7 +126,7 @@ EOF
echo "Before: '${branch}'"
echo "After: '${normalized_branch}'"

# Set artifact tag
# Set version and artifact tags
tag="${version}-${normalized_branch}.${GITHUB_RUN_NUMBER}.${sha}"
# Set docker metadata action compatible tag
docker_tag="type=raw,value=${tag}"
Expand All @@ -136,8 +140,9 @@ EOF
esac

# Set GHA output vars
# Make version output as tag. Maybe remove from output later to reduce confusion.
cat <<EOO >> "${GITHUB_OUTPUT}"
version=${version}
version=${tag}
namespace=${namespace}
sha=${sha}
tag=${tag}
Expand Down

0 comments on commit 84c58dc

Please sign in to comment.