Skip to content

Commit a22e018

Browse files
authored
Update CSM versions update action (#173)
1 parent bde5ddb commit a22e018

File tree

1 file changed

+82
-41
lines changed

1 file changed

+82
-41
lines changed

.github/workflows/csi-sidecars-update.yaml renamed to .github/workflows/csm-versions-update.yaml

Lines changed: 82 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@
66
#
77
# http://www.apache.org/licenses/LICENSE-2.0
88

9-
# Reusable workflow to perform update of CSI sidecars.
10-
name: CSI Sidecars Update
9+
# Reusable workflow to perform update of CSM Versions.
10+
name: CSM Versions Update
1111

1212
# Invocable as a reusable workflow
1313
on:
1414
workflow_call:
1515

1616
jobs:
17-
csi-sidecars-update:
17+
csm-versions-update:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Checkout code
2121
uses: actions/checkout@v4
2222

23-
- name: Get Latest CSI Sidecar Versions from dell/csm
23+
- name: Get CSM Versions from dell/csm
2424
id: vars
2525
run: |
2626
curl -s https://raw.githubusercontent.com/dell/csm/refs/heads/main/config/csm-versions.yaml > versions-content.txt
2727
28-
# Parse out and save each csi sidecar version
28+
# Parse out and save each needed CSM version
2929
readarray -t lines < versions-content.txt
3030
for line in "${lines[@]}"; do
3131
name=$(echo $line | cut -d: -f1 | tr -d ' ')
@@ -45,11 +45,13 @@ jobs:
4545
echo "health_monitor=$version" >> "$GITHUB_OUTPUT"
4646
elif [[ $name == "csm-version" ]]; then
4747
echo "csm=$version" >> "$GITHUB_OUTPUT"
48+
elif [[ $name == "otel-collector" ]]; then
49+
echo "otel_collector=$version" >> "$GITHUB_OUTPUT"
4850
fi
4951
5052
done
5153
52-
- name: CSM docs sidecar update
54+
- name: CSM docs versions update
5355
if: ${{ github.repository == 'dell/csm-docs' }}
5456
env:
5557
attacher: ${{ steps.vars.outputs.attacher }}
@@ -58,41 +60,50 @@ jobs:
5860
resizer: ${{ steps.vars.outputs.resizer }}
5961
registrar: ${{ steps.vars.outputs.registrar }}
6062
health_monitor: ${{ steps.vars.outputs.health_monitor }}
63+
otel_collector: ${{ steps.vars.outputs.otel_collector }}
6164
csm: ${{ steps.vars.outputs.csm }}
6265
run: |
63-
echo "We are updating csm docs..."
64-
65-
declare -A sidecars
66-
sidecars[csi-attacher]=$attacher
67-
sidecars[csi-provisioner]=$provisioner
68-
sidecars[csi-snapshotter]=$snapshotter
69-
sidecars[csi-resizer]=$resizer
70-
sidecars[csi-node-driver-registrar]=$registrar
71-
sidecars[csi-external-health-monitor-controller]=$health_monitor
72-
73-
update_shortcodes_sidecars() {
74-
for key in "${!sidecars[@]}"; do
66+
declare -A latest_images
67+
latest_images[csi-attacher]=$attacher
68+
latest_images[csi-provisioner]=$provisioner
69+
latest_images[csi-snapshotter]=$snapshotter
70+
latest_images[csi-resizer]=$resizer
71+
latest_images[csi-node-driver-registrar]=$registrar
72+
latest_images[csi-external-health-monitor-controller]=$health_monitor
73+
latest_images[opentelemetry-collector]=$otel_collector
74+
75+
# Global variables
76+
updated_shortcodes=""
77+
updated_installation_wizard=""
78+
79+
update_shortcodes() {
80+
for key in "${!latest_images[@]}"; do
7581
path="layouts/shortcodes/version-docs.html"
7682
name=$(echo $key | tr '-' '_')
77-
version=${sidecars[$key]}
78-
79-
echo "Updating $key to $version"
83+
version=${latest_images[$key]}
8084
81-
# Get the shortcode location for sidecar
82-
sidecar_shortcode=$(grep -r "\"$name.*\" -}}" $path)
85+
# If no shortcode was found, we don't need to update it
86+
if ! grep -q "\"$name.*\" -}}" $path; then
87+
echo "No shortcode found for $key. Skipping."
88+
continue
89+
fi
8390
84-
# Remove the version from the shortcode
85-
partial_shortcode=$(echo "$sidecar_shortcode" | sed -E 's/v[0-9]+\.[0-9]+\.[0-9]+//g')
91+
old_shortcode=$(grep -r "\"$name.*\" -}}" $path)
8692
87-
# Replace the version in the shortcode
88-
sed -i "s/${sidecar_shortcode}/${partial_shortcode}$version/g" $path
93+
# If shortcode already contains the version, we don't need to update it
94+
if [[ "$old_shortcode" == *"$version"* ]]; then
95+
continue
96+
fi
97+
98+
new_shortcode=$(echo $old_shortcode | sed "s/}}.*/}}$version/")
99+
100+
updated_shortcodes+="\t$key to $version\n"
101+
sed -i "s|${old_shortcode}|${new_shortcode}|g" $path
89102
done
90103
}
91104
92-
update_installation_wizard_sidecars() {
93-
# Get the latest CSM version
94-
echo "Latest CSM Version is $csm"
95-
105+
update_installation_wizard() {
106+
echo "Starting installation wizard update..."
96107
# Sanitize the CSM version
97108
csm_version=$(echo $csm | tr -d 'v' | tr -d '\r')
98109
@@ -105,25 +116,55 @@ jobs:
105116
fi
106117
107118
for file in $wizard_files; do
108-
echo "Replaceing Sidecars in $file"
109-
for key in "${!sidecars[@]}"; do
119+
updated_images=""
120+
for key in "${!latest_images[@]}"; do
110121
# Retrieve the current version from the file of the sidecar.
111122
old_version=$(grep -r -m 1 "$key:" $file | xargs)
112123
if [ -z "$old_version" ]; then
113124
continue
114125
fi
115126
116-
# Replace the old version with the new version.
117-
new_version=$(echo $old_version | sed "s/:v[^\"]*/:${sidecars[$key]}/")
127+
# All instance of the image in a file either go "image:/value:" so we remove that to get the pure image.
128+
old_version=$(echo $old_version | cut -d':' -f2- | tr -d ' ')
129+
new_version=$(echo $old_version | sed "s/:.*/:${latest_images[$key]}/")
130+
131+
# If the version is the same, then we skip
132+
if [ "$old_version" == "$new_version" ]; then
133+
continue
134+
fi
135+
136+
updated_images+="\t$new_version\n"
118137
119138
# Update the version in the file.
120139
sed -i "s|${old_version}|${new_version}|g" $file
121140
done
141+
142+
if [ -z "$updated_images" ]; then
143+
continue
144+
fi
145+
146+
updated_installation_wizard+="Updated $file with the following images:\n$updated_images\n"
122147
done
123148
}
124149
125-
update_shortcodes_sidecars
126-
update_installation_wizard_sidecars
150+
handle_results() {
151+
if [ -z "$updated_shortcodes" ] && [ -z "$updated_installation_wizard" ]; then
152+
echo "No changes were made. Skipping."
153+
return
154+
fi
155+
156+
if [ -n "$updated_shortcodes" ]; then
157+
echo -e "Updated Shortcodes:\n$updated_shortcodes"
158+
fi
159+
160+
if [ -n "$updated_installation_wizard" ]; then
161+
echo -e "$updated_installation_wizard"
162+
fi
163+
}
164+
165+
update_shortcodes
166+
update_installation_wizard
167+
handle_results
127168
128169
- name: Remove versions content file
129170
run: rm versions-content.txt
@@ -143,11 +184,11 @@ jobs:
143184
uses: peter-evans/create-pull-request@v7
144185
with:
145186
token: ${{ steps.generate-token.outputs.token }}
146-
branch: "update-csi-sidecars"
147-
commit-message: "Update CSI sidecar versions to latest"
148-
title: "Update CSI sidecar versions to latest"
187+
branch: "update-csm-versions-to-latest"
188+
commit-message: "Update CSM versions to latest"
189+
title: "Update CSM versions to latest"
149190
body: |
150-
Automated update of CSI sidecar versions.
191+
Automated update all CSI Sidecars and Third Party Libraries to their latest version.
151192
152193
Auto-generated by [common-github-actions](https://github.com/dell/common-github-actions)
153194
sign-commits: true

0 commit comments

Comments
 (0)