refactor: Simplify values.yaml update using exact version matching
All checks were successful
Helm Chart Release / release-chart (push) Successful in 13s
Update Docker Images and Helm Chart / update (push) Successful in 22s

Refactor the Update values.yaml step to use exact version matching instead of
regex patterns. This approach is simpler, more reliable, and mirrors the
successful implementation in other Helmcharts (e.g., php-fpm).

Changes:
- Extract full current versions using awk (easier to parse)
- Use exact string replacement: sed 's|old_exact_version|new_exact_version|g'
- Only update if version has actually changed (conditional sed)
- Better error handling with set -e
- Clearer logging of what changed

Benefits:
1. Simpler logic: exact match instead of regex patterns
2. More reliable: no regex pattern matching failures
3. Proven approach: matches successful implementation in other projects
4. Clearer intent: code reads like "if version changed, update it"
5. Better debugging: conditional echo statements show exactly what happened

Flow:
1. Get current full version from values.yaml (e.g., 6.9.0-php8.5-fpm-alpine)
2. Get latest version from Docker Hub (shared variable)
3. If different, replace exact old version with exact new version
4. Report what changed (or didn't change)
5. Determine if WordPress version changed for Chart.yaml update decision

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-12 09:50:06 +09:00
parent 64c360f391
commit 945e4e4d29

View File

@@ -159,7 +159,9 @@ jobs:
if: steps.check.outputs.update_needed == 'true'
id: update_values
run: |
# バックアップを作成
set -e
echo "Updating values.yaml..."
cp values.yaml values.yaml.bak
# 共有変数から最新バージョンを取得
@@ -168,22 +170,29 @@ jobs:
NGINX_LATEST="${{ steps.nginx.outputs.version }}"
# 現在のバージョンを取得Chart.yaml更新判定用
CURRENT_WP_BASE=$(grep -A 1 'wordpress:' values.yaml | grep 'tag:' | sed 's/.*tag: "\([^-]*\).*/\1/')
CURRENT_NGINX=$(grep -A 1 'nginx:' values.yaml | grep 'tag:' | sed 's/.*tag: "\(.*\)".*/\1/')
CURRENT_WP=$(grep -A 3 'wordpress:' values.yaml | grep 'tag:' | awk -F'"' '{print $2}')
CURRENT_NGINX=$(grep -A 3 'nginx:' values.yaml | grep 'tag:' | awk -F'"' '{print $2}')
CURRENT_WP_BASE=$(echo "$CURRENT_WP" | cut -d'-' -f1)
echo "Current versions:"
echo " WordPress: $CURRENT_WP_BASE"
echo " WordPress: $CURRENT_WP"
echo " Nginx: $CURRENT_NGINX"
echo ""
echo "Latest versions:"
echo " WordPress: $WP_BASE ($WP_LATEST)"
echo " WordPress: $WP_LATEST"
echo " Nginx: $NGINX_LATEST"
# WordPressのtagを更新より単純で確実な方法
sed -i "s|tag: \"[0-9.]*-php[0-9.]*-fpm-alpine\"|tag: \"$WP_LATEST\"|" values.yaml
# WordPress更新
if [ "$CURRENT_WP" != "$WP_LATEST" ]; then
sed -i "s|tag: \"${CURRENT_WP}\"|tag: \"${WP_LATEST}\"|g" values.yaml
echo "WordPress updated: $CURRENT_WP -> $WP_LATEST"
fi
# Nginxのtagを更新より単純で確実な方法
sed -i "s|tag: \"[0-9.]*-alpine-perl\"|tag: \"$NGINX_LATEST\"|" values.yaml
# Nginx更新
if [ "$CURRENT_NGINX" != "$NGINX_LATEST" ]; then
sed -i "s|tag: \"${CURRENT_NGINX}\"|tag: \"${NGINX_LATEST}\"|g" values.yaml
echo "Nginx updated: $CURRENT_NGINX -> $NGINX_LATEST"
fi
# 変更内容を表示
echo ""
@@ -193,14 +202,14 @@ jobs:
# 実際に変更されたか確認
if diff -q values.yaml.bak values.yaml > /dev/null 2>&1; then
echo "INFO: No changes were made to values.yaml (versions already up to date)"
cat values.yaml | grep -A 5 "image:"
echo "chart_version_update_needed=false" >> $GITHUB_OUTPUT
else
echo "Changes detected in values.yaml"
# WordPressバージョンが更新されたか判定Chart.yaml更新の判定用
if [ "$CURRENT_WP_BASE" != "$WP_BASE" ]; then
echo "WordPress version changed: $CURRENT_WP_BASE -> $WP_BASE"
WP_NEW_BASE=$(echo "$WP_LATEST" | cut -d'-' -f1)
if [ "$CURRENT_WP_BASE" != "$WP_NEW_BASE" ]; then
echo "WordPress version changed: $CURRENT_WP_BASE -> $WP_NEW_BASE"
echo "chart_version_update_needed=true" >> $GITHUB_OUTPUT
else
echo "INFO: WordPress version unchanged - only other images updated"
@@ -210,7 +219,7 @@ jobs:
echo ""
echo "=== Updated values.yaml (image section) ==="
grep -A 5 "^image:" values.yaml
grep -A 10 "^image:" values.yaml
- name: Increment chart version
if: steps.update_values.outputs.chart_version_update_needed == 'true'