diff --git a/.gitea/workflows/renovate.yaml b/.gitea/workflows/renovate.yaml index 2c3311d..47f523c 100644 --- a/.gitea/workflows/renovate.yaml +++ b/.gitea/workflows/renovate.yaml @@ -10,7 +10,6 @@ jobs: discover-repos: name: Discover Repositories runs-on: ubuntu-latest - container: ghcr.io/renovatebot/renovate:39.219.2 outputs: repo-batches: ${{ steps.create-batches.outputs.batches }} @@ -18,71 +17,64 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Cache Renovate dependencies - uses: actions/cache@v4 + - name: Setup Renovate + uses: renovatebot/github-action@v39.221.0 with: - path: /tmp/renovate-cache - key: ${{ runner.os }}-renovate-discovery-${{ hashFiles('config.js') }}-${{ github.run_id }} - restore-keys: | - ${{ runner.os }}-renovate-discovery-${{ hashFiles('config.js') }}- - ${{ runner.os }}-renovate-discovery- + configurationFile: config.js + token: ${{ secrets.RENOVATE_TOKEN }} - name: Discover Repositories run: | - renovate --write-discovered-repos=/tmp/renovate-repos.json + 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_CACHE_DIR: /tmp/renovate-cache RENOVATE_AUTODISCOVER: "true" - name: Create Repository Batches id: create-batches + shell: bash run: | - # 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" + 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 - # 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); - } + # Read repositories and create batches of 5 + REPOS=$(cat renovate-repos.json) + + # Use Python (available in GitHub Actions runner) for JSON processing + BATCHES=$(python3 -c ' + import json + import sys + + try: + data = json.loads(sys.argv[1]) + if not isinstance(data, list): + print("[]") + sys.exit(0) - // Create batches of 5 repos - const batches = []; - for (let i = 0; i < repos.length; i += 5) { - batches.push(repos.slice(i, i + 5)); - } + # Create batches of 5 + batches = [] + for i in range(0, len(data), 5): + batches.append(data[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"}); - } - ' + print(json.dumps(batches)) + except Exception as e: + print(f"Error: {e}", file=sys.stderr) + print("[]") + ' "$REPOS") + + echo "Created batches: $BATCHES" + echo "batches=$BATCHES" >> $GITHUB_OUTPUT 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: @@ -94,6 +86,12 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Setup Renovate + uses: renovatebot/github-action@v39.221.0 + with: + configurationFile: config.js + token: ${{ secrets.RENOVATE_TOKEN }} + - name: Cache Renovate dependencies uses: actions/cache@v4 with: @@ -103,50 +101,56 @@ jobs: ${{ runner.os }}-renovate- - name: Run Renovate on Batch + shell: bash run: | - # 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) }}' + # Simple approach to create comma-separated list + REPOS="" + # Make sure batch is not empty + if [ -n "$BATCH" ] && [ "$BATCH" != "null" ]; then + # Convert JSON array to comma-separated string + REPOS=$(python3 -c ' + import json + import sys + + try: + batch = json.loads(sys.argv[1]) + if isinstance(batch, list) and batch: + print(",".join(batch)) + except Exception as e: + print(f"Error: {e}", file=sys.stderr) + ' "$BATCH") + fi - # 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 if any were found if [ -n "$REPOS" ]; then - echo "Processing: $REPOS" + echo "Processing repositories: $REPOS" renovate $REPOS else echo "No repositories to process in this batch" fi env: - BATCH_JSON: ${{ toJson(matrix.batch) }} + BATCH: ${{ toJson(matrix.batch) }} 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: Setup Renovate + uses: renovatebot/github-action@v39.221.0 + with: + configurationFile: config.js + token: ${{ secrets.RENOVATE_TOKEN }} + - name: Cache Renovate dependencies uses: actions/cache@v4 with: