-
Notifications
You must be signed in to change notification settings - Fork 53
101 lines (91 loc) · 3.25 KB
/
pr-comment-ci.yml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: PR_COMMENT_CI
on:
issue_comment:
types: [created]
jobs:
check:
runs-on: ubuntu-latest
outputs:
next_action: ${{ steps.get-action.outputs.next_action }}
if: ${{ github.event.issue.pull_request }}
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
.github/CODEOWNERS
sparse-checkout-cone-mode: false
- uses: actions/github-script@v7
id: get-action
with:
script: |
const user = context.payload.comment.user.login
core.debug(`user: ${user}`)
const fs = require('fs')
const CODEOWNERS = fs.readFileSync('.github/CODEOWNERS', 'utf8')
core.debug(`CODEOWNERS: ${CODEOWNERS}`)
let isReviewer = false;
CODEOWNERS.match(/@\w+/g).forEach((owner) => {
if (owner === `@${user}`) {
isReviewer = true
}
})
let next_action = ''
if (isReviewer) {
const body = context.payload.comment.body
core.info(`body: ${body}`)
if (body.startsWith('/resolve-conflict')) {
next_action='resolve-conflict'
}
if(next_action){
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'rocket',
})
}
} else {
core.warning('You are not collaborator');
}
core.info(`next_action: ${next_action}`)
core.setOutput('next_action', next_action)
resolve-conflict:
needs: check
runs-on: ubuntu-latest
if: ${{ needs.check.outputs.next_action == 'resolve-conflict' }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PERSONAL_TOKEN }}
fetch-depth: 0
- name: gh checkout pr
env:
GH_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
run: gh pr checkout ${{ github.event.issue.number }}
- uses: pnpm/action-setup@v4
with:
version: 9
- name: Install Dependencies
run: pnpm install
- name: Merge main
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git merge main --no-commit || true
- name: Resolve conflict
run: |
count_both_modified=$(git status | grep -c 'both modified:') || true
both_modified_db=$(git status | grep 'both modified:' | grep -c 'db/TDesign.db') || true
echo "count_both_modified $count_both_modified"
echo "both_modified_db $both_modified_db"
if [ "$count_both_modified" -eq "$both_modified_db" ]&&[ "$count_both_modified" -eq "1" ]; then
git checkout --theirs db/TDesign.db
git add db/TDesign.db
nohup pnpm run dev &
sleep 10
pnpm api:upload
git commit -am "chore: resolve conflict"
git push
else
echo "Condition not established."
fi