fix: Fix workflow to update Chart.yaml only when WordPress version changes
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:
@@ -153,16 +153,21 @@ 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 }}" '
|
||||||
/^image:/ { in_image=1 }
|
/^image:/ { in_image=1 }
|
||||||
in_image && /^ wordpress:/ { in_wordpress=1; print; next }
|
in_image && /^ wordpress:/ { in_wordpress=1; print; next }
|
||||||
in_wordpress && /^ tag:/ {
|
in_wordpress && /^ tag:/ {
|
||||||
print " tag: \"" new_tag "\""
|
print " tag: \"" new_tag "\""
|
||||||
in_wordpress=0
|
in_wordpress=0
|
||||||
next
|
next
|
||||||
@@ -172,13 +177,13 @@ jobs:
|
|||||||
{ print }
|
{ print }
|
||||||
' values.yaml.bak > values.yaml.tmp
|
' values.yaml.bak > values.yaml.tmp
|
||||||
mv values.yaml.tmp values.yaml
|
mv values.yaml.tmp values.yaml
|
||||||
|
|
||||||
# Nginxのtagを更新
|
# Nginxのtagを更新
|
||||||
cp values.yaml values.yaml.tmp
|
cp values.yaml values.yaml.tmp
|
||||||
awk -v new_tag="${{ steps.nginx.outputs.version }}" '
|
awk -v new_tag="${{ steps.nginx.outputs.version }}" '
|
||||||
/^image:/ { in_image=1 }
|
/^image:/ { in_image=1 }
|
||||||
in_image && /^ nginx:/ { in_nginx=1; print; next }
|
in_image && /^ nginx:/ { in_nginx=1; print; next }
|
||||||
in_nginx && /^ tag:/ {
|
in_nginx && /^ tag:/ {
|
||||||
print " tag: \"" new_tag "\""
|
print " tag: \"" new_tag "\""
|
||||||
in_nginx=0
|
in_nginx=0
|
||||||
next
|
next
|
||||||
@@ -188,45 +193,85 @@ jobs:
|
|||||||
{ print }
|
{ print }
|
||||||
' values.yaml.tmp > values.yaml
|
' values.yaml.tmp > values.yaml
|
||||||
rm values.yaml.tmp
|
rm values.yaml.tmp
|
||||||
|
|
||||||
# 変更内容を表示
|
# 変更内容を表示
|
||||||
echo "=== Changes in values.yaml ==="
|
echo "=== Changes in values.yaml ==="
|
||||||
diff values.yaml.bak values.yaml || true
|
diff values.yaml.bak values.yaml || true
|
||||||
|
|
||||||
# 実際に変更されたか確認
|
# 実際に変更されたか確認
|
||||||
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
|
||||||
echo "No changes to commit"
|
echo "No changes to commit"
|
||||||
exit 0
|
exit 0
|
||||||
@@ -260,43 +305,45 @@ 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/
|
||||||
|
|
||||||
# Helmパッケージを作成
|
# Helmパッケージを作成
|
||||||
helm package . -d ./packages/
|
helm package . -d ./packages/
|
||||||
|
|
||||||
# リポジトリインデックスを更新
|
# リポジトリインデックスを更新
|
||||||
helm repo index ./packages/ --url https://git.cafepieters.com/helmchart/wordpress/raw/branch/main/packages/
|
helm repo index ./packages/ --url https://git.cafepieters.com/helmchart/wordpress/raw/branch/main/packages/
|
||||||
|
|
||||||
# パッケージファイルをコミット
|
# パッケージファイルをコミット
|
||||||
git add ./packages/*.tgz ./packages/index.yaml
|
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 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)"
|
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
|
||||||
Release $TAG_NAME
|
Release $TAG_NAME
|
||||||
|
|
||||||
${{ steps.check.outputs.changes }}
|
${{ steps.check.outputs.changes }}
|
||||||
Chart version: ${{ steps.increment.outputs.new_chart_version }}
|
Chart version: ${{ steps.increment.outputs.new_chart_version }}
|
||||||
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()
|
||||||
@@ -311,9 +358,14 @@ jobs:
|
|||||||
echo "Nginx:"
|
echo "Nginx:"
|
||||||
echo " Current: ${{ steps.current.outputs.current_nginx }}"
|
echo " Current: ${{ steps.current.outputs.current_nginx }}"
|
||||||
echo " Latest: ${{ steps.nginx.outputs.version }}"
|
echo " Latest: ${{ steps.nginx.outputs.version }}"
|
||||||
|
|
||||||
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
|
||||||
Reference in New Issue
Block a user