ci: enable test by comment trigger (#1648)
This commit is contained in:
45
.github/workflows/build.yml
vendored
45
.github/workflows/build.yml
vendored
@@ -1,16 +1,8 @@
|
|||||||
name: Build & Test
|
name: Build & Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request_target:
|
issue_comment:
|
||||||
branches: [master]
|
types: [created]
|
||||||
types:
|
|
||||||
- labeled
|
|
||||||
- unlabeled
|
|
||||||
paths-ignore:
|
|
||||||
- '.husky'
|
|
||||||
- '.vscode'
|
|
||||||
- 'docs/**'
|
|
||||||
- 'README.md'
|
|
||||||
# See https://docs.github.com/en/actions/using-jobs/using-concurrency
|
# See https://docs.github.com/en/actions/using-jobs/using-concurrency
|
||||||
concurrency:
|
concurrency:
|
||||||
# The concurrency group contains the workflow name and the branch name for
|
# The concurrency group contains the workflow name and the branch name for
|
||||||
@@ -22,10 +14,41 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
name: Build on Pull Request
|
name: Build on Pull Request
|
||||||
runs-on: ubuntu-latest
|
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
|
environment: development
|
||||||
|
|
||||||
steps:
|
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
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
|||||||
Reference in New Issue
Block a user