diff --git a/.gitea/workflows/image-update-and-release.yaml b/.gitea/workflows/image-update-and-release.yaml index 4ffcfb7..8d0846f 100644 --- a/.gitea/workflows/image-update-and-release.yaml +++ b/.gitea/workflows/image-update-and-release.yaml @@ -72,8 +72,9 @@ jobs: # 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 + 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" @@ -115,17 +116,38 @@ jobs: 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 + + # 更新が必要かチェック + 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 "update_needed=false" >> $GITHUB_OUTPUT - echo "Already up to date" + echo "Already up to date - no action required" fi - name: Update values.yaml @@ -169,7 +191,7 @@ jobs: git diff values.yaml - name: Update Chart.yaml version - if: steps.check_update.outputs.update_needed == 'true' + if: steps.check_update.outputs.php_updated == 'true' run: | set -e APP_VERSION="${{ steps.php.outputs.app_version }}" @@ -183,26 +205,41 @@ 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 PHP ${{ steps.php.outputs.app_version }}, nginx ${{ steps.nginx.outputs.latest }}, selenium ${{ steps.selenium.outputs.latest }}" + + 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.update_needed == 'true' + if: steps.check_update.outputs.php_updated == 'true' run: | helm package . echo "Helm chart packaged" - name: Create Git Tag - if: steps.check_update.outputs.update_needed == 'true' + if: steps.check_update.outputs.php_updated == '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" + + # タグが既に存在する場合はスキップ + 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.update_needed == 'true' + if: steps.check_update.outputs.php_updated == 'true' env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} run: | @@ -210,13 +247,19 @@ jobs: 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" + + # リリースが既に存在する場合はスキップ + 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: Update Helm Repository Index - if: steps.check_update.outputs.update_needed == 'true' + if: steps.check_update.outputs.php_updated == 'true' run: | set -e APP_VERSION="${{ steps.php.outputs.app_version }}" @@ -270,7 +313,16 @@ jobs: 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}" \ No newline at end of file + 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 \ No newline at end of file