Files
phpfpm/.gitea/workflows/image-update-and-release.yaml
Claude ce6fcab5f3
All checks were successful
Helm Chart Release / release-chart (push) Successful in 5s
Update Docker Image Tags and Release Helm Chart / update-and-release (push) Successful in 13s
fix: publish Helm chart to Gitea Package Registry instead of gh-pages
Replace gh-pages branch index approach with direct upload to the
official Gitea Package Registry (same method as helm-release.yaml).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-19 21:13:38 +09:00

298 lines
12 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Update Docker Image Tags and Release Helm Chart
on:
schedule:
- cron: '0 2 * * 1'
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 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"
# Docker Hub API v2を使用してタグを取得
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 PHP version
id: php
run: |
set -e
echo "Checking PHP versions..."
CURRENT=$(grep -A3 "php:" values.yaml | grep "tag:" | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ')
echo "Current PHP: $CURRENT"
# jqの確認とインストール
if ! command -v jq &> /dev/null; then
echo "jq not found, installing..."
sudo apt-get update -qq && sudo apt-get install -y -qq jq
fi
# Docker Hub API v2を使用してタグを取得fpm-alpineでフィルタ
echo "Fetching tags from Docker Hub..."
LATEST=$(curl -s "https://registry.hub.docker.com/v2/repositories/library/php/tags?page_size=100&name=fpm-alpine" | \
jq -r '.results[].name' | \
grep -E '^[0-9]+\.[0-9]+\.[0-9]+-fpm-alpine[0-9]+\.[0-9]{2,3}$' | \
sort -V | tail -1)
echo "DEBUG: Matched LATEST=$LATEST"
if [ -z "$LATEST" ]; then
echo "Warning: Could not fetch latest PHP version, using current"
LATEST="$CURRENT"
fi
# PHPバージョンを抽出 (8.5.2の部分)
APP_VERSION=$(echo "$LATEST" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
if [ -z "$APP_VERSION" ]; then
echo "Warning: Could not extract PHP version from: $LATEST"
echo "Using current version instead"
APP_VERSION=$(echo "$CURRENT" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
fi
echo "Latest PHP: $LATEST"
echo "PHP version: $APP_VERSION"
echo "current=$CURRENT" >> $GITHUB_OUTPUT
echo "latest=$LATEST" >> $GITHUB_OUTPUT
echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT
- name: Check for new Selenium version
id: selenium
run: |
set -e
echo "Checking Selenium versions..."
CURRENT=$(grep -A3 "selenium:" values.yaml | grep "tag:" | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ')
echo "Current Selenium: $CURRENT"
# Docker Hub API v2を使用してタグを取得
# パターン: 139.0-chromedriver-139.0 形式
LATEST=$(curl -s "https://registry.hub.docker.com/v2/repositories/selenium/standalone-chromium/tags?page_size=100" | \
jq -r '.results[].name' | \
grep -E '^[0-9]+\.[0-9]+-chromedriver-[0-9]+\.[0-9]+$' | \
sort -V | tail -1)
if [ -z "$LATEST" ]; then
echo "Warning: Could not fetch latest Selenium version, using current"
LATEST="$CURRENT"
fi
echo "Latest Selenium: $LATEST"
echo "current=$CURRENT" >> $GITHUB_OUTPUT
echo "latest=$LATEST" >> $GITHUB_OUTPUT
- name: Determine if update is needed
id: check_update
run: |
set -e
NGINX_CURRENT="${{ steps.nginx.outputs.current }}"
NGINX_LATEST="${{ steps.nginx.outputs.latest }}"
PHP_CURRENT="${{ steps.php.outputs.current }}"
PHP_LATEST="${{ steps.php.outputs.latest }}"
SELENIUM_CURRENT="${{ steps.selenium.outputs.current }}"
SELENIUM_LATEST="${{ steps.selenium.outputs.latest }}"
echo "Nginx: $NGINX_CURRENT vs $NGINX_LATEST"
echo "PHP: $PHP_CURRENT vs $PHP_LATEST"
echo "Selenium: $SELENIUM_CURRENT vs $SELENIUM_LATEST"
# 更新が必要かチェック
UPDATE_NEEDED=false
PHP_UPDATED=false
if [ "$PHP_CURRENT" != "$PHP_LATEST" ]; then
UPDATE_NEEDED=true
PHP_UPDATED=true
echo "PHP update detected"
fi
if [ "$NGINX_CURRENT" != "$NGINX_LATEST" ]; then
UPDATE_NEEDED=true
echo "Nginx update detected"
fi
if [ "$SELENIUM_CURRENT" != "$SELENIUM_LATEST" ]; then
UPDATE_NEEDED=true
echo "Selenium update detected"
fi
echo "update_needed=$UPDATE_NEEDED" >> $GITHUB_OUTPUT
echo "php_updated=$PHP_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_update.outputs.update_needed == 'true'
run: |
set -e
echo "Updating values.yaml..."
# PHPバージョンを取得
APP_VERSION="${{ steps.php.outputs.app_version }}"
# version フィールドを更新 (PHPバージョンと同一)
sed -i "s/^version: .*/version: \"${APP_VERSION}\"/" values.yaml
echo "Version updated to: ${APP_VERSION}"
# Nginx更新
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
# PHP更新
PHP_OLD="${{ steps.php.outputs.current }}"
PHP_NEW="${{ steps.php.outputs.latest }}"
if [ "$PHP_OLD" != "$PHP_NEW" ]; then
sed -i "s|tag: \"${PHP_OLD}\"|tag: \"${PHP_NEW}\"|g" values.yaml
echo "PHP updated: $PHP_OLD -> $PHP_NEW"
fi
# Selenium更新
SELENIUM_OLD="${{ steps.selenium.outputs.current }}"
SELENIUM_NEW="${{ steps.selenium.outputs.latest }}"
if [ "$SELENIUM_OLD" != "$SELENIUM_NEW" ]; then
sed -i "s|tag: \"${SELENIUM_OLD}\"|tag: \"${SELENIUM_NEW}\"|g" values.yaml
echo "Selenium updated: $SELENIUM_OLD -> $SELENIUM_NEW"
fi
echo "values.yaml updated"
git diff values.yaml
- name: Update Chart.yaml version
if: steps.check_update.outputs.php_updated == 'true'
run: |
set -e
APP_VERSION="${{ steps.php.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 "GitHub Actions Bot"
git config user.email "actions@github.com"
if [ "${{ steps.check_update.outputs.php_updated }}" = "true" ]; then
# PHP更新時はChart.yamlも含める
git add values.yaml Chart.yaml
git commit -m "chore: update to PHP ${{ steps.php.outputs.app_version }}, nginx ${{ steps.nginx.outputs.latest }}, selenium ${{ steps.selenium.outputs.latest }}"
else
# Nginx/Seleniumのみの更新時はvalues.yamlのみ
git add values.yaml
git commit -m "chore: update nginx to ${{ steps.nginx.outputs.latest }}, selenium to ${{ steps.selenium.outputs.latest }} (no release)"
fi
git push origin main
- name: Package Helm Chart
if: steps.check_update.outputs.php_updated == 'true'
run: |
helm package .
CHART_FILE=$(ls *.tgz)
echo "CHART_FILE=${CHART_FILE}" >> $GITHUB_ENV
echo "Helm chart packaged: ${CHART_FILE}"
- name: Create Git Tag
if: steps.check_update.outputs.php_updated == 'true'
run: |
APP_VERSION="${{ steps.php.outputs.app_version }}"
# タグが既に存在する場合はスキップ
if git rev-parse "v$APP_VERSION" >/dev/null 2>&1; then
echo "Tag v$APP_VERSION already exists, skipping tag creation"
else
git tag -a "v$APP_VERSION" -m "Release PHP $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.php_updated == 'true'
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
APP_VERSION="${{ steps.php.outputs.app_version }}"
CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}')
PACKAGE_FILE="${CHART_NAME}-${APP_VERSION}.tgz"
RELEASE_BODY="PHP Helm Chart v${APP_VERSION} - Automated release"
# リリースが既に存在する場合はスキップ
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 created"
fi
- name: Publish to Gitea Package Registry
if: steps.check_update.outputs.php_updated == 'true'
run: |
echo "🚀 Publishing ${CHART_FILE} to Gitea Package Registry..."
curl --fail-with-body \
-u "${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_TOKEN }}" \
-X POST \
--upload-file "${CHART_FILE}" \
"${REGISTRY_URL}/api/packages/${OWNER}/helm/api/charts"
echo "✅ Chart published successfully!"
- name: Summary
if: steps.check_update.outputs.update_needed == 'true'
run: |
APP_VERSION="${{ steps.php.outputs.app_version }}"
NGINX_VERSION="${{ steps.nginx.outputs.latest }}"
SELENIUM_VERSION="${{ steps.selenium.outputs.latest }}"
PHP_UPDATED="${{ steps.check_update.outputs.php_updated }}"
echo "Update completed!"
echo "- PHP: ${APP_VERSION}"
echo "- Nginx: ${NGINX_VERSION}"
echo "- Selenium: ${SELENIUM_VERSION}"
echo ""
if [ "$PHP_UPDATED" = "true" ]; then
echo "✅ PHP version updated - Release created (v${APP_VERSION})"
else
echo " Nginx/Selenium only update - No release (waiting for next PHP update)"
fi