refactor: align workflow with phpfpm chart, add Gitea Release and Helm repo index
All checks were successful
Helm Chart Release / release-chart (push) Successful in 7s
All checks were successful
Helm Chart Release / release-chart (push) Successful in 7s
- Rename steps/variables to match phpfpm chart naming conventions - job: update -> update-and-release - step: check -> check_update (id) - flag: chart_version_update_needed -> wp_updated - Checkout repository -> Checkout - Commit and push changes -> Commit changes - git user: Gitea Actions -> Gitea Actions Bot - Add: Create Gitea Release step (API call + .tgz asset upload) - Add: Update Helm Repository Index step (gh-pages branch management) - Restructure: Move Install Helm before version checks (same as phpfpm) - Simplify: Remove redundant steps (Get current versions, Check if update is needed merged into check_update) - Add: app_version output to wordpress step (WordPress version number only) - Align: cron schedule 0 2 * * 1 (Monday 02:00 UTC, same as phpfpm) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,37 +1,34 @@
|
||||
name: Update Docker Images and Helm Chart
|
||||
name: Update Docker Image Tags and Release Helm Chart
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
schedule:
|
||||
- cron: "0 0 * * 0" # 毎週日曜日 00:00 UTC
|
||||
workflow_dispatch: # 手動実行も可能にする
|
||||
- cron: "0 2 * * 1" # 毎週月曜日 02:00 UTC
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
update:
|
||||
update-and-release:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write # Git pushに必要な権限を明示的に付与
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0 # 完全な履歴を取得
|
||||
token: ${{ secrets.GITEA_TOKEN || github.token }} # トークンを明示的に指定
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Git
|
||||
run: |
|
||||
git config user.name "Gitea Actions"
|
||||
git config user.email "actions@git.cafepieters.com"
|
||||
- name: Install Helm
|
||||
uses: azure/setup-helm@v3
|
||||
with:
|
||||
version: 'v3.12.0'
|
||||
|
||||
- name: Fetch latest WordPress FPM Alpine version
|
||||
- name: Check for new WordPress version
|
||||
id: wordpress
|
||||
run: |
|
||||
# Docker Hubから最新のWordPress FPM Alpineバージョンを取得(PHPバージョンも最新)
|
||||
echo "Fetching WordPress FPM Alpine versions..."
|
||||
set -e
|
||||
echo "Checking WordPress versions..."
|
||||
CURRENT=$(grep -A3 "wordpress:" values.yaml | grep "tag:" | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ')
|
||||
echo "Current WordPress: $CURRENT"
|
||||
|
||||
# fpm-alpineタグを取得(全PHPバージョン対象)
|
||||
LATEST_VERSION=$(curl -s "https://hub.docker.com/v2/repositories/library/wordpress/tags?page_size=100&name=fpm-alpine" | \
|
||||
# Docker Hub API v2を使用してfpm-alpineタグを取得(全PHPバージョン対象)
|
||||
LATEST=$(curl -s "https://hub.docker.com/v2/repositories/library/wordpress/tags?page_size=100&name=fpm-alpine" | \
|
||||
jq -r '.results[].name' | \
|
||||
grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)?-php[0-9]+\.[0-9]+-fpm-alpine$' | \
|
||||
grep -v 'rc' | \
|
||||
@@ -40,44 +37,34 @@ jobs:
|
||||
sort -t- -k1,1V -k2,2V | \
|
||||
tail -n 1)
|
||||
|
||||
if [ -z "$LATEST_VERSION" ]; then
|
||||
echo "Failed to fetch from first method, trying alternative..."
|
||||
# 代替方法: すべてのfpm-alpineタグを取得
|
||||
LATEST_VERSION=$(curl -s "https://hub.docker.com/v2/repositories/library/wordpress/tags?page_size=100" | \
|
||||
jq -r '.results[].name' | \
|
||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+-php[0-9]+\.[0-9]+-fpm-alpine$' | \
|
||||
grep -v 'rc' | \
|
||||
grep -v 'beta' | \
|
||||
grep -v 'alpha' | \
|
||||
sort -t- -k1,1V -k2,2V | \
|
||||
tail -n 1)
|
||||
if [ -z "$LATEST" ]; then
|
||||
echo "Warning: Could not fetch latest WordPress version, using current"
|
||||
LATEST="$CURRENT"
|
||||
fi
|
||||
|
||||
if [ -z "$LATEST_VERSION" ]; then
|
||||
echo "ERROR: Failed to fetch WordPress version"
|
||||
exit 1
|
||||
# WordPressバージョンを抽出 (6.9.1の部分)
|
||||
APP_VERSION=$(echo "$LATEST" | grep -oE '^[0-9]+\.[0-9]+(\.[0-9]+)?')
|
||||
if [ -z "$APP_VERSION" ]; then
|
||||
echo "Warning: Could not extract WordPress version from: $LATEST"
|
||||
APP_VERSION=$(echo "$CURRENT" | grep -oE '^[0-9]+\.[0-9]+(\.[0-9]+)?')
|
||||
fi
|
||||
|
||||
echo "WordPress latest version: $LATEST_VERSION"
|
||||
echo "Latest WordPress: $LATEST"
|
||||
echo "WordPress version: $APP_VERSION"
|
||||
echo "current=$CURRENT" >> $GITHUB_OUTPUT
|
||||
echo "latest=$LATEST" >> $GITHUB_OUTPUT
|
||||
echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
# バージョン情報を分解して表示
|
||||
WP_VERSION=$(echo $LATEST_VERSION | cut -d'-' -f1)
|
||||
PHP_VERSION=$(echo $LATEST_VERSION | cut -d'-' -f2)
|
||||
echo " WordPress: $WP_VERSION"
|
||||
echo " PHP: $PHP_VERSION"
|
||||
echo " Base: fpm-alpine"
|
||||
|
||||
# 共有変数として出力
|
||||
echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "version_base=$WP_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Fetch latest Nginx Alpine Perl version
|
||||
- name: Check for new Nginx version
|
||||
id: nginx
|
||||
run: |
|
||||
# Docker Hubから最新のNginx Alpine Perlバージョンを取得
|
||||
echo "Fetching Nginx Alpine Perl versions..."
|
||||
set -e
|
||||
echo "Checking Nginx versions..."
|
||||
CURRENT=$(grep -A3 "nginx:" values.yaml | grep "tag:" | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ')
|
||||
echo "Current Nginx: $CURRENT"
|
||||
|
||||
LATEST_VERSION=$(curl -s "https://hub.docker.com/v2/repositories/library/nginx/tags?page_size=100&name=alpine-perl" | \
|
||||
# Docker Hub API v2を使用してalphine-perlタグを取得
|
||||
LATEST=$(curl -s "https://hub.docker.com/v2/repositories/library/nginx/tags?page_size=100&name=alpine-perl" | \
|
||||
jq -r '.results[].name' | \
|
||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+-alpine-perl$' | \
|
||||
grep -v 'rc' | \
|
||||
@@ -86,199 +73,101 @@ jobs:
|
||||
sort -V | \
|
||||
tail -n 1)
|
||||
|
||||
if [ -z "$LATEST_VERSION" ]; then
|
||||
echo "Failed to fetch from first method, trying alternative..."
|
||||
# 代替方法: alpine-perlタグを別の方法で検索
|
||||
LATEST_VERSION=$(curl -s "https://hub.docker.com/v2/repositories/library/nginx/tags?page_size=100" | \
|
||||
jq -r '.results[].name' | \
|
||||
grep 'alpine-perl$' | \
|
||||
grep -E '^[0-9]+\.[0-9]+\.[0-9]+-alpine-perl$' | \
|
||||
grep -v 'rc' | \
|
||||
grep -v 'beta' | \
|
||||
grep -v 'alpha' | \
|
||||
sort -V | \
|
||||
tail -n 1)
|
||||
if [ -z "$LATEST" ]; then
|
||||
echo "Warning: Could not fetch latest Nginx version, using current"
|
||||
LATEST="$CURRENT"
|
||||
fi
|
||||
echo "Latest Nginx: $LATEST"
|
||||
echo "current=$CURRENT" >> $GITHUB_OUTPUT
|
||||
echo "latest=$LATEST" >> $GITHUB_OUTPUT
|
||||
|
||||
if [ -z "$LATEST_VERSION" ]; then
|
||||
echo "ERROR: Failed to fetch Nginx version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Nginx latest version: $LATEST_VERSION"
|
||||
|
||||
# バージョン情報を表示
|
||||
NGINX_VERSION=$(echo $LATEST_VERSION | cut -d'-' -f1)
|
||||
echo " Nginx: $NGINX_VERSION"
|
||||
echo " Base: alpine-perl"
|
||||
|
||||
# 共有変数として出力
|
||||
echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "version_base=$NGINX_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Get current versions from values.yaml
|
||||
id: current
|
||||
- name: Determine if update is needed
|
||||
id: check_update
|
||||
run: |
|
||||
# 現在のバージョンを取得
|
||||
CURRENT_WORDPRESS=$(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}')
|
||||
set -e
|
||||
WP_CURRENT="${{ steps.wordpress.outputs.current }}"
|
||||
WP_LATEST="${{ steps.wordpress.outputs.latest }}"
|
||||
NGINX_CURRENT="${{ steps.nginx.outputs.current }}"
|
||||
NGINX_LATEST="${{ steps.nginx.outputs.latest }}"
|
||||
|
||||
echo "current_wordpress=$CURRENT_WORDPRESS" >> $GITHUB_OUTPUT
|
||||
echo "current_nginx=$CURRENT_NGINX" >> $GITHUB_OUTPUT
|
||||
echo "Current WordPress: $CURRENT_WORDPRESS"
|
||||
echo "Current Nginx: $CURRENT_NGINX"
|
||||
echo "WordPress: $WP_CURRENT vs $WP_LATEST"
|
||||
echo "Nginx: $NGINX_CURRENT vs $NGINX_LATEST"
|
||||
|
||||
- name: Check if update is needed
|
||||
id: check
|
||||
run: |
|
||||
# 更新が必要かチェック
|
||||
UPDATE_NEEDED=false
|
||||
CHANGES=""
|
||||
WP_UPDATED=false
|
||||
|
||||
if [ "${{ steps.current.outputs.current_wordpress }}" != "${{ steps.wordpress.outputs.version }}" ]; then
|
||||
echo "WordPress update available: ${{ steps.current.outputs.current_wordpress }} -> ${{ steps.wordpress.outputs.version }}"
|
||||
if [ "$WP_CURRENT" != "$WP_LATEST" ]; then
|
||||
UPDATE_NEEDED=true
|
||||
CHANGES="${CHANGES}- WordPress: ${{ steps.current.outputs.current_wordpress }} -> ${{ steps.wordpress.outputs.version }}\n"
|
||||
else
|
||||
echo "WordPress is up to date: ${{ steps.current.outputs.current_wordpress }}"
|
||||
WP_UPDATED=true
|
||||
echo "WordPress update detected"
|
||||
fi
|
||||
|
||||
if [ "${{ steps.current.outputs.current_nginx }}" != "${{ steps.nginx.outputs.version }}" ]; then
|
||||
echo "Nginx update available: ${{ steps.current.outputs.current_nginx }} -> ${{ steps.nginx.outputs.version }}"
|
||||
if [ "$NGINX_CURRENT" != "$NGINX_LATEST" ]; then
|
||||
UPDATE_NEEDED=true
|
||||
CHANGES="${CHANGES}- Nginx: ${{ steps.current.outputs.current_nginx }} -> ${{ steps.nginx.outputs.version }}\n"
|
||||
else
|
||||
echo "Nginx is up to date: ${{ steps.current.outputs.current_nginx }}"
|
||||
echo "Nginx update detected"
|
||||
fi
|
||||
|
||||
echo "update_needed=$UPDATE_NEEDED" >> $GITHUB_OUTPUT
|
||||
echo -e "changes<<EOF" >> $GITHUB_OUTPUT
|
||||
echo -e "$CHANGES" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
echo "wp_updated=$WP_UPDATED" >> $GITHUB_OUTPUT
|
||||
|
||||
if [ "$UPDATE_NEEDED" = "true" ]; then
|
||||
echo "Update is needed"
|
||||
else
|
||||
echo "Already up to date - no action required"
|
||||
fi
|
||||
|
||||
- name: Update values.yaml
|
||||
if: steps.check.outputs.update_needed == 'true'
|
||||
id: update_values
|
||||
if: steps.check_update.outputs.update_needed == 'true'
|
||||
run: |
|
||||
set -e
|
||||
echo "Updating values.yaml..."
|
||||
|
||||
cp values.yaml values.yaml.bak
|
||||
|
||||
# 共有変数から最新バージョンを取得
|
||||
WP_LATEST="${{ steps.wordpress.outputs.version }}"
|
||||
WP_BASE="${{ steps.wordpress.outputs.version_base }}"
|
||||
NGINX_LATEST="${{ steps.nginx.outputs.version }}"
|
||||
|
||||
# 現在のバージョンを取得(Chart.yaml更新判定用)
|
||||
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"
|
||||
echo " Nginx: $CURRENT_NGINX"
|
||||
echo ""
|
||||
echo "Latest versions:"
|
||||
echo " WordPress: $WP_LATEST"
|
||||
echo " Nginx: $NGINX_LATEST"
|
||||
|
||||
# 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"
|
||||
WP_OLD="${{ steps.wordpress.outputs.current }}"
|
||||
WP_NEW="${{ steps.wordpress.outputs.latest }}"
|
||||
if [ "$WP_OLD" != "$WP_NEW" ]; then
|
||||
sed -i "s|tag: \"${WP_OLD}\"|tag: \"${WP_NEW}\"|g" values.yaml
|
||||
echo "WordPress updated: $WP_OLD -> $WP_NEW"
|
||||
fi
|
||||
|
||||
# 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"
|
||||
NGINX_OLD="${{ steps.nginx.outputs.current }}"
|
||||
NGINX_NEW="${{ steps.nginx.outputs.latest }}"
|
||||
if [ "$NGINX_OLD" != "$NGINX_NEW" ]; then
|
||||
sed -i "s|tag: \"${NGINX_OLD}\"|tag: \"${NGINX_NEW}\"|g" values.yaml
|
||||
echo "Nginx updated: $NGINX_OLD -> $NGINX_NEW"
|
||||
fi
|
||||
|
||||
# 変更内容を表示
|
||||
echo ""
|
||||
echo "=== Changes in values.yaml ==="
|
||||
diff values.yaml.bak values.yaml || true
|
||||
echo "values.yaml updated"
|
||||
git diff values.yaml
|
||||
|
||||
# 実際に変更されたか確認
|
||||
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)"
|
||||
echo "chart_version_update_needed=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Changes detected in values.yaml"
|
||||
|
||||
# WordPressバージョンが更新されたか判定(Chart.yaml更新の判定用)
|
||||
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"
|
||||
echo "chart_version_update_needed=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== Updated values.yaml (image section) ==="
|
||||
grep -A 10 "^image:" values.yaml
|
||||
|
||||
- name: Increment chart version
|
||||
if: steps.update_values.outputs.chart_version_update_needed == 'true'
|
||||
id: increment
|
||||
- name: Update Chart.yaml version
|
||||
if: steps.check_update.outputs.wp_updated == 'true'
|
||||
run: |
|
||||
# Chart.yamlのバージョンをインクリメント(WordPressバージョン更新時のみ)
|
||||
# WordPressバージョン更新時は新しいWPバージョンをそのまま使用(サフィックスは付けない)
|
||||
if [ -f Chart.yaml ]; then
|
||||
CURRENT_CHART_VERSION=$(grep '^version:' Chart.yaml | awk '{print $2}')
|
||||
CURRENT_APP_VERSION=$(grep '^appVersion:' Chart.yaml | awk '{print $2}' | tr -d '"')
|
||||
set -e
|
||||
APP_VERSION="${{ steps.wordpress.outputs.app_version }}"
|
||||
sed -i "s/^version: .*/version: $APP_VERSION/" Chart.yaml
|
||||
sed -i "s/^appVersion: .*/appVersion: \"$APP_VERSION\"/" Chart.yaml
|
||||
echo "Chart.yaml updated to version $APP_VERSION"
|
||||
cat Chart.yaml
|
||||
|
||||
# 共有変数から最新のWordPressバージョン(ベース)を取得
|
||||
NEW_WP_VERSION="${{ steps.wordpress.outputs.version_base }}"
|
||||
|
||||
# Chart.yamlはWordPressバージョンに合わせて更新(version と appVersion を同じにする)
|
||||
NEW_CHART_VERSION="$NEW_WP_VERSION"
|
||||
|
||||
sed -i "s/^version: .*/version: $NEW_CHART_VERSION/" Chart.yaml
|
||||
sed -i "s/^appVersion: .*/appVersion: \"$NEW_WP_VERSION\"/" Chart.yaml
|
||||
|
||||
echo "Chart version updated: $CURRENT_CHART_VERSION -> $NEW_CHART_VERSION"
|
||||
echo "Chart appVersion updated: $CURRENT_APP_VERSION -> $NEW_WP_VERSION"
|
||||
echo "new_chart_version=$NEW_CHART_VERSION" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Chart.yaml not found, skipping version increment"
|
||||
echo "new_chart_version=" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Commit and push changes
|
||||
if: steps.check.outputs.update_needed == 'true'
|
||||
- name: Commit changes
|
||||
if: steps.check_update.outputs.update_needed == 'true'
|
||||
run: |
|
||||
# values.yamlは常に追加
|
||||
git add values.yaml
|
||||
git config user.name "Gitea Actions Bot"
|
||||
git config user.email "actions@git.cafepieters.com"
|
||||
|
||||
# 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
|
||||
if [ "${{ steps.check_update.outputs.wp_updated }}" = "true" ]; then
|
||||
# WordPress更新時はChart.yamlも含める
|
||||
git add values.yaml Chart.yaml
|
||||
git commit -m "chore: update to WordPress ${{ steps.wordpress.outputs.app_version }}, nginx ${{ steps.nginx.outputs.latest }}"
|
||||
else
|
||||
echo "Skipping Chart.yaml (only other images were updated)"
|
||||
# Nginxのみの更新時はvalues.yamlのみ
|
||||
git add values.yaml
|
||||
git commit -m "chore: update nginx to ${{ steps.nginx.outputs.latest }} (no release)"
|
||||
fi
|
||||
|
||||
git status
|
||||
|
||||
if git diff --staged --quiet; then
|
||||
echo "No changes to commit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# コミットメッセージを作成
|
||||
cat << EOF > /tmp/commit_msg.txt
|
||||
chore: Update Docker images
|
||||
|
||||
${{ steps.check.outputs.changes }}
|
||||
Auto-updated by Gitea Actions
|
||||
EOF
|
||||
|
||||
git commit -F /tmp/commit_msg.txt
|
||||
|
||||
# プッシュをリトライ機構付きで実行
|
||||
MAX_RETRIES=3
|
||||
RETRY_COUNT=0
|
||||
@@ -296,104 +185,126 @@ jobs:
|
||||
|
||||
echo "Successfully pushed changes to main branch"
|
||||
|
||||
- name: Install Helm
|
||||
if: steps.update_values.outputs.chart_version_update_needed == 'true'
|
||||
uses: azure/setup-helm@v3
|
||||
with:
|
||||
version: 'latest'
|
||||
|
||||
- name: Create Helm package
|
||||
if: steps.update_values.outputs.chart_version_update_needed == 'true'
|
||||
- name: Package Helm Chart
|
||||
if: steps.check_update.outputs.wp_updated == 'true'
|
||||
run: |
|
||||
# packagesディレクトリを作成
|
||||
mkdir -p ./packages/
|
||||
helm package .
|
||||
echo "Helm chart packaged"
|
||||
|
||||
# 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"
|
||||
|
||||
# パッケージのプッシュをリトライ機構付きで実行
|
||||
MAX_RETRIES=3
|
||||
RETRY_COUNT=0
|
||||
until git push origin main || [ $RETRY_COUNT -eq $MAX_RETRIES ]; do
|
||||
RETRY_COUNT=$((RETRY_COUNT+1))
|
||||
echo "Push failed, retrying ($RETRY_COUNT/$MAX_RETRIES)..."
|
||||
sleep 5
|
||||
git pull --rebase origin main
|
||||
done
|
||||
|
||||
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
|
||||
echo "ERROR: Failed to push Helm packages after $MAX_RETRIES attempts"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Successfully pushed Helm packages"
|
||||
|
||||
- name: Create release tag
|
||||
if: steps.update_values.outputs.chart_version_update_needed == 'true'
|
||||
- name: Create Git Tag
|
||||
if: steps.check_update.outputs.wp_updated == 'true'
|
||||
run: |
|
||||
# リリースタグを作成(Chart.yaml更新時のみ)
|
||||
TAG_NAME="v${{ steps.increment.outputs.new_chart_version }}"
|
||||
APP_VERSION="${{ steps.wordpress.outputs.app_version }}"
|
||||
|
||||
# タグが既に存在するか確認
|
||||
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
|
||||
echo "INFO: Tag $TAG_NAME already exists locally"
|
||||
# タグが既に存在する場合はスキップ
|
||||
if git rev-parse "v$APP_VERSION" >/dev/null 2>&1; then
|
||||
echo "Tag v$APP_VERSION already exists, skipping tag creation"
|
||||
else
|
||||
# タグメッセージを作成
|
||||
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
|
||||
echo "Created tag: $TAG_NAME"
|
||||
git tag -a "v$APP_VERSION" -m "Release WordPress $APP_VERSION"
|
||||
git push origin "v$APP_VERSION"
|
||||
echo "Git tag v$APP_VERSION created"
|
||||
fi
|
||||
|
||||
# タグをプッシュ(リトライ付き)
|
||||
MAX_RETRIES=3
|
||||
RETRY_COUNT=0
|
||||
until git push origin "$TAG_NAME" 2>/dev/null || [ $RETRY_COUNT -eq $MAX_RETRIES ]; do
|
||||
RETRY_COUNT=$((RETRY_COUNT+1))
|
||||
echo "Tag push failed, retrying ($RETRY_COUNT/$MAX_RETRIES)..."
|
||||
sleep 5
|
||||
done
|
||||
- name: Create Gitea Release
|
||||
if: steps.check_update.outputs.wp_updated == 'true'
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
APP_VERSION="${{ steps.wordpress.outputs.app_version }}"
|
||||
CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}')
|
||||
PACKAGE_FILE="${CHART_NAME}-${APP_VERSION}.tgz"
|
||||
RELEASE_BODY="WordPress Helm Chart v${APP_VERSION} - Automated release"
|
||||
|
||||
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
|
||||
echo "ERROR: Failed to push tag $TAG_NAME after $MAX_RETRIES attempts"
|
||||
exit 1
|
||||
# リリースが既に存在する場合はスキップ
|
||||
if curl -s -H "Authorization: token ${GITEA_TOKEN}" "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/v${APP_VERSION}" | jq -e '.id' >/dev/null 2>&1; then
|
||||
echo "Release v$APP_VERSION already exists, skipping release creation"
|
||||
else
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"v${APP_VERSION}\",\"name\":\"v${APP_VERSION}\",\"body\":\"${RELEASE_BODY}\"}" \
|
||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases"
|
||||
|
||||
RELEASE_ID=$(curl -s \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/v${APP_VERSION}" | jq -r '.id')
|
||||
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/gzip" \
|
||||
--data-binary "@${PACKAGE_FILE}" \
|
||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${PACKAGE_FILE}"
|
||||
|
||||
echo "Release v${APP_VERSION} created with asset ${PACKAGE_FILE}"
|
||||
fi
|
||||
|
||||
echo "Successfully pushed tag: $TAG_NAME"
|
||||
- name: Update Helm Repository Index
|
||||
if: steps.check_update.outputs.wp_updated == 'true'
|
||||
run: |
|
||||
set -e
|
||||
APP_VERSION="${{ steps.wordpress.outputs.app_version }}"
|
||||
CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}')
|
||||
PACKAGE_FILE="${CHART_NAME}-${APP_VERSION}.tgz"
|
||||
|
||||
echo "Preparing Helm repository update..."
|
||||
|
||||
# パッケージファイルを一時ディレクトリに移動
|
||||
mkdir -p /tmp/helm-repo
|
||||
cp "${PACKAGE_FILE}" /tmp/helm-repo/
|
||||
|
||||
# gh-pagesブランチの処理
|
||||
if git ls-remote --heads origin gh-pages | grep gh-pages; then
|
||||
echo "gh-pages branch exists, checking out..."
|
||||
git fetch origin gh-pages
|
||||
git checkout gh-pages
|
||||
else
|
||||
echo "Creating new gh-pages branch..."
|
||||
git checkout --orphan gh-pages
|
||||
git rm -rf . || true
|
||||
echo "# Helm Repository" > README.md
|
||||
git config user.name "Gitea Actions Bot"
|
||||
git config user.email "actions@git.cafepieters.com"
|
||||
git add README.md
|
||||
git commit -m "Initialize gh-pages branch"
|
||||
git push origin gh-pages
|
||||
fi
|
||||
|
||||
# パッケージファイルをコピー
|
||||
cp /tmp/helm-repo/"${PACKAGE_FILE}" .
|
||||
|
||||
# index.yamlを生成/更新
|
||||
helm repo index . --url "https://git.cafepieters.com/${GITHUB_REPOSITORY}/raw/branch/gh-pages"
|
||||
|
||||
# コミットしてプッシュ
|
||||
git config user.name "Gitea Actions Bot"
|
||||
git config user.email "actions@git.cafepieters.com"
|
||||
git add "${PACKAGE_FILE}" index.yaml
|
||||
git commit -m "chore: add ${CHART_NAME} v${APP_VERSION}" || echo "No changes to commit"
|
||||
git push origin gh-pages
|
||||
|
||||
echo "Helm repository updated successfully"
|
||||
|
||||
# mainブランチに戻る
|
||||
git checkout main
|
||||
|
||||
- name: Summary
|
||||
if: always()
|
||||
run: |
|
||||
echo "=== Workflow Summary ==="
|
||||
echo "Update needed: ${{ steps.check.outputs.update_needed }}"
|
||||
echo ""
|
||||
echo "WordPress:"
|
||||
echo " Current: ${{ steps.current.outputs.current_wordpress }}"
|
||||
echo " Latest: ${{ steps.wordpress.outputs.version }}"
|
||||
echo ""
|
||||
echo "Nginx:"
|
||||
echo " Current: ${{ steps.current.outputs.current_nginx }}"
|
||||
echo " Latest: ${{ steps.nginx.outputs.version }}"
|
||||
APP_VERSION="${{ steps.wordpress.outputs.app_version }}"
|
||||
NGINX_VERSION="${{ steps.nginx.outputs.latest }}"
|
||||
WP_UPDATED="${{ steps.check_update.outputs.wp_updated }}"
|
||||
|
||||
if [ "${{ steps.check.outputs.update_needed }}" == "true" ]; then
|
||||
echo ""
|
||||
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
|
||||
echo "================================"
|
||||
echo "Update completed!"
|
||||
echo "- WordPress: ${APP_VERSION}"
|
||||
echo "- Nginx: ${NGINX_VERSION}"
|
||||
echo ""
|
||||
|
||||
if [ "$WP_UPDATED" = "true" ]; then
|
||||
echo "✅ WordPress version updated - Release created (v${APP_VERSION})"
|
||||
elif [ "${{ steps.check_update.outputs.update_needed }}" = "true" ]; then
|
||||
echo "ℹ️ Nginx only update - No release (waiting for next WordPress update)"
|
||||
else
|
||||
echo "ℹ️ Already up to date - no action required"
|
||||
fi
|
||||
echo "================================"
|
||||
|
||||
Reference in New Issue
Block a user