-
Notifications
You must be signed in to change notification settings - Fork 40
80 lines (72 loc) · 3.04 KB
/
Copy pathcomment-trigger.yml
File metadata and controls
80 lines (72 loc) · 3.04 KB
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
name: Test Trigger On Comment
on:
issue_comment:
types: [created]
jobs:
trigger-remote-test:
if: github.event.issue.pull_request
runs-on: ubuntu-latest
steps:
- name: Check team membership
id: check-team
env:
GH_TOKEN: ${{ secrets.PASEO_CI_PAT }}
run: |
response=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/orgs/paseo-network/teams/paseo-core/memberships/${{ github.event.comment.user.login }}")
if [ "$(echo "$response" | jq -r '.state // empty')" == "active" ]; then
echo "is_allowed=true" >> $GITHUB_OUTPUT
else
echo "is_allowed=false" >> $GITHUB_OUTPUT
fi
- name: Check comment content
if: steps.check-team.outputs.is_allowed == 'true'
id: check-comment
run: |
comment="${{ github.event.comment.body }}"
if [[ "$comment" =~ ^/bot.* ]]; then
echo "is_bot_command=true" >> $GITHUB_OUTPUT
echo "command=$comment" >> $GITHUB_OUTPUT
echo $command
else
echo "is_bot_command=false" >> $GITHUB_OUTPUT
fi
- name: Get PR Details
if: steps.check-comment.outputs.is_bot_command == 'true' && steps.check-team.outputs.is_allowed == 'true'
id: pr-details
env:
GH_TOKEN: ${{ secrets.PASEO_CI_PAT }}
run: |
pr_data=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}")
pr_branch=$(echo "$pr_data" | jq -r .head.ref)
echo "branch=$pr_branch" >> $GITHUB_OUTPUT
- name: Trigger Remote Test Workflow
if: steps.check-comment.outputs.is_bot_command == 'true' && steps.check-team.outputs.is_allowed == 'true'
env:
GH_TOKEN: ${{ secrets.ZONDAX_CI_PAT }}
run: |
response=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Zondax/paseo-runtime-test/actions/workflows/bot-trigger.yml/dispatches \
-d '{
"ref": "main",
"inputs": {
"target_repo": "https://github.com/${{ github.repository }}",
"target_branch": "${{ steps.pr-details.outputs.branch }}",
"pr_number": "${{ github.event.issue.number }}",
"command": "${{ steps.check-comment.outputs.command }}"
}' -w "%{http_code}" -o /dev/null)
if [ "$response" != "204" ]; then
echo "Failed to trigger remote test. HTTP status code: $response"
exit 1
fi