forked from ivy-llc/ivy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_intelligent_tests_workflow.py
98 lines (96 loc) · 3.28 KB
/
generate_intelligent_tests_workflow.py
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
total_jobs = 40
job_prefix = "run_tests_"
print("name: intelligent-tests-pr")
print("on:")
print(" workflow_dispatch:")
print(" pull_request:")
print(" types: [ labeled, opened, synchronize, reopened, review_requested ]")
print()
print("permissions:")
print(" actions: read")
print("jobs:")
print(" display_test_results:")
print(" if: ${{ always() }}")
print(" runs-on: ubuntu-latest")
print(" needs:")
for i in range(1, total_jobs + 1):
print(f" - {job_prefix}{i}")
print()
print(" steps:")
print(" - name: Download all test results")
print(" uses: actions/download-artifact@v3")
print()
print(" - name: Combined Test Results")
print(" run: |")
print(
' find . -name "test_results_*.txt" -exec cat {} + >'
" combined_test_results.txt"
)
print(' echo "Test results summary:"')
print(" cat combined_test_results.txt")
print()
print(" - name: New Failures Introduced")
print(" run: |")
print(
' find . -name "new_failures_*.txt" -exec cat {} + > combined_failures.txt'
)
print(" if [ -s combined_failures.txt ]")
print(" then")
print(' echo "This PR introduces the following new failing tests:"')
print(" cat combined_failures.txt")
print(" else")
print(' echo "This PR does not introduce any new test failures! Yippee!"')
print(" fi")
print()
for i in range(1, total_jobs + 1):
print(f" {job_prefix}{i}:")
print(" runs-on: ubuntu-latest")
print(" steps:")
print(" - name: Checkout Ivy 🛎")
print(" uses: actions/checkout@v2")
print(" with:")
print(" path: ivy")
print(" persist-credentials: false")
print(' submodules: "recursive"')
print(" fetch-depth: 100")
print()
print(" - name: Determine and Run Tests")
print(" id: tests")
print(" run: |")
print(
f" git clone -b master{i} https://github.com/unifyai/Mapping.git"
" --depth 1"
)
print(" pip install pydriller")
print(" cp Mapping/tests.pbz2 ivy/")
print(" cd ivy")
print(" mkdir .ivy")
print(" touch .ivy/key.pem")
print(" echo -n ${{ secrets.USER_API_KEY }} > .ivy/key.pem")
if i == 1:
print(" python determine_tests.py extra")
else:
print(" python determine_tests.py")
print(" set -o pipefail")
print(
f" python run_tests_pr.py new_failures_{i}.txt | tee"
f" test_results_{i}.txt"
)
print(" continue-on-error: true")
print()
print(" - name: Upload test results")
print(" uses: actions/upload-artifact@v3")
print(" with:")
print(f" name: test_results_{i}")
print(f" path: ivy/test_results_{i}.txt")
print()
print(" - name: Upload New Failures")
print(" uses: actions/upload-artifact@v3")
print(" with:")
print(f" name: new_failures_{i}")
print(f" path: ivy/new_failures_{i}.txt")
print()
print(" - name: Check on failures")
print(" if: steps.tests.outcome != 'success'")
print(" run: exit 1")
print()