From 7808f78e1ca3c0214767b59d5bde1515fb96f3e2 Mon Sep 17 00:00:00 2001 From: pieter Date: Fri, 5 Dec 2025 01:46:14 +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 | 365 ++-------------------------- 1 file changed, 24 insertions(+), 341 deletions(-) diff --git a/.gitea/workflows/update-images.yaml b/.gitea/workflows/update-images.yaml index ddbbb0b..c73667f 100644 --- a/.gitea/workflows/update-images.yaml +++ b/.gitea/workflows/update-images.yaml @@ -26,10 +26,14 @@ jobs: echo "Checking nginx versions..." CURRENT=$(grep -A3 "nginx:" values.yaml | grep "tag:" | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ') echo "Current nginx: $CURRENT" - - LATEST=$(curl -s "https://registry.hub.docker.com/v2/repositories/library/nginx/tags?page_size=100&name=alpine-perl" | \ - jq -r '.results[].name' | \ - grep -E '^[0-9]+\.[0-9]+\.[0-9]+-alpine-perl + LATEST=$(curl -s "https://registry.hub.docker.com/v2/repositories/library/nginx/tags?page_size=100&name=alpine-perl" | 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 WordPress version id: wordpress @@ -38,10 +42,21 @@ jobs: echo "Checking WordPress versions..." CURRENT=$(grep -A3 "wordpress:" values.yaml | grep "tag:" | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ') echo "Current WordPress: $CURRENT" - - LATEST=$(curl -s "https://registry.hub.docker.com/v2/repositories/library/wordpress/tags?page_size=100&name=fpm-alpine" | \ - jq -r '.results[].name' | \ - grep -E '^[0-9]+\.[0-9]+\.[0-9]+-php[0-9]+\.[0-9]+-fpm-alpine + LATEST=$(curl -s "https://registry.hub.docker.com/v2/repositories/library/wordpress/tags?page_size=100&name=fpm-alpine" | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-php[0-9]+\.[0-9]+-fpm-alpine$' | sort -V | tail -1) + if [ -z "$LATEST" ]; then + echo "Warning: Could not fetch latest WordPress version, using current" + LATEST="$CURRENT" + fi + WP_VERSION=$(echo "$LATEST" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+') + if [ -z "$WP_VERSION" ]; then + echo "Error: Could not extract WordPress version" + exit 1 + fi + echo "Latest WordPress: $LATEST" + echo "WordPress version: $WP_VERSION" + echo "current=$CURRENT" >> $GITHUB_OUTPUT + echo "latest=$LATEST" >> $GITHUB_OUTPUT + echo "wp_version=$WP_VERSION" >> $GITHUB_OUTPUT - name: Determine if update is needed id: check_update @@ -51,10 +66,8 @@ jobs: NGINX_LATEST="${{ steps.nginx.outputs.latest }}" WP_CURRENT="${{ steps.wordpress.outputs.current }}" WP_LATEST="${{ steps.wordpress.outputs.latest }}" - echo "Nginx: $NGINX_CURRENT vs $NGINX_LATEST" echo "WordPress: $WP_CURRENT vs $WP_LATEST" - if [ "$NGINX_CURRENT" != "$NGINX_LATEST" ] || [ "$WP_CURRENT" != "$WP_LATEST" ]; then echo "update_needed=true" >> $GITHUB_OUTPUT echo "Update is needed" @@ -68,349 +81,19 @@ jobs: run: | set -e echo "Updating values.yaml..." - NGINX_OLD="${{ steps.nginx.outputs.current }}" NGINX_NEW="${{ steps.nginx.outputs.latest }}" sed -i "s|tag: \"${NGINX_OLD}\"|tag: \"${NGINX_NEW}\"|g" values.yaml - WP_OLD="${{ steps.wordpress.outputs.current }}" WP_NEW="${{ steps.wordpress.outputs.latest }}" sed -i "s|tag: \"${WP_OLD}\"|tag: \"${WP_NEW}\"|g" values.yaml - echo "values.yaml updated" git diff values.yaml - name: Update Chart.yaml version if: steps.check_update.outputs.update_needed == 'true' run: | - WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - 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 - - - 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 WordPress ${{ steps.wordpress.outputs.wp_version }}" - 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: | - WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - git tag -a "v$WP_VERSION" -m "Release WordPress $WP_VERSION" - git push origin "v$WP_VERSION" - echo "Git tag v$WP_VERSION created" - - - name: Create Gitea Release - if: steps.check_update.outputs.update_needed == 'true' - env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - run: | - WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}') - PACKAGE_FILE="${CHART_NAME}-${WP_VERSION}.tgz" - 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' - run: | - WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}') - PACKAGE_FILE="${CHART_NAME}-${WP_VERSION}.tgz" - 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}" . - 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}" - git push origin gh-pages - 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 to version ${WP_VERSION}" - | \ - 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 WordPress version - 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) - 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 - echo "WordPress: $CURRENT -> $LATEST (version: $WP_VERSION)" - - - 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 - 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: | - sed -i 's|tag: "${{ steps.nginx.outputs.current }}"|tag: "${{ steps.nginx.outputs.latest }}"|' values.yaml - 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 }}" - 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 - - - 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 WordPress ${{ steps.wordpress.outputs.wp_version }}" - 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: | - WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - git tag -a "v$WP_VERSION" -m "Release WordPress $WP_VERSION" - git push origin "v$WP_VERSION" - echo "Git tag v$WP_VERSION created" - - - name: Create Gitea Release - if: steps.check_update.outputs.update_needed == 'true' - env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - run: | - WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}') - PACKAGE_FILE="${CHART_NAME}-${WP_VERSION}.tgz" - 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' - run: | - WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}') - PACKAGE_FILE="${CHART_NAME}-${WP_VERSION}.tgz" - 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}" . - 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}" - git push origin gh-pages - 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 to version ${WP_VERSION}" - | \ - sort -V | \ - tail -1) - - if [ -z "$LATEST" ]; then - echo "Warning: Could not fetch latest WordPress version, using current" - LATEST="$CURRENT" - fi - - WP_VERSION=$(echo "$LATEST" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+') - - if [ -z "$WP_VERSION" ]; then - echo "Error: Could not extract WordPress version" - exit 1 - fi - - echo "Latest WordPress: $LATEST" - echo "WordPress version: $WP_VERSION" - echo "current=$CURRENT" >> $GITHUB_OUTPUT - echo "latest=$LATEST" >> $GITHUB_OUTPUT - echo "wp_version=$WP_VERSION" >> $GITHUB_OUTPUT - - - 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 - 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: | - sed -i 's|tag: "${{ steps.nginx.outputs.current }}"|tag: "${{ steps.nginx.outputs.latest }}"|' values.yaml - 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 }}" - 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 - - - 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 WordPress ${{ steps.wordpress.outputs.wp_version }}" - 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: | - WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - git tag -a "v$WP_VERSION" -m "Release WordPress $WP_VERSION" - git push origin "v$WP_VERSION" - echo "Git tag v$WP_VERSION created" - - - name: Create Gitea Release - if: steps.check_update.outputs.update_needed == 'true' - env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - run: | - WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}') - PACKAGE_FILE="${CHART_NAME}-${WP_VERSION}.tgz" - 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' - run: | - WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" - CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}') - PACKAGE_FILE="${CHART_NAME}-${WP_VERSION}.tgz" - 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}" . - 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}" - git push origin gh-pages - 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 to version ${WP_VERSION}" - | \ - 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 WordPress version - 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) - 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 - echo "WordPress: $CURRENT -> $LATEST (version: $WP_VERSION)" - - - 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 - 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: | - sed -i 's|tag: "${{ steps.nginx.outputs.current }}"|tag: "${{ steps.nginx.outputs.latest }}"|' values.yaml - 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: | + set -e WP_VERSION="${{ steps.wordpress.outputs.wp_version }}" sed -i "s/^version: .*/version: $WP_VERSION/" Chart.yaml sed -i "s/^appVersion: .*/appVersion: \"$WP_VERSION\"/" Chart.yaml