All checks were successful
Helm Chart Release / release-chart (push) Successful in 12s
248 lines
9.8 KiB
YAML
248 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:
|
||
|
||
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 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 if update is needed
|
||
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"
|
||
|
||
if [ "$NGINX_CURRENT" != "$NGINX_LATEST" ] || [ "$PMA_CURRENT" != "$PMA_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..."
|
||
|
||
# phpMyAdminバージョンを取得
|
||
APP_VERSION="${{ steps.phpmyadmin.outputs.app_version }}"
|
||
|
||
# Nginx更新
|
||
NGINX_OLD="${{ steps.nginx.outputs.current }}"
|
||
NGINX_NEW="${{ steps.nginx.outputs.latest }}"
|
||
if [ "$NGINX_OLD" != "$NGINX_NEW" ]; then
|
||
# nginxセクションのtagのみを更新(1つ目のタグ)
|
||
sed -i "0,/tag: \"${NGINX_OLD}\"/s//tag: \"${NGINX_NEW}\"/" values.yaml
|
||
echo "Nginx updated: $NGINX_OLD -> $NGINX_NEW"
|
||
fi
|
||
|
||
# phpMyAdmin更新
|
||
PMA_OLD="${{ steps.phpmyadmin.outputs.current }}"
|
||
PMA_NEW="${{ steps.phpmyadmin.outputs.latest }}"
|
||
if [ "$PMA_OLD" != "$PMA_NEW" ]; then
|
||
# phpmyadminセクションのtagのみを更新(2つ目のタグ)
|
||
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.update_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 "Gitea Actions Bot"
|
||
git config user.email "actions@gitea.local"
|
||
git add values.yaml Chart.yaml
|
||
git commit -m "chore: update to phpMyAdmin ${{ steps.phpmyadmin.outputs.app_version }}, nginx ${{ steps.nginx.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.phpmyadmin.outputs.app_version }}"
|
||
git tag -a "v$APP_VERSION" -m "Release phpMyAdmin $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.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}
|
||
|
||
Changes:
|
||
- phpMyAdmin: ${{ steps.phpmyadmin.outputs.latest }}
|
||
- Nginx: ${{ steps.nginx.outputs.latest }}
|
||
|
||
Automated release by Gitea Actions"
|
||
|
||
# リリースを作成
|
||
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"
|
||
|
||
# リリースIDを取得
|
||
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 with asset: ${PACKAGE_FILE}"
|
||
|
||
- name: Checkout Helm Repository
|
||
if: steps.check_update.outputs.update_needed == 'true'
|
||
uses: actions/checkout@v3
|
||
with:
|
||
repository: helmchart/repo
|
||
token: ${{ secrets.GITEA_TOKEN }}
|
||
path: helm-repo
|
||
fetch-depth: 0
|
||
|
||
- name: Update Helm Repository Index
|
||
if: steps.check_update.outputs.update_needed == 'true'
|
||
run: |
|
||
set -e
|
||
APP_VERSION="${{ steps.phpmyadmin.outputs.app_version }}"
|
||
CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}')
|
||
PACKAGE_FILE="${CHART_NAME}-${APP_VERSION}.tgz"
|
||
|
||
echo "Updating Helm repository..."
|
||
|
||
# パッケージファイルをHelmリポジトリにコピー
|
||
cp "${PACKAGE_FILE}" helm-repo/
|
||
|
||
cd helm-repo
|
||
|
||
# index.yamlを生成/更新
|
||
helm repo index . --url "https://git.cafepieters.com/helmchart/repo/raw/branch/main"
|
||
|
||
# コミットしてプッシュ
|
||
git config user.name "Gitea Actions Bot"
|
||
git config user.email "actions@gitea.local"
|
||
git add "${PACKAGE_FILE}" index.yaml
|
||
git commit -m "chore: add ${CHART_NAME} v${APP_VERSION}" || echo "No changes to commit"
|
||
git push origin main
|
||
|
||
echo "Helm repository updated successfully"
|
||
|
||
- name: Summary
|
||
if: steps.check_update.outputs.update_needed == 'true'
|
||
run: |
|
||
APP_VERSION="${{ steps.phpmyadmin.outputs.app_version }}"
|
||
NGINX_VERSION="${{ steps.nginx.outputs.latest }}"
|
||
PMA_VERSION="${{ steps.phpmyadmin.outputs.latest }}"
|
||
echo "========================================"
|
||
echo "Update completed successfully!"
|
||
echo "========================================"
|
||
echo "Chart Version: ${APP_VERSION}"
|
||
echo "phpMyAdmin: ${PMA_VERSION}"
|
||
echo "Nginx: ${NGINX_VERSION}"
|
||
echo "========================================"
|
||
echo "Helm repository updated at:"
|
||
echo "https://git.cafepieters.com/helmchart/repo"
|
||
echo "========================================" |