name: Auto-merge showcase PRs on: pull_request: branches: [main] paths: - "examples/showcases/**" permissions: contents: write pull-requests: write jobs: auto-merge: runs-on: ubuntu-latest steps: - name: Check author is on Demo team id: check-team uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 with: # Authorize on the PR AUTHOR (immutable for the lifetime of the PR), # never `context.actor` — `actor` is whoever triggered the most # recent event, so a team member synchronizing or reopening an # outsider's PR would otherwise green-light auto-merge of code # they didn't author. script: | const prAuthor = context.payload.pull_request.user.login; try { await github.rest.teams.getMembershipForUserInOrg({ org: 'CopilotKit', team_slug: 'demo', username: prAuthor, }); core.setOutput('is_demo', 'true'); } catch { core.info(`${prAuthor} is not a member of CopilotKit/demo`); core.setOutput('is_demo', 'false'); } - name: Check PR only touches showcases if: steps.check-team.outputs.is_demo == 'true' id: check-files uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 with: script: | const { data: files } = await github.rest.pulls.listFiles({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.payload.pull_request.number, per_page: 100, }); const allShowcases = files.every(f => f.filename.startsWith('examples/showcases/') ); if (!allShowcases) { const outside = files .filter(f => !f.filename.startsWith('examples/showcases/')) .map(f => f.filename); core.info(`Files outside showcases: ${outside.join(', ')}`); } core.setOutput('only_showcases', allShowcases.toString()); - name: Approve PR if: steps.check-team.outputs.is_demo == 'true' && steps.check-files.outputs.only_showcases == 'true' uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 with: script: | await github.rest.pulls.createReview({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.payload.pull_request.number, event: 'APPROVE', body: 'Auto-approved: showcase-only changes from CopilotKit/demo team member.', }); - name: Enable auto-merge if: steps.check-team.outputs.is_demo == 'true' && steps.check-files.outputs.only_showcases == 'true' uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 with: script: | await github.graphql(` mutation($prId: ID!) { enablePullRequestAutoMerge(input: { pullRequestId: $prId, mergeMethod: MERGE }) { clientMutationId } } `, { prId: context.payload.pull_request.node_id });