From e7d6bda7a59fea19fdc30e8319eac8881c67ace5 Mon Sep 17 00:00:00 2001 From: Himself65 Date: Tue, 21 Mar 2023 19:25:17 -0500 Subject: [PATCH] ci: enable test by comment trigger (#1648) --- .github/workflows/build.yml | 45 ++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e763c246eb..fb76a26854 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,16 +1,8 @@ name: Build & Test on: - pull_request_target: - branches: [master] - types: - - labeled - - unlabeled - paths-ignore: - - '.husky' - - '.vscode' - - 'docs/**' - - 'README.md' + issue_comment: + types: [created] # See https://docs.github.com/en/actions/using-jobs/using-concurrency concurrency: # The concurrency group contains the workflow name and the branch name for @@ -22,10 +14,41 @@ jobs: build: name: Build on Pull Request runs-on: ubuntu-latest - if: contains(github.event.pull_request.labels.*.name, 'safe to test') + if: github.repository == 'toeverything/AFFiNE' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/test run') environment: development steps: + - uses: actions/github-script@v6 + with: + script: | + const user = context.payload.sender.login + console.log(`Validate user: ${user}`) + let isAffineMember = false + try { + const { status } = await github.rest.orgs.checkMembershipForUser({ + org: 'toeverything', + username: user + }); + isAffineMember = (status === 204) + } catch (e) {} + if (isAffineMember) { + console.log('Allowed') + await github.rest.reactions.createForIssueComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: '+1', + }) + } else { + console.log('Not allowed') + await github.rest.reactions.createForIssueComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: '-1', + }) + throw new Error('not allowed') + } - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }}