From 496479079a8e9c75603af4ca4d6b483975fbd560 Mon Sep 17 00:00:00 2001 From: Derek Su Date: Wed, 8 Jan 2025 16:27:26 +0800 Subject: [PATCH] WIP Signed-off-by: Derek Su --- .../update-branch-image-versions.yaml | 4 +- .github/workflows/update-repo-image-tags.sh | 71 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/update-repo-image-tags.sh diff --git a/.github/workflows/update-branch-image-versions.yaml b/.github/workflows/update-branch-image-versions.yaml index d095876f7f..421885e386 100644 --- a/.github/workflows/update-branch-image-versions.yaml +++ b/.github/workflows/update-branch-image-versions.yaml @@ -20,9 +20,11 @@ jobs: steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} - name: Update repo branch image tags - run: bash ./.github/workflows/update-repo-branch-image-tags.sh ${{ inputs.branch }} ${{ inputs.tag }} + run: bash ./.github/workflows/update-repo-image-tags.sh ${{ inputs.tag }} - name: Create Pull Request uses: peter-evans/create-pull-request@v7 diff --git a/.github/workflows/update-repo-image-tags.sh b/.github/workflows/update-repo-image-tags.sh new file mode 100644 index 0000000000..40150454c6 --- /dev/null +++ b/.github/workflows/update-repo-image-tags.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +set -o errexit +set -o xtrace + +if [ "$#" -ne 1 ]; then + echo "Illegal number of arguments. tag is required." >/dev/stderr + exit 1 +fi + +tag=$1 + +repos_dir=.repos + +images=( + longhornio/backing-image-manager + longhornio/longhorn-engine + longhornio/longhorn-instance-manager + longhornio/longhorn-manager + longhornio/longhorn-share-manager + longhornio/longhorn-ui + longhornio/longhorn-cli +) + +function replace_images_tags_in_longhorn_images_txt() { + local input_file="$1" + local tag="$2" + + local output_file="${input_file}.new" + + if [ -z "$input_file" ] || [ -z "$tag" ]; then + echo "Usage: replace_longhorn_images " + return 1 + fi + + while IFS= read -r line; do + modified=false + for img in "${images[@]}"; do + if [[ "$line" == *"$img"* ]]; then + if [[ "$line" =~ $img(:[^ ]*)? ]]; then + line=$(echo "$line" | sed -E "s|$img(:[^ ]*)?|$img:$tag|") + modified=true + break + fi + fi + done + echo "$line" >> "$output_file" + done < "$input_file" + + if [ $? -eq 0 ]; then + mv "$output_file" "$input_file" + echo "Successfully replaced Longhorn image tags in '$input_file'." + else + rm -f "$output_file" + echo "Error: Failed to replace Longhorn image tags." + return 1 + fi +} + +function teardown() { + rm -rf $repos_dir +} +trap teardown EXIT + +mkdir -p $repos_dir + +pushd $repos_dir + +replace_images_tags_in_longhorn_images_txt "deploy/longhorn-images.txt" "${tag}" + +popd