85a22e4d34
- Replace broken helmchart/repo checkout+index.yaml approach with Gitea Package Registry upload (matching phpfpm pattern) - Fix release condition: release only on phpMyAdmin update, not nginx-only - Add release_needed output separate from update_needed - Add duplicate tag/release guard before creation - Add jq availability check - Add env vars REGISTRY_URL and OWNER - Fix git user to Claude / claude@cafepieters.com - Add CLAUDE.md with git info, release rules, and PHP runtime note Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
255 lines
9.8 KiB
YAML
255 lines
9.8 KiB
YAML
name: Update Docker Image Tags and Release Helm Chart
|
|
|
|
on:
|
|
schedule:
|
|
- cron: '0 3 * * 1' # 毎週月曜日 3:00 AM (JST 12:00 PM)
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
REGISTRY_URL: https://git.cafepieters.com
|
|
OWNER: helmchart
|
|
|
|
jobs:
|
|
update-and-release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install Helm
|
|
uses: azure/setup-helm@v3
|
|
with:
|
|
version: 'v3.12.0'
|
|
|
|
- name: Check jq availability
|
|
run: |
|
|
if ! command -v jq &> /dev/null; then
|
|
echo "Installing jq..."
|
|
apt-get update && apt-get install -y jq
|
|
fi
|
|
jq --version
|
|
|
|
- name: Check for new nginx version
|
|
id: nginx
|
|
run: |
|
|
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=$(curl -s "https://registry.hub.docker.com/v2/repositories/library/nginx/tags?page_size=100" | \
|
|
jq -r '.results[].name' | \
|
|
grep -E '^[0-9]+\.[0-9]+\.[0-9]+-alpine-perl$' | \
|
|
sort -V | tail -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
|
|
|
|
- name: Check for new phpMyAdmin version
|
|
id: phpmyadmin
|
|
run: |
|
|
set -e
|
|
echo "Checking phpMyAdmin versions..."
|
|
CURRENT=$(grep -A3 "phpmyadmin:" values.yaml | grep "tag:" | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ')
|
|
echo "Current phpMyAdmin: $CURRENT"
|
|
|
|
# Docker Hub API v2を使用してタグを取得
|
|
# パターン: 5.2.3-fpm-alpine 形式
|
|
LATEST=$(curl -s "https://registry.hub.docker.com/v2/repositories/phpmyadmin/phpmyadmin/tags?page_size=100" | \
|
|
jq -r '.results[].name' | \
|
|
grep -E '^[0-9]+\.[0-9]+\.[0-9]+-fpm-alpine$' | \
|
|
sort -V | tail -1)
|
|
|
|
if [ -z "$LATEST" ]; then
|
|
echo "Warning: Could not fetch latest phpMyAdmin version, using current"
|
|
LATEST="$CURRENT"
|
|
fi
|
|
|
|
# phpMyAdminバージョンを抽出 (5.2.3の部分)
|
|
APP_VERSION=$(echo "$LATEST" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
|
|
if [ -z "$APP_VERSION" ]; then
|
|
echo "Error: Could not extract phpMyAdmin version"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Latest phpMyAdmin: $LATEST"
|
|
echo "phpMyAdmin version: $APP_VERSION"
|
|
echo "current=$CURRENT" >> $GITHUB_OUTPUT
|
|
echo "latest=$LATEST" >> $GITHUB_OUTPUT
|
|
echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Determine update and release conditions
|
|
id: check_update
|
|
run: |
|
|
set -e
|
|
NGINX_CURRENT="${{ steps.nginx.outputs.current }}"
|
|
NGINX_LATEST="${{ steps.nginx.outputs.latest }}"
|
|
PMA_CURRENT="${{ steps.phpmyadmin.outputs.current }}"
|
|
PMA_LATEST="${{ steps.phpmyadmin.outputs.latest }}"
|
|
|
|
echo "Nginx: $NGINX_CURRENT vs $NGINX_LATEST"
|
|
echo "phpMyAdmin: $PMA_CURRENT vs $PMA_LATEST"
|
|
|
|
UPDATE_NEEDED=false
|
|
RELEASE_NEEDED=false
|
|
|
|
if [ "$NGINX_CURRENT" != "$NGINX_LATEST" ] || [ "$PMA_CURRENT" != "$PMA_LATEST" ]; then
|
|
UPDATE_NEEDED=true
|
|
echo "Update needed"
|
|
else
|
|
echo "Already up to date"
|
|
fi
|
|
|
|
if [ "$PMA_CURRENT" != "$PMA_LATEST" ]; then
|
|
RELEASE_NEEDED=true
|
|
echo "Release needed: phpMyAdmin updated"
|
|
else
|
|
echo "No release (nginx-only update or no change)"
|
|
fi
|
|
|
|
echo "update_needed=$UPDATE_NEEDED" >> $GITHUB_OUTPUT
|
|
echo "release_needed=$RELEASE_NEEDED" >> $GITHUB_OUTPUT
|
|
|
|
- name: Update values.yaml
|
|
if: steps.check_update.outputs.update_needed == 'true'
|
|
run: |
|
|
set -e
|
|
echo "Updating values.yaml..."
|
|
|
|
NGINX_OLD="${{ steps.nginx.outputs.current }}"
|
|
NGINX_NEW="${{ steps.nginx.outputs.latest }}"
|
|
PMA_OLD="${{ steps.phpmyadmin.outputs.current }}"
|
|
PMA_NEW="${{ steps.phpmyadmin.outputs.latest }}"
|
|
|
|
if [ "$NGINX_OLD" != "$NGINX_NEW" ]; then
|
|
sed -i "0,/tag: \"${NGINX_OLD}\"/s//tag: \"${NGINX_NEW}\"/" values.yaml
|
|
echo "Nginx updated: $NGINX_OLD -> $NGINX_NEW"
|
|
fi
|
|
|
|
if [ "$PMA_OLD" != "$PMA_NEW" ]; then
|
|
sed -i "0,/tag: \"${NGINX_NEW}\"/b; s/tag: \"${PMA_OLD}\"/tag: \"${PMA_NEW}\"/" values.yaml
|
|
echo "phpMyAdmin updated: $PMA_OLD -> $PMA_NEW"
|
|
fi
|
|
|
|
echo "values.yaml updated"
|
|
git diff values.yaml
|
|
|
|
- name: Update Chart.yaml version
|
|
if: steps.check_update.outputs.release_needed == 'true'
|
|
run: |
|
|
set -e
|
|
APP_VERSION="${{ steps.phpmyadmin.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
|
|
|
|
- name: Commit changes
|
|
if: steps.check_update.outputs.update_needed == 'true'
|
|
run: |
|
|
git config user.name "Claude"
|
|
git config user.email "claude@cafepieters.com"
|
|
git add values.yaml Chart.yaml
|
|
git commit -m "chore: update to phpMyAdmin ${{ steps.phpmyadmin.outputs.latest }}, nginx ${{ steps.nginx.outputs.latest }}"
|
|
git push origin main
|
|
|
|
- name: Package Helm Chart
|
|
if: steps.check_update.outputs.release_needed == 'true'
|
|
run: |
|
|
helm package .
|
|
echo "Helm chart packaged"
|
|
|
|
- name: Create Git Tag
|
|
if: steps.check_update.outputs.release_needed == 'true'
|
|
run: |
|
|
APP_VERSION="${{ steps.phpmyadmin.outputs.app_version }}"
|
|
if git rev-parse "v$APP_VERSION" >/dev/null 2>&1; then
|
|
echo "Tag v$APP_VERSION already exists, skipping"
|
|
else
|
|
git tag -a "v$APP_VERSION" -m "Release phpMyAdmin $APP_VERSION"
|
|
git push origin "v$APP_VERSION"
|
|
echo "Git tag v$APP_VERSION created"
|
|
fi
|
|
|
|
- name: Create Gitea Release
|
|
if: steps.check_update.outputs.release_needed == 'true'
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
APP_VERSION="${{ steps.phpmyadmin.outputs.app_version }}"
|
|
CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}')
|
|
PACKAGE_FILE="${CHART_NAME}-${APP_VERSION}.tgz"
|
|
RELEASE_BODY="phpMyAdmin Helm Chart v${APP_VERSION} - phpMyAdmin: ${{ steps.phpmyadmin.outputs.latest }}, Nginx: ${{ steps.nginx.outputs.latest }}"
|
|
|
|
# リリースが既に存在するか確認
|
|
EXISTING=$(curl -s \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/v${APP_VERSION}" | jq -r '.id // empty')
|
|
|
|
if [ -n "$EXISTING" ]; then
|
|
echo "Release v$APP_VERSION already exists (id=$EXISTING), skipping"
|
|
else
|
|
# リリースを作成
|
|
RELEASE_ID=$(curl -s -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" | 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
|
|
|
|
- name: Publish to Gitea Package Registry
|
|
if: steps.check_update.outputs.release_needed == 'true'
|
|
run: |
|
|
CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}')
|
|
APP_VERSION="${{ steps.phpmyadmin.outputs.app_version }}"
|
|
PACKAGE_FILE="${CHART_NAME}-${APP_VERSION}.tgz"
|
|
|
|
echo "Publishing ${PACKAGE_FILE} to Gitea Package Registry..."
|
|
curl --fail-with-body \
|
|
-u "${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_TOKEN }}" \
|
|
-X POST \
|
|
--upload-file "${PACKAGE_FILE}" \
|
|
"${REGISTRY_URL}/api/packages/${OWNER}/helm/api/charts"
|
|
|
|
echo "Chart published to registry successfully"
|
|
|
|
- name: Summary
|
|
run: |
|
|
APP_VERSION="${{ steps.phpmyadmin.outputs.app_version }}"
|
|
NGINX_VERSION="${{ steps.nginx.outputs.latest }}"
|
|
PMA_VERSION="${{ steps.phpmyadmin.outputs.latest }}"
|
|
UPDATE_NEEDED="${{ steps.check_update.outputs.update_needed }}"
|
|
RELEASE_NEEDED="${{ steps.check_update.outputs.release_needed }}"
|
|
echo "========================================"
|
|
if [ "$UPDATE_NEEDED" = "true" ]; then
|
|
echo "Update completed!"
|
|
else
|
|
echo "Already up to date, no changes."
|
|
fi
|
|
echo "========================================"
|
|
echo "phpMyAdmin: ${PMA_VERSION}"
|
|
echo "Nginx: ${NGINX_VERSION}"
|
|
if [ "$RELEASE_NEEDED" = "true" ]; then
|
|
echo "Chart Version: ${APP_VERSION} (released)"
|
|
echo "Registry: ${REGISTRY_URL}/api/packages/${OWNER}/helm"
|
|
else
|
|
echo "No release (nginx-only or no update)"
|
|
fi
|
|
echo "========================================"
|