Update Longhorn Repository Branch Image Tags #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ inputs.branch }} | |
- name: Prepare packages | |
run: sudo apt update -y ; sudo apt install -y snapd; sudo snap install yq | |
- name: Update repo branch image tags in deploy/longhorn-images.txt | |
run: | | |
set -o errexit | |
set -o xtrace | |
tag=${{ inputs.tag }} | |
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 | |
} | |
replace_images_tags_in_longhorn_images_txt "deploy/longhorn-images.txt" "$tag" | |
- name: Update repo branch image tags in chart/values.yaml | |
run: | | |
yq eval '.image.longhorn.engine.tag = "${{ inputs.tag }}"' -i chart/values.yaml | |
yq eval '.image.longhorn.manager.tag = "${{ inputs.tag }}"' -i chart/values.yaml | |
yq eval '.image.longhorn.ui.tag = "${{ inputs.tag }}"' -i chart/values.yaml | |
yq eval '.image.longhorn.instanceManager.tag = "${{ inputs.tag }}"' -i chart/values.yaml | |
yq eval '.image.longhorn.shareManager.tag = "${{ inputs.tag }}"' -i chart/values.yaml | |
yq eval '.image.longhorn.backingImageManager.tag = "${{ inputs.tag }}"' -i chart/values.yaml | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} | |
branch: "update-image-tags-${{ inputs.branch }}" | |
commit-message: "chore: update image tags for branch ${{ inputs.branch }}" | |
title: "chore: update image tags for branch ${{ inputs.branch }}" | |
body: | | |
This PR updates the image tags for branch ${{ inputs.branch }} to ${{ inputs.tag }}. |