-
Notifications
You must be signed in to change notification settings - Fork 1
/
updater.sh
executable file
·60 lines (48 loc) · 1.56 KB
/
updater.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# Check if the correct number of arguments are provided
if [ "$#" -lt 3 ]; then
echo "Usage: $0 <path-to-yaml-file> <current-version> <new-version> [<new-version> ...]"
exit 1
fi
# Assign arguments to variables
yaml_file=$1
current_version=$2
shift 2
new_versions=("$@")
# Validate the YAML file exists
if [ ! -f "$yaml_file" ]; then
echo "File not found: $yaml_file"
exit 1
fi
# Original image pattern to search
original_image="gcr.io/heptio-images/ks-guestbook-demo:$current_version"
# Loop through each new version and update the image
for new_version in "${new_versions[@]}"; do
# New image tag
new_image="gcr.io/heptio-images/ks-guestbook-demo:$new_version"
# Replace the image in the YAML file
sed -i.bak "s|$original_image|$new_image|" "$yaml_file"
# Check if the replacement was successful
if grep -q "$new_image" "$yaml_file"; then
echo "Updated image to $new_image in $yaml_file"
else
echo "Failed to update image to $new_image in $yaml_file"
exit 1
fi
# Add changes to git
git add "$yaml_file"
# Commit the changes
commit_message="$yaml_file Updated image in $yaml_file to $new_image"
git commit -m "$commit_message"
# Push the changes
git push
# Provide feedback
if [ $? -eq 0 ]; then
echo "Changes pushed successfully for version $new_version."
else
echo "Failed to push changes for version $new_version."
exit 1
fi
# Set the original image to the new image for the next iteration
original_image=$new_image
done