Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only attach :latest tag to versioned images from main #5781

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
squash
Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro committed Jul 27, 2024
commit 51cfa7c53a1d9f4269caf4c715c3ee6739b9bd31
29 changes: 12 additions & 17 deletions scripts/compute-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,7 @@ GITHUB_SHA=${GITHUB_SHA:?'expecting GITHUB_SHA env var'}
# allow substituting for ggrep on Mac, since its default grep doesn't grok -P flag.
GREP=${GREP:-"grep"}

## If we are on a release tag, let's extract the version number.
## The other possible values are 'main' or another branch name.
if [[ $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
MAJOR_MINOR_PATCH=$(echo "${BRANCH}" | ${GREP} -Po "([\d\.]+)")
MAJOR_MINOR=$(echo "${MAJOR_MINOR_PATCH}" | awk -F. '{print $1"."$2}')
MAJOR=$(echo "${MAJOR_MINOR_PATCH}" | awk -F. '{print $1}')
else
MAJOR_MINOR_PATCH="latest"
MAJOR_MINOR=""
MAJOR=""
fi

# accumulate output in this variable
IMAGE_TAGS=""

# append given tag for docker.io and quay.io
Expand All @@ -40,14 +29,20 @@ tags() {
}

tags "${BASE_BUILD_IMAGE}"
tags "${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"

if [ "${MAJOR_MINOR}x" != "x" ]; then
tags "${BASE_BUILD_IMAGE}:${MAJOR_MINOR}"
fi
## If we are on a release tag, let's extract the version number.
## The other possible values are 'main' or another branch name.
if [[ $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
MAJOR_MINOR_PATCH=$(echo "${BRANCH}" | ${GREP} -Po "([\d\.]+)")
MAJOR_MINOR=$(echo "${MAJOR_MINOR_PATCH}" | awk -F. '{print $1"."$2}')
MAJOR=$(echo "${MAJOR_MINOR_PATCH}" | awk -F. '{print $1}')

if [ "${MAJOR}x" != "x" ]; then
tags "${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"
tags "${BASE_BUILD_IMAGE}:${MAJOR_MINOR}"
tags "${BASE_BUILD_IMAGE}:${MAJOR}"
tags "${BASE_BUILD_IMAGE}:latest"
elif [[ $BRANCH != "main" ]]; then
tags "${BASE_BUILD_IMAGE}:latest"
fi

tags "${BASE_BUILD_IMAGE}-snapshot:${GITHUB_SHA}"
Expand Down
21 changes: 15 additions & 6 deletions scripts/compute-tags.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,19 @@ out=""
expect() {
echo ' Actual:' "$out"
while [ "$#" -gt 0 ]; do
echo ' checking' "$1"
assertContains "actual !!$out!!" "$out" "--tag docker.io/$1"
assertContains "actual !!$out!!" "$out" "--tag quay.io/$1"
echo ' checking includes' "$1"
assertContains "actual [$out]" "$out" "--tag docker.io/$1"
assertContains "actual [$out]" "$out" "--tag quay.io/$1"
shift
done
}

expectNot() {
echo ' Actual:' "$out"
while [ "$#" -gt 0 ]; do
echo ' checking excludes' "$1"
assertNotContains "actual [$out]" "$out" "--tag docker.io/$1"
assertNotContains "actual [$out]" "$out" "--tag quay.io/$1"
shift
done
}
Expand All @@ -54,21 +64,20 @@ testRandomBranch() {

testMainBranch() {
out=$(BRANCH=main GITHUB_SHA=sha bash "$computeTags" foo/bar)
# TODO we do not want :latest tag in this scenario for non-snapshot images
expected=(
"foo/bar"
"foo/bar:latest"
"foo/bar-snapshot:sha"
"foo/bar-snapshot:latest"
)
expect "${expected[@]}"
expectNot "foo/bar:latest"
}

testSemVerBranch() {
out=$(BRANCH=v1.2.3 GITHUB_SHA=sha bash "$computeTags" foo/bar)
# TODO we want :latest tag in this scenario, it's currently not produced
expected=(
"foo/bar"
"foo/bar:latest"
"foo/bar:1"
"foo/bar:1.2"
"foo/bar:1.2.3"
Expand Down
Loading