current commit
261028.14 · meta: bump actions/setup-node from 7.0.0 to 7.1.0
# This action uses the following secrets:
#   JENKINS_USER: GitHub user whose Jenkins token is defined below
#   JENKINS_TOKEN: Jenkins token, to be used to start or resume CI
# Optional repository variables:
#   AUTO_START_CI_BATCH_SIZE: maximum PRs to process per run (default: 5)
#   AUTO_START_CI_MAX_WORKLOAD: pause at this many running or queued PR jobs (default: 15)
name: Auto Start CI

on:
  schedule:
    # Runs every five minutes (fastest the scheduler can run). Five minutes is
    # optimistic, it can take longer to run.
    # To understand why `schedule` is used instead of other events, refer to
    # ./doc/contributing/commit-queue.md
    - cron: 3/5 * * * *

concurrency: ${{ github.workflow }}

env:
  NODE_VERSION: lts/*

permissions:
  contents: read

jobs:
  get-prs-for-ci:
    permissions:
      pull-requests: read
    if: github.repository == 'nodejs/node'
    runs-on: ubuntu-slim
    outputs:
      numbers: ${{ steps.get_prs_for_ci.outputs.numbers }}
    steps:
      - name: Get Pull Requests
        id: get_prs_for_ci
        # Explicit bash enables pipefail so jq cannot hide a failed gh query.
        shell: bash
        run: |
          if ! [[ "$BATCH_SIZE" =~ ^[1-9][0-9]*$ ]]; then
            echo '::error::AUTO_START_CI_BATCH_SIZE must be a strictly positive integer'
            exit 1
          fi
          # Filter before selecting the batch; UNKNOWN mergeability is retried later.
          numbers=$(gh pr list \
                  --repo "$GITHUB_REPOSITORY" \
                  --json 'number,mergeable' \
                  --search 'review:approved label:request-ci,resume-ci' \
                  --limit 100 \
                  | jq --argjson limit "$BATCH_SIZE" \
                    '[.[] | select(.mergeable == "MERGEABLE") | .number] | .[:$limit] | map(tostring) | join(" ")' -r)
          echo "numbers=$numbers" >> "$GITHUB_OUTPUT"
        env:
          GH_TOKEN: ${{ github.token }}
          BATCH_SIZE: ${{ vars.AUTO_START_CI_BATCH_SIZE || '5' }}
  start-ci:
    permissions:
      actions: read
      checks: read
      contents: read
      pull-requests: write
      statuses: read
    needs: get-prs-for-ci
    if: needs.get-prs-for-ci.outputs.numbers != ''
    runs-on: ubuntu-slim
    steps:
      - name: Install Node.js
        uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1  # v7.1.0
        with:
          node-version: ${{ env.NODE_VERSION }}

      - name: Install @node-core/utils
        run: npm install -g @node-core/utils

      - name: Setup @node-core/utils
        run: |
          ncu-config set username "$USERNAME"
          ncu-config set token "$GH_TOKEN"
          ncu-config set jenkins_token "$JENKINS_TOKEN"
          ncu-config set owner "$GITHUB_REPOSITORY_OWNER"
          ncu-config set repo "${GITHUB_REPOSITORY#*/}"
        env:
          USERNAME: ${{ secrets.JENKINS_USER }}
          GH_TOKEN: ${{ github.token }}
          JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}

      - name: Start or resume the CI
        run: |
          read -r -a numbers <<< "$PULL_REQUESTS"
          curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/start-ci.sh" \
          | sh -s -- "${numbers[@]}"
        env:
          GH_TOKEN: ${{ github.token }}
          PULL_REQUESTS: ${{ needs.get-prs-for-ci.outputs.numbers }}
          MAX_WORKLOAD: ${{ vars.AUTO_START_CI_MAX_WORKLOAD || '15' }}