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,10 +153,15 @@ jobs:
- name: Update values.yaml - name: Update values.yaml
if: steps.check.outputs.update_needed == 'true' if: steps.check.outputs.update_needed == 'true'
id: update_values
run: | run: |
# バックアップを作成 # バックアップを作成
cp values.yaml values.yaml.bak 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を更新 # WordPressのtagを更新
# image.wordpress.tagの行を特定して置換 # image.wordpress.tagの行を特定して置換
awk -v new_tag="${{ steps.wordpress.outputs.version }}" ' awk -v new_tag="${{ steps.wordpress.outputs.version }}" '
@@ -197,34 +202,74 @@ jobs:
if diff -q values.yaml.bak values.yaml > /dev/null; then 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)" echo "INFO: No changes were made to values.yaml (versions already up to date)"
cat values.yaml | grep -A 5 "image:" cat values.yaml | grep -A 5 "image:"
echo "chart_version_update_needed=false" >> $GITHUB_OUTPUT
else else
echo "Changes detected in values.yaml" 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 fi
echo "=== Updated values.yaml (image section) ===" echo "=== Updated values.yaml (image section) ==="
grep -A 10 "^image:" values.yaml grep -A 10 "^image:" values.yaml
- name: Increment chart version - name: Increment chart version
if: steps.check.outputs.update_needed == 'true' if: steps.update_values.outputs.chart_version_update_needed == 'true'
id: increment id: increment
run: | run: |
# Chart.yamlのバージョンをインクリメント # Chart.yamlのバージョンをインクリメントWordPressバージョン更新時のみ
if [ -f Chart.yaml ]; then if [ -f Chart.yaml ]; then
CURRENT_CHART_VERSION=$(grep '^version:' Chart.yaml | awk '{print $2}') 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 sed -i "s/^version: .*/version: $NEW_CHART_VERSION/" Chart.yaml
echo "Chart version updated: $CURRENT_CHART_VERSION -> $NEW_CHART_VERSION" echo "Chart version updated: $CURRENT_CHART_VERSION -> $NEW_CHART_VERSION"
echo "new_chart_version=$NEW_CHART_VERSION" >> $GITHUB_OUTPUT echo "new_chart_version=$NEW_CHART_VERSION" >> $GITHUB_OUTPUT
else else
echo "Chart.yaml not found, skipping version increment" echo "Chart.yaml not found, skipping version increment"
echo "new_chart_version=unknown" >> $GITHUB_OUTPUT echo "new_chart_version=" >> $GITHUB_OUTPUT
fi fi
- name: Commit and push changes - name: Commit and push changes
if: steps.check.outputs.update_needed == 'true' if: steps.check.outputs.update_needed == 'true'
run: | 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 git status
if git diff --staged --quiet; then if git diff --staged --quiet; then
@@ -260,13 +305,13 @@ jobs:
echo "Successfully pushed changes to main branch" echo "Successfully pushed changes to main branch"
- name: Install Helm - 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 uses: azure/setup-helm@v3
with: with:
version: 'latest' version: 'latest'
- name: Create Helm package - name: Create Helm package
if: steps.check.outputs.update_needed == 'true' if: steps.update_values.outputs.chart_version_update_needed == 'true'
run: | run: |
# packagesディレクトリを作成 # packagesディレクトリを作成
mkdir -p ./packages/ mkdir -p ./packages/
@@ -283,9 +328,9 @@ jobs:
git push origin main || echo "Failed to push packages (this may be expected)" git push origin main || echo "Failed to push packages (this may be expected)"
- name: Create release tag - name: Create release tag
if: steps.check.outputs.update_needed == 'true' if: steps.update_values.outputs.chart_version_update_needed == 'true'
run: | run: |
# リリースタグを作成 # リリースタグを作成Chart.yaml更新時のみ
TAG_NAME="v${{ steps.increment.outputs.new_chart_version }}" TAG_NAME="v${{ steps.increment.outputs.new_chart_version }}"
cat << EOF > /tmp/tag_msg.txt cat << EOF > /tmp/tag_msg.txt
@@ -296,7 +341,9 @@ jobs:
EOF EOF
git tag -a "$TAG_NAME" -F /tmp/tag_msg.txt 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 - name: Summary
if: always() if: always()
@@ -314,6 +361,11 @@ jobs:
if [ "${{ steps.check.outputs.update_needed }}" == "true" ]; then if [ "${{ steps.check.outputs.update_needed }}" == "true" ]; then
echo "" echo ""
echo "Chart version: ${{ steps.increment.outputs.new_chart_version }}" echo "Chart version update: ${{ steps.update_values.outputs.chart_version_update_needed }}"
echo "Tag: v${{ steps.increment.outputs.new_chart_version }}" 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 fi