Files
phpfpm/.gitea/workflows/image-update-and-release.yaml
Claude e21bc2e1a5
All checks were successful
Helm Chart Release / release-chart (push) Successful in 11s
fix: Revert to jq with proper URL filtering
Pythonアプローチで発生したYAMLエラーを解消。
jqベースに戻し、Docker Hub APIのnameパラメータで効率的にフィルタ。

Changes:
- Pythonスクリプトを削除(YAMLインデント問題の原因)
- jqベースのシンプルなパイプラインに戻す
- URLに&name=fpm-alpineパラメータを追加(必須)
- jqの自動インストールを追加(念のため)
- 正規表現パターンを維持(alpine 2-3桁対応)
- デバッグ出力を維持

URL: https://registry.hub.docker.com/v2/repositories/library/php/tags?page_size=100&name=fpm-alpine

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-10 12:46:39 +09:00

276 lines
11 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
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:
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 "Error: Could not extract PHP version from: $LATEST"
exit 1
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"
if [ "$NGINX_CURRENT" != "$NGINX_LATEST" ] || [ "$PHP_CURRENT" != "$PHP_LATEST" ] || [ "$SELENIUM_CURRENT" != "$SELENIUM_LATEST" ]; then
echo "update_needed=true" >> $GITHUB_OUTPUT
echo "Update is needed"
else
echo "update_needed=false" >> $GITHUB_OUTPUT
echo "Already up to date"
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.update_needed == '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"
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 }}"
git push origin main
- name: Package Helm Chart
if: steps.check_update.outputs.update_needed == 'true'
run: |
helm package .
echo "Helm chart packaged"
- name: Create Git Tag
if: steps.check_update.outputs.update_needed == 'true'
run: |
APP_VERSION="${{ steps.php.outputs.app_version }}"
git tag -a "v$APP_VERSION" -m "Release PHP $APP_VERSION"
git push origin "v$APP_VERSION"
echo "Git tag v$APP_VERSION created"
- name: Create Gitea Release
if: steps.check_update.outputs.update_needed == '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"
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"
- name: Update Helm Repository Index
if: steps.check_update.outputs.update_needed == 'true'
run: |
set -e
APP_VERSION="${{ steps.php.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 add README.md
git config user.name "GitHub Actions Bot"
git config user.email "actions@github.com"
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 "GitHub Actions Bot"
git config user.email "actions@github.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: 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 }}"
echo "Update completed!"
echo "- PHP: ${APP_VERSION}"
echo "- Nginx: ${NGINX_VERSION}"
echo "- Selenium: ${SELENIUM_VERSION}"