Skip to content

Commit bb8d2c9

Browse files
committed
chore
1 parent c7fa455 commit bb8d2c9

File tree

1 file changed

+98
-14
lines changed

1 file changed

+98
-14
lines changed

.github/workflows/trigger-tests.yml

Lines changed: 98 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,101 @@ jobs:
1212

1313
steps:
1414
- name: Trigger workflow in nvim-java/tests
15-
uses: actions/github-script@v7
16-
with:
17-
github-token: ${{ secrets.INTEGRATION_TEST_TOKEN }}
18-
script: |
19-
github.rest.repos.createDispatchEvent({
20-
owner: 'nvim-java',
21-
repo: 'tests',
22-
event_type: 'test-nvim-java',
23-
client_payload: {
24-
triggered_by: context.repo.repo,
25-
ref: context.sha,
26-
event_type: context.eventName
27-
}
28-
});
15+
runs: |
16+
OWNER="nvim-java"
17+
REPO="tests"
18+
19+
# Get workflows and extract URL and ID for "Test nvim-java Plugin"
20+
response=$(curl -s -L \
21+
-H "Accept: application/vnd.github+json" \
22+
-H "Authorization: Bearer $TOKEN" \
23+
-H "X-GitHub-Api-Version: 2022-11-28" \
24+
"https://api.github.com/repos/$OWNER/$REPO/actions/workflows")
25+
26+
# Extract URL and ID using jq
27+
workflow_url=$(echo "$response" | jq -r '.workflows[] | select(.name == "Test nvim-java Plugin") | .url')
28+
workflow_id=$(echo "$response" | jq -r '.workflows[] | select(.name == "Test nvim-java Plugin") | .id')
29+
30+
echo "Workflow URL: $workflow_url"
31+
echo "Workflow ID: $workflow_id"
32+
33+
# Trigger workflow dispatch
34+
if [ ! -z "$workflow_id" ]; then
35+
dispatch_response=$(curl -s -L \
36+
-X POST \
37+
-H "Accept: application/vnd.github+json" \
38+
-H "Authorization: Bearer $TOKEN" \
39+
-H "X-GitHub-Api-Version: 2022-11-28" \
40+
"https://api.github.com/repos/$OWNER/$REPO/actions/workflows/$workflow_id/dispatches" \
41+
-d '{"ref":"main"}')
42+
43+
echo "Workflow dispatch triggered"
44+
if [ ! -z "$dispatch_response" ]; then
45+
echo "Response:"
46+
echo "$dispatch_response" | jq '.'
47+
else
48+
echo "No response body (successful dispatch returns empty response)"
49+
fi
50+
51+
# Wait for the workflow run to start and get the run ID
52+
echo "Waiting for workflow run to start..."
53+
run_id=""
54+
start_time=$(date +%s)
55+
timeout=60 # 60 seconds timeout
56+
57+
while [ -z "$run_id" ]; do
58+
current_time=$(date +%s)
59+
if [ $((current_time - start_time)) -gt $timeout ]; then
60+
echo "Timeout waiting for workflow to start"
61+
exit 1
62+
fi
63+
64+
sleep 5
65+
runs_response=$(curl -s -L \
66+
-H "Accept: application/vnd.github+json" \
67+
-H "Authorization: Bearer $TOKEN" \
68+
-H "X-GitHub-Api-Version: 2022-11-28" \
69+
"https://api.github.com/repos/$OWNER/$REPO/actions/workflows/$workflow_id/runs?per_page=1")
70+
71+
latest_run_id=$(echo "$runs_response" | jq -r '.workflow_runs[0].id')
72+
latest_run_time=$(echo "$runs_response" | jq -r '.workflow_runs[0].created_at')
73+
74+
# Check if this run was created after we triggered the workflow
75+
if [ ! -z "$latest_run_id" ] && [ "$latest_run_id" != "null" ]; then
76+
run_created=$(date -d "$latest_run_time" +%s 2>/dev/null || echo "0")
77+
if [ $run_created -gt $((start_time - 10)) ]; then
78+
run_id=$latest_run_id
79+
echo "Found new workflow run: $run_id"
80+
fi
81+
fi
82+
done
83+
84+
# Wait for workflow to complete
85+
echo "Waiting for workflow run $run_id to complete..."
86+
while true; do
87+
run_response=$(curl -s -L \
88+
-H "Accept: application/vnd.github+json" \
89+
-H "Authorization: Bearer $TOKEN" \
90+
-H "X-GitHub-Api-Version: 2022-11-28" \
91+
"https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id")
92+
93+
status=$(echo "$run_response" | jq -r '.status')
94+
conclusion=$(echo "$run_response" | jq -r '.conclusion')
95+
96+
echo "Workflow status: $status"
97+
98+
if [ "$status" = "completed" ]; then
99+
echo "Workflow completed with conclusion: $conclusion"
100+
if [ "$conclusion" = "success" ]; then
101+
echo "Workflow succeeded!"
102+
exit 0
103+
else
104+
echo "Workflow failed with conclusion: $conclusion"
105+
exit 1
106+
fi
107+
fi
108+
109+
sleep 10
110+
done
111+
fi
112+

0 commit comments

Comments
 (0)