| 1 | name: (Shared) Check maintainer |
| 2 | |
| 3 | on: |
| 4 | workflow_call: |
| 5 | inputs: |
| 6 | actor: |
| 7 | required: true |
| 8 | type: string |
| 9 | outputs: |
| 10 | is_core_team: |
| 11 | value: ${{ jobs.check_maintainer.outputs.is_core_team }} |
| 12 | |
| 13 | permissions: {} |
| 14 | |
| 15 | env: |
| 16 | TZ: /usr/share/zoneinfo/America/Los_Angeles |
| 17 | # https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout |
| 18 | SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1 |
| 19 | |
| 20 | jobs: |
| 21 | check_maintainer: |
| 22 | runs-on: ubuntu-latest |
| 23 | permissions: |
| 24 | # We fetch the contents of the MAINTAINERS file |
| 25 | contents: read |
| 26 | outputs: |
| 27 | is_core_team: ${{ steps.check_if_actor_is_maintainer.outputs.result }} |
| 28 | steps: |
| 29 | - name: Check if actor is maintainer |
| 30 | id: check_if_actor_is_maintainer |
| 31 | uses: actions/github-script@v7 |
| 32 | with: |
| 33 | script: | |
| 34 | const fs = require('fs'); |
| 35 | const actor = '${{ inputs.actor }}'; |
| 36 | const res = await github.rest.repos.getContent({ |
| 37 | owner: 'facebook', |
| 38 | repo: 'react', |
| 39 | path: 'MAINTAINERS', |
| 40 | ref: 'main', |
| 41 | headers: { Accept: 'application/vnd.github+json' } |
| 42 | }); |
| 43 | if (res.status !== 200) { |
| 44 | console.error(res); |
| 45 | throw new Error('Unable to fetch MAINTAINERS file'); |
| 46 | } |
| 47 | content = Buffer.from(res.data.content, 'base64').toString(); |
| 48 | if (content == null || typeof content !== 'string') { |
| 49 | throw new Error('Unable to retrieve MAINTAINERS file'); |
| 50 | } |
| 51 | |
| 52 | const maintainers = new Set(content.split('\n')); |
| 53 | if (maintainers.has(actor)) { |
| 54 | console.log(`🟢 ${actor} is a maintainer`); |
| 55 | return true; |
| 56 | } |
| 57 | console.log(`🔴 ${actor} is NOT a maintainer`); |
| 58 | return null; |