Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit committed Jan 8, 2025
1 parent 5ab862a commit 3f57914
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/update-branch-image-versions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Update Longhorn Repository Branch Image Tags

on:
workflow_dispatch:
inputs:
branch:
description: "Branch, ex: v1.7.x"
required: true
tag:
description: "Tag, ex: v1.7.x-head"
required: true

defaults:
run:
shell: bash

jobs:
release:
runs-on: ubuntu-latest

env:
GITHUB_TOKEN: ${{ secrets.GH_ACTION_TOKEN }}

steps:
- name: Setup Git
run: |
gh auth setup-git
- uses: actions/checkout@v4

- name: Update repo branch image tags
run: ./scripts/update-repo-branch-image-tags.sh ${{ inputs.branch }} ${{ inputs.tag }}

- name: Commit and Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
branch: "update-image-tags-${{ inputs.branch }}"
commit-message: "chore: update image tags in deploy/longhorn-images.txt"
title: "Update image tags for branch ${{ inputs.branch }}"
body: |
This PR updates the image tags in `deploy/longhorn-images.txt` to use the tag `${{ inputs.tag }}`.
labels: |
automation
74 changes: 74 additions & 0 deletions .github/workflows/update-repo-branch-image-tags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

set -o errexit
set -o xtrace

if [ "$#" -ne 2 ]; then
echo "Illegal number of arguments. branch and tag are required." >/dev/stderr
exit 1
fi

branch=$1
tag=$2

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 <input_file> <tag>"
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

git checkout "$branch"

replace_images_tags_in_longhorn_images_txt "deploy/longhorn-images.txt" "${tag}"

popd

0 comments on commit 3f57914

Please sign in to comment.