fix: Fix workflow to update Chart.yaml only when WordPress version changes
All checks were successful
Helm Chart Release / release-chart (push) Successful in 13s
Update Docker Images and Helm Chart / update (push) Successful in 17s

Refactor the image-update-and-release workflow to correctly handle Chart.yaml updates:

Changes:
- Add chart_version_update_needed flag in Update values.yaml step
  - Compares WordPress version before/after update
  - Only sets flag=true if WordPress version actually changed
- Modify Increment chart version step to run only when chart_version_update_needed=true
  - Implement proper suffix handling for versions like 6.9.3-a, 6.9.3-b, etc
  - Support upgrading base version without suffix to add -a suffix
- Update Commit and push changes step
  - Always add values.yaml
  - Only add Chart.yaml if WordPress version was updated
- Update Create Helm package and Create release tag steps
  - Only run if Chart.yaml was updated (chart_version_update_needed=true)
- Update Summary step to show whether Chart.yaml was updated

This prevents Chart.yaml from being updated when only Nginx or other images change,
avoiding version number regression issues (e.g., 6.9.3 -> 6.9.4 when only Nginx updated).

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-10 19:28:16 +09:00
parent 732bf94cdd
commit 7959242e1a

View File

@@ -153,16 +153,21 @@ jobs:
- name: Update values.yaml
if: steps.check.outputs.update_needed == 'true'
id: update_values
run: |
# バックアップを作成
cp values.yaml values.yaml.bak
# 現在のWordPressバージョンを取得Chart.yamlの更新判定用
CURRENT_WP_VERSION=$(grep -A 3 'wordpress:' values.yaml.bak | grep 'tag:' | awk -F'"' '{print $2}')
NEW_WP_VERSION="${{ steps.wordpress.outputs.version }}"
# WordPressのtagを更新
# image.wordpress.tagの行を特定して置換
awk -v new_tag="${{ steps.wordpress.outputs.version }}" '
/^image:/ { in_image=1 }
in_image && /^ wordpress:/ { in_wordpress=1; print; next }
in_wordpress && /^ tag:/ {
in_wordpress && /^ tag:/ {
print " tag: \"" new_tag "\""
in_wordpress=0
next
@@ -172,13 +177,13 @@ jobs:
{ print }
' values.yaml.bak > values.yaml.tmp
mv values.yaml.tmp values.yaml
# Nginxのtagを更新
cp values.yaml values.yaml.tmp
awk -v new_tag="${{ steps.nginx.outputs.version }}" '
/^image:/ { in_image=1 }
in_image && /^ nginx:/ { in_nginx=1; print; next }
in_nginx && /^ tag:/ {
in_nginx && /^ tag:/ {
print " tag: \"" new_tag "\""
in_nginx=0
next
@@ -188,45 +193,85 @@ jobs:
{ print }
' values.yaml.tmp > values.yaml
rm values.yaml.tmp
# 変更内容を表示
echo "=== Changes in values.yaml ==="
diff values.yaml.bak values.yaml || true
# 実際に変更されたか確認
if diff -q values.yaml.bak values.yaml > /dev/null; 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_VERSION" != "$NEW_WP_VERSION" ]; then
echo "WordPress version changed: $CURRENT_WP_VERSION -> $NEW_WP_VERSION"
echo "chart_version_update_needed=true" >> $GITHUB_OUTPUT
else
echo "INFO: WordPress version unchanged - only other images updated"
echo "chart_version_update_needed=false" >> $GITHUB_OUTPUT
fi
fi
echo "=== Updated values.yaml (image section) ==="
grep -A 10 "^image:" values.yaml
- name: Increment chart version
if: steps.check.outputs.update_needed == 'true'
if: steps.update_values.outputs.chart_version_update_needed == 'true'
id: increment
run: |
# Chart.yamlのバージョンをインクリメント
# Chart.yamlのバージョンをインクリメントWordPressバージョン更新時のみ
if [ -f Chart.yaml ]; then
CURRENT_CHART_VERSION=$(grep '^version:' Chart.yaml | awk '{print $2}')
# パッチバージョンをインクリメント(例: 1.0.0 -> 1.0.1
NEW_CHART_VERSION=$(echo $CURRENT_CHART_VERSION | awk -F. '{print $1"."$2"."$3+1}')
# バージョンのベース部分とサフィックスを分離
if [[ $CURRENT_CHART_VERSION == *"-"* ]]; then
# サフィックス付き(例: 6.9.3-aの場合、サフィックスをインクリメント
BASE_VERSION="${CURRENT_CHART_VERSION%-*}"
SUFFIX="${CURRENT_CHART_VERSION#*-}"
# サフィックスをインクリメントa -> b, b -> c, など)
case "$SUFFIX" in
a) NEW_SUFFIX="b" ;;
b) NEW_SUFFIX="c" ;;
c) NEW_SUFFIX="d" ;;
d) NEW_SUFFIX="e" ;;
e) NEW_SUFFIX="f" ;;
*) NEW_SUFFIX="a" ;; # 予期しないサフィックスはリセット
esac
NEW_CHART_VERSION="${BASE_VERSION}-${NEW_SUFFIX}"
else
# サフィックスなし(例: 6.9.3)の場合、-a を追加
NEW_CHART_VERSION="${CURRENT_CHART_VERSION}-a"
fi
sed -i "s/^version: .*/version: $NEW_CHART_VERSION/" Chart.yaml
echo "Chart version updated: $CURRENT_CHART_VERSION -> $NEW_CHART_VERSION"
echo "new_chart_version=$NEW_CHART_VERSION" >> $GITHUB_OUTPUT
else
echo "Chart.yaml not found, skipping version increment"
echo "new_chart_version=unknown" >> $GITHUB_OUTPUT
echo "new_chart_version=" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.check.outputs.update_needed == 'true'
run: |
git add values.yaml Chart.yaml
# values.yamlは常に追加
git add values.yaml
# Chart.yamlはWordPressバージョン更新時のみ追加
if [ "${{ steps.update_values.outputs.chart_version_update_needed }}" == "true" ]; then
echo "Adding Chart.yaml (WordPress version was updated)"
git add Chart.yaml
else
echo "Skipping Chart.yaml (only other images were updated)"
fi
git status
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
@@ -260,43 +305,45 @@ jobs:
echo "Successfully pushed changes to main branch"
- name: Install Helm
if: steps.check.outputs.update_needed == 'true'
if: steps.update_values.outputs.chart_version_update_needed == 'true'
uses: azure/setup-helm@v3
with:
version: 'latest'
- name: Create Helm package
if: steps.check.outputs.update_needed == 'true'
if: steps.update_values.outputs.chart_version_update_needed == 'true'
run: |
# packagesディレクトリを作成
mkdir -p ./packages/
# Helmパッケージを作成
helm package . -d ./packages/
# リポジトリインデックスを更新
helm repo index ./packages/ --url https://git.cafepieters.com/helmchart/wordpress/raw/branch/main/packages/
# パッケージファイルをコミット
git add ./packages/*.tgz ./packages/index.yaml
git commit -m "chore: Add Helm package for version ${{ steps.increment.outputs.new_chart_version }}" || echo "No package changes to commit"
git push origin main || echo "Failed to push packages (this may be expected)"
- name: Create release tag
if: steps.check.outputs.update_needed == 'true'
if: steps.update_values.outputs.chart_version_update_needed == 'true'
run: |
# リリースタグを作成
# リリースタグを作成Chart.yaml更新時のみ
TAG_NAME="v${{ steps.increment.outputs.new_chart_version }}"
cat << EOF > /tmp/tag_msg.txt
Release $TAG_NAME
${{ steps.check.outputs.changes }}
Chart version: ${{ steps.increment.outputs.new_chart_version }}
EOF
git tag -a "$TAG_NAME" -F /tmp/tag_msg.txt
git push origin "$TAG_NAME" || echo "Failed to push tag (tag may already exist)"
if ! git push origin "$TAG_NAME"; then
echo "WARNING: Failed to push tag (may already exist or network issue)"
fi
- name: Summary
if: always()
@@ -311,9 +358,14 @@ jobs:
echo "Nginx:"
echo " Current: ${{ steps.current.outputs.current_nginx }}"
echo " Latest: ${{ steps.nginx.outputs.version }}"
if [ "${{ steps.check.outputs.update_needed }}" == "true" ]; then
echo ""
echo "Chart version: ${{ steps.increment.outputs.new_chart_version }}"
echo "Tag: v${{ steps.increment.outputs.new_chart_version }}"
echo "Chart version update: ${{ steps.update_values.outputs.chart_version_update_needed }}"
if [ "${{ steps.update_values.outputs.chart_version_update_needed }}" == "true" ]; then
echo "Chart version: ${{ steps.increment.outputs.new_chart_version }}"
echo "Tag: v${{ steps.increment.outputs.new_chart_version }}"
else
echo "INFO: Chart.yaml skipped (WordPress version unchanged)"
fi
fi