forked from CUBRID/cubrid
-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (78 loc) · 3.21 KB
/
comment_trigger.yml
File metadata and controls
89 lines (78 loc) · 3.21 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
81
82
83
84
85
86
87
88
89
name: Comment trigger
on:
issue_comment:
types: [created, edited]
jobs:
run_test:
name: Run test on CircleCI
if: ${{ github.event.issue.pull_request != null && startsWith(github.event.comment.body, '/run') }}
runs-on: ubuntu-24.04
steps:
- name: Validate Command
shell: bash
run: |
COMMENT="${{ github.event.comment.body }}"
echo "[debug] Comment: $COMMENT"
# Allowed commands: /run all, /run shell, /run sql, /run medium
# Or any combination of them (up to 4)
if ! [[ "$COMMENT" =~ ^/run([[:space:]]+(all|shell|sql|medium)){1,4}$ ]]; then
echo "[info] Ignored invalid command: $COMMENT"
exit 0
fi
echo "[debug] Valid command: $COMMENT"
echo "VALID_RUN=true" >> $GITHUB_ENV
- name: Get Branch Name and Test Type
if: ${{ env.VALID_RUN == 'true' }}
shell: bash
run: |
COMMENT="${{ github.event.comment.body }}"
echo "[debug] Comment: $COMMENT"
TEST_TYPES="shell sql medium"
TEST_JSON="{"
# If 'all' is included, run all tests
if [[ "$COMMENT" =~ (^|[[:space:]])all($|[[:space:]]) ]]; then
echo "[debug] Running all tests"
for test in $TEST_TYPES; do
TEST_JSON+="\"run_${test}_test\":true,"
done
TEST_JSON+="\"run_all_test\":true,"
else
# Detect each combined test type separately
for test in $TEST_TYPES; do
if [[ "$COMMENT" =~ (^|[[:space:]])$test($|[[:space:]]) ]]; then
echo "[debug] Will run $test test"
TEST_JSON+="\"run_${test}_test\":true,"
fi
done
TEST_JSON+="\"run_all_test\":false,"
fi
BASELINE=$(echo "$COMMENT" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+-[0-9a-f]+' || echo "")
if [ -n "$BASELINE" ]; then
echo "[debug] Baseline Version: $BASELINE"
TEST_JSON+="\"baseline\":\"$BASELINE\"}"
else
echo "[debug] No Baseline Version provided. Will use latest from DB."
TEST_JSON+="\"baseline\":\"none\"}"
fi
TEST_JSON=$(echo $TEST_JSON | sed 's/,}/}/')
echo "TEST_JSON=$TEST_JSON" >> $GITHUB_ENV
echo "[debug] Test Parameters: $TEST_JSON"
- name: Trigger CircleCI Test
if: ${{ env.VALID_RUN == 'true' }}
env:
CIRCLECI_TOKEN: ${{ secrets.CIRCLECI_TOKEN }}
BRANCH_NAME: pull/${{ github.event.issue.number }}/head
TEST_JSON: ${{ env.TEST_JSON }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
shell: bash
run: |
DATA=$(echo '{"branch": "'"$BRANCH_NAME"'", "parameters": '"$TEST_JSON"'}')
echo "[debug] DATA: $DATA"
echo "[debug] REPO_OWNER: $REPO_OWNER"
echo "[debug] REPO_NAME: $REPO_NAME"
curl --request POST \
--url "https://circleci.com/api/v2/project/gh/$REPO_OWNER/$REPO_NAME/pipeline" \
--header "Circle-Token: $CIRCLECI_TOKEN" \
--header "Content-Type: application/json" \
--data "$DATA"