Skip to content

Commit

Permalink
Annotate task bundle if it has a migration
Browse files Browse the repository at this point in the history
STONEBLD-3026
  • Loading branch information
tkdchen committed Jan 17, 2025
1 parent c6dce55 commit 9261219
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions hack/build-and-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ build_push_task() {
local -r prepared_task_file=$2
local -r task_bundle=$3
local -r task_file_sha=$4
local -r has_migration=$5

local -r task_description=$(yq e '.spec.description' "$prepared_task_file" | head -n 1)

Expand All @@ -248,6 +249,9 @@ build_push_task() {
if [ -f "${task_dir}/USAGE.md" ]; then
ANNOTATIONS+=("dev.tekton.docs.usage=${VCS_URL}/tree/${VCS_REF}/${task_dir}/USAGE.md")
fi
if [ -n "$has_migration" ]; then
ANNOTATIONS+=("dev.konflux-ci.task.migration=true")
fi

local -a ANNOTATION_FLAGS=()
for annotation in "${ANNOTATIONS[@]}"; do
Expand Down Expand Up @@ -367,12 +371,7 @@ attach_migration_file() {
local -r task_dir=$1
local -r concrete_task_version=$2
local -r task_bundle=$3

local -r migration_file="${task_dir}/migrations/${concrete_task_version}.sh"

if [ ! -e "$migration_file" ]; then
return 0
fi
local -r migration_file=$4

# Check if task bundle has an attached migration file.
local filename
Expand Down Expand Up @@ -440,6 +439,7 @@ build_push_tasks() {
local task_file_sha
local task_bundle
local output
local has_migration

find task/*/* -maxdepth 0 -type d | awk -F '/' '{ print $0, $2, $3 }' | \
while read -r task_dir task_name task_version
Expand Down Expand Up @@ -467,21 +467,30 @@ build_push_tasks() {
read -r prepared_task_file task_file_sha task_bundle <<<"$build_data"
digest=$(fetch_image_digest "${task_bundle}-${task_file_sha}")

concrete_task_version=$(get_concrete_task_version "$prepared_task_file")
migration_file="${task_dir}/migrations/${concrete_task_version}.sh"

has_migration=false
if [ -f "$migration_file" ]; then
has_migration=yes
fi

if [ -n "$digest" ]; then
task_bundle_with_digest=${task_bundle}@${digest}
echo "info: use existing $task_bundle_with_digest" 1>&2
else
echo "info: push new bundle $task_bundle" 1>&2

output=$(build_push_task "$task_dir" "$prepared_task_file" "$task_bundle" "$task_file_sha")
output=$(build_push_task "$task_dir" "$prepared_task_file" "$task_bundle" "$task_file_sha" "$has_migration")

task_bundle_with_digest=$(grep -m 1 "^Pushed Tekton Bundle to" <<<"$output" 2>/dev/null)
task_bundle_with_digest=${task_bundle_with_digest##* }
cache_set "${task_bundle}-${task_file_sha}" "${task_bundle_with_digest#*@}"
fi

concrete_task_version=$(get_concrete_task_version "$prepared_task_file")
attach_migration_file "$task_dir" "$concrete_task_version" "$task_bundle_with_digest"
if [ "$has_migration" == "yes" ]; then
attach_migration_file "$task_dir" "$concrete_task_version" "$task_bundle_with_digest" "$migration_file"
fi

# version placeholder is removed naturally by the substitution.
echo "info: inject task bundle to pielines $task_bundle_with_digest" 1>&2
Expand Down

0 comments on commit 9261219

Please sign in to comment.