From 5613be4685075fcde4f2ef3047f25593a8a88717 Mon Sep 17 00:00:00 2001 From: pieter Date: Thu, 27 Nov 2025 22:18:27 +0000 Subject: [PATCH] =?UTF-8?q?.gitea/workflows/update-images.yaml=20=E3=82=92?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/update-images.yaml | 137 +++------------------------- 1 file changed, 13 insertions(+), 124 deletions(-) diff --git a/.gitea/workflows/update-images.yaml b/.gitea/workflows/update-images.yaml index b4980cd..6ae89fe 100644 --- a/.gitea/workflows/update-images.yaml +++ b/.gitea/workflows/update-images.yaml @@ -2,7 +2,7 @@ name: Update Docker Image Tags and Release Helm Chart on: schedule: - - cron: '0 2 * * 1' # 毎週月曜日午前2時 + - cron: '0 2 * * 1' workflow_dispatch: jobs: @@ -23,8 +23,7 @@ jobs: id: nginx run: | CURRENT=$(grep -A2 "nginx:" values.yaml | grep "tag:" | sed 's/.*tag: "\(.*\)"/\1/') - 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) + 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) echo "current=$CURRENT" >> $GITHUB_OUTPUT echo "latest=$LATEST" >> $GITHUB_OUTPUT echo "Nginx: $CURRENT -> $LATEST" @@ -33,12 +32,8 @@ jobs: id: wordpress run: | CURRENT=$(grep -A2 "wordpress:" values.yaml | grep "tag:" | sed 's/.*tag: "\(.*\)"/\1/') - LATEST=$(curl -s https://registry.hub.docker.com/v2/repositories/library/wordpress/tags?page_size=100 | \ - jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-php[0-9]+\.[0-9]+-fpm-alpine$' | sort -V | tail -1) - - # WordPressバージョンを抽出(例: 6.8.3-php8.4-fpm-alpine -> 6.8.3) + LATEST=$(curl -s https://registry.hub.docker.com/v2/repositories/library/wordpress/tags?page_size=100 | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-php[0-9]+\.[0-9]+-fpm-alpine$' | sort -V | tail -1) WP_VERSION=$(echo "$LATEST" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+') - echo "current=$CURRENT" >> $GITHUB_OUTPUT echo "latest=$LATEST" >> $GITHUB_OUTPUT echo "wp_version=$WP_VERSION" >> $GITHUB_OUTPUT @@ -47,8 +42,7 @@ jobs: - name: Determine if update is needed id: check_update run: | - if [ "${{ steps.nginx.outputs.current }}" != "${{ steps.nginx.outputs.latest }}" ] || \ - [ "${{ steps.wordpress.outputs.current }}" != "${{ steps.wordpress.outputs.latest }}" ]; then + if [ "${{ steps.nginx.outputs.current }}" != "${{ steps.nginx.outputs.latest }}" ] || [ "${{ steps.wordpress.outputs.current }}" != "${{ steps.wordpress.outputs.latest }}" ]; then echo "update_needed=true" >> $GITHUB_OUTPUT echo "Update is needed" else @@ -59,23 +53,16 @@ jobs: - name: Update values.yaml if: steps.check_update.outputs.update_needed == 'true' run: | - # Nginxタグ更新 sed -i 's|tag: "${{ steps.nginx.outputs.current }}"|tag: "${{ steps.nginx.outputs.latest }}"|' values.yaml - - # WordPressタグ更新 sed -i 's|tag: "${{ steps.wordpress.outputs.current }}"|tag: "${{ steps.wordpress.outputs.latest }}"|' values.yaml - echo "values.yaml updated" - name: Update Chart.yaml version if: steps.check_update.outputs.update_needed == 'true' run: | WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - - # Chart.yamlのversionとappVersionを更新 sed -i "s/^version: .*/version: $WP_VERSION/" Chart.yaml sed -i "s/^appVersion: .*/appVersion: \"$WP_VERSION\"/" Chart.yaml - echo "Chart.yaml updated to version $WP_VERSION" cat Chart.yaml @@ -84,14 +71,8 @@ jobs: 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 WordPress ${{ steps.wordpress.outputs.wp_version }} - -- nginx: ${{ steps.nginx.outputs.current }} → ${{ steps.nginx.outputs.latest }} -- wordpress: ${{ steps.wordpress.outputs.current }} → ${{ steps.wordpress.outputs.latest }} -- chart version: ${{ steps.wordpress.outputs.wp_version }}" - + git commit -m "chore: update to WordPress ${{ steps.wordpress.outputs.wp_version }}" git push origin main - name: Package Helm Chart @@ -116,73 +97,11 @@ jobs: WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}') PACKAGE_FILE="${CHART_NAME}-${WP_VERSION}.tgz" - - # リリースノートの生成 - cat > release_notes.md << 'NOTES' - ## WordPress Helm Chart v$WP_VERSION - - ### Updated Components - - | Component | Previous | Current | - |-----------|----------|---------| - | Nginx | `$NGINX_OLD` | `$NGINX_NEW` | - | WordPress | `$WP_OLD` | `$WP_NEW` | - - ### Installation - - ```bash - helm repo add myrepo https://gitea.example.com/user/repo/raw/branch/gh-pages - helm repo update - helm install wordpress myrepo/$CHART_NAME --version $WP_VERSION - ``` - - ### Upgrade - - ```bash - helm upgrade wordpress myrepo/$CHART_NAME --version $WP_VERSION - ``` - - --- - *This release was automatically generated* - NOTES - - # 変数を置換 - sed -i "s/\$WP_VERSION/${WP_VERSION}/g" release_notes.md - sed -i "s/\$CHART_NAME/${CHART_NAME}/g" release_notes.md - sed -i "s/\$NGINX_OLD/${{ steps.nginx.outputs.current }}/g" release_notes.md - sed -i "s/\$NGINX_NEW/${{ steps.nginx.outputs.latest }}/g" release_notes.md - sed -i "s/\$WP_OLD/${{ steps.wordpress.outputs.current }}/g" release_notes.md - sed -i "s/\$WP_NEW/${{ steps.wordpress.outputs.latest }}/g" release_notes.md - - RELEASE_BODY=$(cat release_notes.md | jq -Rs .) - - # Gitea APIでリリース作成 - curl -X POST \ - -H "Authorization: token ${GITEA_TOKEN}" \ - -H "Content-Type: application/json" \ - -d "{ - \"tag_name\": \"v${WP_VERSION}\", - \"name\": \"WordPress Helm Chart v${WP_VERSION}\", - \"body\": ${RELEASE_BODY}, - \"draft\": false, - \"prerelease\": false - }" \ - "${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${WP_VERSION}" | \ - jq -r '.id') - - # Helmパッケージをリリースにアタッチ - 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 "Gitea release v${WP_VERSION} created with chart package" + RELEASE_BODY="WordPress Helm Chart v${WP_VERSION} - Automated release" + curl -X POST -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/json" -d "{\"tag_name\":\"v${WP_VERSION}\",\"name\":\"v${WP_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${WP_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' @@ -190,49 +109,19 @@ jobs: WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}') PACKAGE_FILE="${CHART_NAME}-${WP_VERSION}.tgz" - - # gh-pagesブランチをチェックアウト git fetch origin gh-pages || git checkout --orphan gh-pages git checkout gh-pages || (git checkout --orphan gh-pages && git rm -rf .) - - # 新しいパッケージを追加 mv "${PACKAGE_FILE}" . - - # index.yamlを生成/更新 helm repo index . --url https://gitea.example.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${WP_VERSION} to Helm repository" + git commit -m "chore: add ${CHART_NAME} v${WP_VERSION}" git push origin gh-pages - - echo "Helm repository index updated" + echo "Helm repository updated" - name: Summary if: steps.check_update.outputs.update_needed == 'true' run: | WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - echo "## ✅ Update Completed" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "### Updated Images" >> $GITHUB_STEP_SUMMARY - echo "- **Nginx**: \`${{ steps.nginx.outputs.current }}\` → \`${{ steps.nginx.outputs.latest }}\`" >> $GITHUB_STEP_SUMMARY - echo "- **WordPress**: \`${{ steps.wordpress.outputs.current }}\` → \`${{ steps.wordpress.outputs.latest }}\`" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "### Chart Version" >> $GITHUB_STEP_SUMMARY - echo "- **Version**: \`${WP_VERSION}\`" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "### Actions Taken" >> $GITHUB_STEP_SUMMARY - echo "- ✅ Updated values.yaml" >> $GITHUB_STEP_SUMMARY - echo "- ✅ Updated Chart.yaml" >> $GITHUB_STEP_SUMMARY - echo "- ✅ Created Git tag v${WP_VERSION}" >> $GITHUB_STEP_SUMMARY - echo "- ✅ Created Gitea release" >> $GITHUB_STEP_SUMMARY - echo "- ✅ Updated Helm repository" >> $GITHUB_STEP_SUMMARY - - - name: No Update Needed - if: steps.check_update.outputs.update_needed == 'false' - run: | - echo "## No Update Needed" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "All images are already up to date." >> $GITHUB_STEP_SUMMARY \ No newline at end of file + echo "Update completed to version ${WP_VERSION}" \ No newline at end of file