From 011e8bf6a5f3f1335afeaff8bb2f32b760b37407 Mon Sep 17 00:00:00 2001 From: jank <jan@kjan.email> Date: Thu, 27 Mar 2025 17:27:36 +0000 Subject: [PATCH] Update .gitea/workflows/renovate.yaml --- .gitea/workflows/renovate.yaml | 215 ++++++++++++--------------------- 1 file changed, 79 insertions(+), 136 deletions(-) diff --git a/.gitea/workflows/renovate.yaml b/.gitea/workflows/renovate.yaml index 70bcbbd..bfc83db 100644 --- a/.gitea/workflows/renovate.yaml +++ b/.gitea/workflows/renovate.yaml @@ -7,164 +7,107 @@ on: push: jobs: - discover-repos: - name: Discover Repositories + renovate: + name: Renovate with Batching runs-on: ubuntu-latest - outputs: - repo-batches: ${{ steps.create-batches.outputs.batches }} steps: - name: Checkout uses: actions/checkout@v4 - - name: Install Renovate + - name: Install Renovate and Dependencies run: | npm install -g renovate - - - name: Discover Repositories - run: | - renovate --write-discovered-repos=renovate-repos.json - env: - RENOVATE_CONFIG_FILE: "config.js" - RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} - GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} - LOG_LEVEL: "info" - RENOVATE_AUTODISCOVER: "true" - - - name: Create Repository Batches - id: create-batches - run: | - if [ ! -f renovate-repos.json ] || [ ! -s renovate-repos.json ]; then - echo "No repositories discovered or file not created" - echo "batches=[]" >> $GITHUB_OUTPUT - exit 0 - fi - - # Install jq if not available if ! command -v jq &> /dev/null; then sudo apt-get update && sudo apt-get install -y jq fi - - # Check if file contains valid JSON - if ! jq . renovate-repos.json > /dev/null 2>&1; then - echo "File does not contain valid JSON" - echo "batches=[]" >> $GITHUB_OUTPUT - exit 0 - fi - - # Create batches using shell commands - REPO_COUNT=$(jq '. | length' renovate-repos.json) - if [ "$REPO_COUNT" -eq 0 ]; then - echo "No repositories found" - echo "batches=[]" >> $GITHUB_OUTPUT - exit 0 - fi - - echo "Found $REPO_COUNT repositories" - - # Create batches of 5 repos - BATCHES="[" - for i in $(seq 0 5 $((REPO_COUNT-1))); do - if [ "$i" -gt 0 ]; then - BATCHES="$BATCHES," - fi - - # Create a batch of up to 5 repos - BATCH="[" - for j in $(seq 0 4); do - IDX=$((i+j)) - if [ "$IDX" -lt "$REPO_COUNT" ]; then - if [ "$j" -gt 0 ]; then - BATCH="$BATCH," - fi - REPO=$(jq -r ".[$IDX]" renovate-repos.json) - BATCH="$BATCH\"$REPO\"" - fi - done - BATCH="$BATCH]" - BATCHES="$BATCHES$BATCH" - done - BATCHES="$BATCHES]" - - echo "batches=$BATCHES" >> $GITHUB_OUTPUT - echo "Created $(echo "$BATCHES" | jq '. | length') batches" - - renovate: - name: Run Renovate - needs: discover-repos - runs-on: ubuntu-latest - 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: Install Renovate + - name: Debug Environment run: | - npm install -g renovate - - - name: Run Renovate on Batch - run: | - # Convert batch to string and process safely - BATCH='${{ toJson(matrix.batch) }}' - - # Check if batch is valid - if [ "$BATCH" = "null" ] || [ "$BATCH" = "" ]; then - echo "Batch is empty or null" - exit 0 - fi - - # Parse batch and run Renovate - REPOS="" - # Parse JSON array using bash - BATCH=${BATCH//\[/} - BATCH=${BATCH//\]/} - BATCH=${BATCH//\"/} - BATCH=${BATCH//,/ } - - for REPO in $BATCH; do - if [ -n "$REPO" ]; then - if [ -n "$REPOS" ]; then - REPOS="$REPOS,$REPO" - else - REPOS="$REPO" - fi - fi - done - - if [ -n "$REPOS" ]; then - echo "Processing repositories: $REPOS" - renovate $REPOS + echo "Node version: $(node --version)" + echo "NPM version: $(npm --version)" + echo "JQ version: $(jq --version)" + echo "Current directory: $(pwd)" + ls -la + echo "Config file contents:" + if [ -f "config.js" ]; then + cat config.js else - echo "No repositories to process in this batch" + echo "Config file not found!" + fi + + - name: Discover Repositories + id: discover + run: | + echo "Starting repository discovery..." + renovate --write-discovered-repos=renovate-repos.json + + if [ -f renovate-repos.json ]; then + echo "Repository discovery results:" + cat renovate-repos.json + + if jq . renovate-repos.json > /dev/null 2>&1; then + echo "Valid JSON file found" + REPO_COUNT=$(jq '. | length' renovate-repos.json) + echo "Found $REPO_COUNT repositories" + + if [ "$REPO_COUNT" -gt 0 ]; then + # Create list of all repos for processing + ALL_REPOS=$(jq -r '. | join(",")' renovate-repos.json) + echo "all_repos=$ALL_REPOS" >> $GITHUB_OUTPUT + echo "All repositories: $ALL_REPOS" + else + echo "No repositories found in autodiscovery" + fi + else + echo "Invalid JSON in renovate-repos.json" + cat renovate-repos.json + fi + else + echo "No repository discovery results file created" fi + env: + RENOVATE_CONFIG_FILE: "config.js" + RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} + GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} + LOG_LEVEL: "debug" # Set to debug for more information + RENOVATE_AUTODISCOVER: "true" + + - name: Process All Repositories + if: steps.discover.outputs.all_repos != '' + run: | + ALL_REPOS="${{ steps.discover.outputs.all_repos }}" + echo "Processing all repositories: $ALL_REPOS" + + # Process in batches of 5 + IFS=',' read -ra REPO_ARRAY <<< "$ALL_REPOS" + + TOTAL=${#REPO_ARRAY[@]} + echo "Total repositories to process: $TOTAL" + + for ((i=0; i<TOTAL; i+=5)); do + BATCH="" + for ((j=i; j<i+5 && j<TOTAL; j++)); do + if [ -n "$BATCH" ]; then + BATCH="$BATCH,${REPO_ARRAY[$j]}" + else + BATCH="${REPO_ARRAY[$j]}" + fi + done + + echo "Processing batch $((i/5+1)): $BATCH" + renovate $BATCH + done env: RENOVATE_CONFIG_FILE: "config.js" RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} LOG_LEVEL: "info" - - renovate-default: - name: Run Renovate (Default) - needs: discover-repos - runs-on: ubuntu-latest - if: ${{ needs.discover-repos.outputs.repo-batches == '[]' }} - - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Install Renovate - run: | - npm install -g renovate - - - name: Run Renovate + - name: Run Default Renovate + if: steps.discover.outputs.all_repos == '' run: | + echo "No repositories discovered, running default renovate" renovate env: RENOVATE_CONFIG_FILE: "config.js"