diff --git a/.gitea/workflows/renovate.yaml b/.gitea/workflows/renovate.yaml index 19df32b..2c3311d 100644 --- a/.gitea/workflows/renovate.yaml +++ b/.gitea/workflows/renovate.yaml @@ -27,10 +27,6 @@ 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 @@ -52,29 +48,35 @@ jobs: exit 0 fi - # 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 - - # Read the JSON array and create batches - echo "Creating batches of repositories..." - batches=$(jq -c 'if type == "array" then . else [] end | _nwise(5) | [.[]]' /tmp/renovate-repos.json) - - # 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" + # Use node to process JSON instead of jq (Node.js is already installed in the container) + node -e ' + const fs = require("fs"); + try { + const data = fs.readFileSync("/tmp/renovate-repos.json", "utf8"); + let repos = []; + try { + repos = JSON.parse(data); + if (!Array.isArray(repos)) { + repos = []; + } + } catch (e) { + console.error("Invalid JSON:", e.message); + } + + // Create batches of 5 repos + const batches = []; + for (let i = 0; i < repos.length; i += 5) { + batches.push(repos.slice(i, i + 5)); + } + + console.log(`Created ${batches.length} batches of repositories`); + // Output for GitHub Actions + fs.writeFileSync(process.env.GITHUB_OUTPUT, `batches=${JSON.stringify(batches)}\n`, {flag: "a"}); + } catch (e) { + console.error("Error processing repositories:", e.message); + fs.writeFileSync(process.env.GITHUB_OUTPUT, "batches=[]\n", {flag: "a"}); + } + ' renovate: name: Run Renovate @@ -100,31 +102,33 @@ jobs: restore-keys: | ${{ runner.os }}-renovate- - - name: Install jq - run: | - apt-get update && apt-get install -y jq - - name: Run Renovate on Batch run: | - # 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 + # Use node to process the batch and generate comma-separated repo list + node -e ' + const batch = JSON.parse(process.argv[1]); + if (batch && batch.length > 0) { + const repoList = batch.join(","); + console.log(`Processing repositories: ${repoList}`); + console.log(`::set-output name=repo_list::${repoList}`); + } else { + console.log("No repositories to process in this batch"); + console.log("::set-output name=repo_list::"); + } + ' '${{ toJson(matrix.batch) }}' - echo "Processing repositories: $REPOS" + # Get the repo list from the node script output + REPOS=$(node -e 'console.log(process.env.BATCH_JSON ? JSON.parse(process.env.BATCH_JSON).join(",") : "")' ) - # Run Renovate on the specific repositories + # Run Renovate on the specific repositories if any were found if [ -n "$REPOS" ]; then + echo "Processing: $REPOS" renovate $REPOS else echo "No repositories to process in this batch" fi env: + BATCH_JSON: ${{ toJson(matrix.batch) }} RENOVATE_CONFIG_FILE: "config.js" RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }}