diff --git a/.gitea/workflows/renovate.yaml b/.gitea/workflows/renovate.yaml index a6da2b5..19df32b 100644 --- a/.gitea/workflows/renovate.yaml +++ b/.gitea/workflows/renovate.yaml @@ -27,6 +27,10 @@ jobs: ${{ runner.os }}-renovate-discovery-${{ hashFiles('config.js') }}- ${{ runner.os }}-renovate-discovery- + - name: Install jq + run: | + apt-get update && apt-get install -y jq + - name: Discover Repositories run: | renovate --write-discovered-repos=/tmp/renovate-repos.json @@ -41,24 +45,33 @@ jobs: - 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" + # Check if repos file exists and is not empty + if [ ! -f /tmp/renovate-repos.json ] || [ ! -s /tmp/renovate-repos.json ]; then + echo "No repositories discovered or file not created/empty" echo "batches=[]" >> $GITHUB_OUTPUT exit 0 fi - # Read the JSON array from the input file - json_array=$(cat /tmp/renovate-repos.json) + # Verify the file contains valid JSON + if ! jq empty /tmp/renovate-repos.json 2>/dev/null; then + echo "Invalid JSON in repositories file" + echo "batches=[]" >> $GITHUB_OUTPUT + exit 0 + fi - # Group repositories into batches of 5 + # Read the JSON array and create batches 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 .) + batches=$(jq -c 'if type == "array" then . else [] end | _nwise(5) | [.[]]' /tmp/renovate-repos.json) - # Set the output for the next job + # Handle empty results + if [ "$batches" = "" ] || [ "$batches" = "null" ]; then + echo "No valid repositories found" + echo "batches=[]" >> $GITHUB_OUTPUT + exit 0 + fi + + # Format as proper JSON array for GitHub Actions output + batches="[$(echo "$batches" | tr '\n' ',' | sed 's/,$//' )]" echo "batches=$batches" >> $GITHUB_OUTPUT echo "Created $(echo "$batches" | jq '. | length') batches of repositories" @@ -83,20 +96,34 @@ jobs: uses: actions/cache@v4 with: path: /tmp/renovate-cache - key: ${{ runner.os }}-renovate-batch-${{ join(matrix.batch, '-') }}-${{ hashFiles('config.js') }}-${{ github.run_id }} + key: ${{ runner.os }}-renovate-batch-${{ 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: Install jq + run: | + apt-get update && apt-get install -y jq + - name: Run Renovate on Batch run: | - # Convert array to comma-separated list - REPOS=$(echo '${{ toJson(matrix.batch) }}' | jq -r 'join(",")') + # Simple processing of batch array without complex jq + REPOS="" + for repo in $(echo '${{ toJson(matrix.batch) }}' | jq -r '.[]'); do + if [ -n "$REPOS" ]; then + REPOS="$REPOS,$repo" + else + REPOS="$repo" + fi + done + echo "Processing repositories: $REPOS" # Run Renovate on the specific repositories - renovate $REPOS + if [ -n "$REPOS" ]; then + renovate $REPOS + else + echo "No repositories to process in this batch" + fi env: RENOVATE_CONFIG_FILE: "config.js" RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }}