From 74d9858c87badac8b156b79625e3127d15fe9383 Mon Sep 17 00:00:00 2001 From: jank Date: Thu, 27 Mar 2025 17:06:17 +0000 Subject: [PATCH] Update .gitea/workflows/renovate.yaml --- .gitea/workflows/renovate.yaml | 136 +++++++++++++++++++++++++++------ 1 file changed, 112 insertions(+), 24 deletions(-) diff --git a/.gitea/workflows/renovate.yaml b/.gitea/workflows/renovate.yaml index ee0aa4a..a6da2b5 100644 --- a/.gitea/workflows/renovate.yaml +++ b/.gitea/workflows/renovate.yaml @@ -7,41 +7,129 @@ on: push: jobs: - renovate: + discover-repos: + name: Discover Repositories runs-on: ubuntu-latest - # Pin to a specific Renovate version for stability (check ghcr.io for latest) - # Example: ghcr.io/renovatebot/renovate:37.250.0 - container: ghcr.io/renovatebot/renovate:39.219.2 # Pinned version - + container: ghcr.io/renovatebot/renovate:39.219.2 + outputs: + repo-batches: ${{ steps.create-batches.outputs.batches }} + steps: - # Checkout the repository containing config.js - name: Checkout uses: actions/checkout@v4 - - # Cache Renovate's dependency cache directory between runs + - name: Cache Renovate dependencies uses: actions/cache@v4 with: - path: /tmp/renovate-cache # Renovate's default cache directory - # Key based on OS, config file hash, and run ID (ensures save) - key: ${{ runner.os }}-renovate-${{ hashFiles('config.js') }}-${{ github.run_id }} - # Fallback keys for restoring from previous runs + path: /tmp/renovate-cache + key: ${{ runner.os }}-renovate-discovery-${{ hashFiles('config.js') }}-${{ github.run_id }} restore-keys: | - ${{ runner.os }}-renovate-${{ hashFiles('config.js') }}- - ${{ runner.os }}-renovate- + ${{ runner.os }}-renovate-discovery-${{ hashFiles('config.js') }}- + ${{ runner.os }}-renovate-discovery- + + - name: Discover Repositories + run: | + renovate --write-discovered-repos=/tmp/renovate-repos.json + env: + RENOVATE_CONFIG_FILE: "config.js" + RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} + GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} + LOG_LEVEL: "info" + RENOVATE_CACHE_DIR: /tmp/renovate-cache + RENOVATE_AUTODISCOVER: "true" + + - name: Create Repository Batches + id: create-batches + run: | + # Install jq (not included in Renovate image) + apt-get update && apt-get install -y jq + + # Check if repos file exists + if [ ! -f /tmp/renovate-repos.json ]; then + echo "No repositories discovered or file not created" + echo "batches=[]" >> $GITHUB_OUTPUT + exit 0 + fi + + # Read the JSON array from the input file + json_array=$(cat /tmp/renovate-repos.json) + + # Group repositories into batches of 5 + echo "Creating batches of repositories..." + batches=$(echo "$json_array" | jq -r '.[]' | xargs -n5 | jq -R -s 'split("\n") | map(select(length > 0) | split(" "))' | jq 'del(.[] | select(. == []))' | jq -c .) + + # Set the output for the next job + echo "batches=$batches" >> $GITHUB_OUTPUT + + echo "Created $(echo "$batches" | jq '. | length') batches of repositories" - # Run Renovate using the configuration file + renovate: + name: Run Renovate + needs: discover-repos + runs-on: ubuntu-latest + container: ghcr.io/renovatebot/renovate:39.219.2 + if: ${{ needs.discover-repos.outputs.repo-batches != '[]' }} + strategy: + matrix: + batch: ${{ fromJson(needs.discover-repos.outputs.repo-batches) }} + fail-fast: false + max-parallel: 5 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Cache Renovate dependencies + uses: actions/cache@v4 + with: + path: /tmp/renovate-cache + key: ${{ runner.os }}-renovate-batch-${{ join(matrix.batch, '-') }}-${{ hashFiles('config.js') }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-renovate-batch-${{ join(matrix.batch, '-') }}-${{ hashFiles('config.js') }}- + ${{ runner.os }}-renovate-batch-${{ join(matrix.batch, '-') }}- + ${{ runner.os }}-renovate- + + - name: Run Renovate on Batch + run: | + # Convert array to comma-separated list + REPOS=$(echo '${{ toJson(matrix.batch) }}' | jq -r 'join(",")') + echo "Processing repositories: $REPOS" + + # Run Renovate on the specific repositories + renovate $REPOS + env: + RENOVATE_CONFIG_FILE: "config.js" + RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} + GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} + LOG_LEVEL: "info" + RENOVATE_CACHE_DIR: /tmp/renovate-cache + + # Fallback job in case no repositories are found or for handling config repositories + renovate-default: + name: Run Renovate (Default) + needs: discover-repos + runs-on: ubuntu-latest + container: ghcr.io/renovatebot/renovate:39.219.2 + if: ${{ needs.discover-repos.outputs.repo-batches == '[]' }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Cache Renovate dependencies + uses: actions/cache@v4 + with: + path: /tmp/renovate-cache + key: ${{ runner.os }}-renovate-default-${{ hashFiles('config.js') }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-renovate-default-${{ hashFiles('config.js') }}- + ${{ runner.os }}-renovate-default- + - name: Run Renovate run: renovate env: - # --- Core Configuration --- - RENOVATE_CONFIG_FILE: "config.js" # Path to your config file - RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} # Token for Gitea - GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} # Only needed if Renovate MUST access github.com (e.g., for release notes). Remove if not needed. - - # --- Performance & Logging --- - # Use 'info' for normal runs, 'debug' only when troubleshooting + RENOVATE_CONFIG_FILE: "config.js" + RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} + GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} LOG_LEVEL: "info" - # Explicitly tell Renovate where the cache is (matches actions/cache path) RENOVATE_CACHE_DIR: /tmp/renovate-cache -