All checks were successful
Helm Chart Release / release-chart (push) Successful in 12s
jqが利用できない環境でも動作するよう、Python3に変更。 Changes: - jqの依存を削除 - Python3でDocker Hub APIレスポンスをパース - 正規表現パターンマッチングをPythonで実装 - バージョンソートをPythonで実装 - デバッグ出力を追加(利用可能なタグ、マッチ数) Benefits: - 追加パッケージのインストール不要 - デバッグ情報が詳細 - より確実な動作 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
307 lines
12 KiB
YAML
307 lines
12 KiB
YAML
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"
|
|
|
|
# Docker Hub API v2を使用してタグを取得
|
|
echo "Fetching tags from Docker Hub..."
|
|
|
|
# Pythonを使用してJSONをパースし、タグを抽出
|
|
LATEST=$(python3 << 'PYTHON_SCRIPT'
|
|
import sys
|
|
import urllib.request
|
|
import json
|
|
import re
|
|
|
|
url = "https://registry.hub.docker.com/v2/repositories/library/php/tags?page_size=100"
|
|
try:
|
|
with urllib.request.urlopen(url) as response:
|
|
data = json.loads(response.read())
|
|
tags = [result['name'] for result in data.get('results', [])]
|
|
|
|
# パターン: 8.5.2-fpm-alpine3.23 形式
|
|
pattern = re.compile(r'^\d+\.\d+\.\d+-fpm-alpine\d+\.\d{2,3}$')
|
|
matching_tags = [tag for tag in tags if pattern.match(tag)]
|
|
|
|
# デバッグ出力
|
|
print("DEBUG: Available PHP tags (first 10):", file=sys.stderr)
|
|
for tag in [t for t in tags if 'fpm-alpine' in t][:10]:
|
|
print(f" {tag}", file=sys.stderr)
|
|
|
|
print(f"DEBUG: Matching tags count: {len(matching_tags)}", file=sys.stderr)
|
|
|
|
if matching_tags:
|
|
# バージョンソート
|
|
def version_key(tag):
|
|
parts = tag.split('-')[0].split('.')
|
|
return tuple(int(p) for p in parts)
|
|
|
|
sorted_tags = sorted(matching_tags, key=version_key)
|
|
latest = sorted_tags[-1]
|
|
print(latest)
|
|
else:
|
|
print("", end="")
|
|
except Exception as e:
|
|
print(f"ERROR: {e}", file=sys.stderr)
|
|
print("", end="")
|
|
PYTHON_SCRIPT
|
|
)
|
|
|
|
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}" |