-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_success_timeout_big_test
executable file
·64 lines (54 loc) · 2.23 KB
/
check_success_timeout_big_test
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
#!/usr/bin/env bash
# Set maximum running time of the tests
#MAX_RUNTIME_SECONDS=$((330*60))
MAX_RUNTIME_SECONDS=0 # We do not check the running time of the tests
# Install jq
sudo apt update && sudo apt install -y jq
# Fetch the jobs for the current workflow run using the GitHub API
# $1 = ${{ secrets.GITHUB_TOKEN }}
# $2 = ${{ github.repository }}
# $3 = ${{ github.run_id }}
response=$(curl -s -H "Authorization: token $1" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$2/actions/runs/$3/jobs?per_page=100")
echo "Response:"
echo "$response"
echo "Jobs length:" "$(echo "$response" | jq ' .jobs | length')"
# Loop through all the test jobs
all_success_or_timeout=true
jobs_length=$(echo "$response" | jq ' .jobs | length')
for ((i=0; i<jobs_length; i++)); do
job=$(echo "$response" | jq ".jobs[$i]")
job_name=$(echo "$job" | jq -r '.name')
# Skip the current job, i.e., the job does the checking.
job_status=$(echo "$job" | jq -r '.status')
if [[ "$job_status" == "in_progress" ]] ; then
continue
fi
# Extract the conclusion and timestamps of the job
conclusion=$(echo "$job" | jq -r '.conclusion')
started_at=$(echo "$job" | jq -r '.started_at')
completed_at=$(echo "$job" | jq -r '.completed_at')
# Calculate the running time of the job
start_time=$(date --utc --date "$started_at" +%s)
end_time=$(date --utc --date "$completed_at" +%s)
runtime=$((end_time - start_time))
echo "$job_name": "$conclusion", running time: "$runtime"
# Check if the conclusion is successful or cancelled due to timeout or cancelled without starting
if [[ "$conclusion" == "success" ]]; then
continue
elif [[ "$job_name" == *big* ]] && [[ "$conclusion" == "cancelled" ]] && [[ "$runtime" -ge "$MAX_RUNTIME_SECONDS" ]] || [[ "$runtime" -eq "0" ]]; then
continue
else
all_success_or_timeout=false
break
fi
done
# Determine the final status of the workflow
if [[ "$all_success_or_timeout" == true ]]; then
echo "All tests are successful or cancelled due to timeout. The workflow is successful."
exit 0
else
echo "Some tests are unsuccessful or cancelled not due to timeout. The workflow is unsuccessful."
exit 42
fi