summaryrefslogtreecommitdiff
path: root/.github/workflows/auto-start-ci.yml
blob: 4cb5d49fe77324536fc3dc6f672d6d8f1ad277de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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: '*/5 * * * *'

concurrency: ${{ github.workflow }}

# todo (node-fetch not working on 18, waiting for node-core-utils to fix)
env:
  NODE_VERSION: 16

permissions:
  contents: read

jobs:
  get-prs-for-ci:
    permissions:
      pull-requests: read
    if: github.repository == 'nodejs/node'
    runs-on: ubuntu-latest
    outputs:
      numbers: ${{ steps.get_prs_for_ci.outputs.numbers }}
    steps:
      - name: Get Pull Requests
        id: get_prs_for_ci
        run: >
          numbers=$(gh pr list \
                  --repo ${{ github.repository }} \
                  --label 'request-ci' \
                  --json 'number' \
                  -t '{{ range . }}{{ .number }} {{ end }}' \
                  --limit 100)
          echo "numbers=$numbers" >> $GITHUB_OUTPUT
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  start-ci:
    permissions:
      contents: read
      pull-requests: write
    needs: get-prs-for-ci
    if: needs.get-prs-for-ci.outputs.numbers != ''
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c  # v3.3.0
        with:
          persist-credentials: false

      - name: Install Node.js
        uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c  # v3.6.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 ${{ secrets.JENKINS_USER }}
          ncu-config set token "${{ secrets.GH_USER_TOKEN }}"
          ncu-config set jenkins_token ${{ secrets.JENKINS_TOKEN }}
          ncu-config set owner "${{ github.repository_owner }}"
          ncu-config set repo "$(echo ${{ github.repository }} | cut -d/ -f2)"

      - name: Start the CI
        run: ./tools/actions/start-ci.sh ${{ needs.get-prs-for-ci.outputs.numbers }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}