Skip to content

Commit e80e4ef

Browse files
ci: Using a dynamically generated matrix for testing job setup (#3232)
* test: matrix building dynamically * test: calling building matrix * test: fix file permissions * feat: adding checkout * chore: adding changelog file 3232.changed.md * test: checks if github context is accessible from shell script * fix: wrong github user login * feat: checking in a script which test should be generated. * fix: final implementation * ci: replacing action * feat: adding hardlimit * fix: comments in shell file. * feat: adding matrix builder to local and minimal. renaming jobs. * fix: wrong context * feat: moving extended testing calculation to inside shell script. * fix: wrong matrix name * fix: coverage issues --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 587a0cb commit e80e4ef

File tree

3 files changed

+223
-107
lines changed

3 files changed

+223
-107
lines changed

.ci/build_matrix.sh

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
2+
3+
# List of versions
4+
versions=(
5+
# if added more "latest", change "$LATEST"
6+
'latest-ubuntu'
7+
'latest-ubuntu-student'
8+
'v24.2.0'
9+
'v24.2-ubuntu'
10+
'v24.2-ubuntu-student'
11+
'v24.1.0'
12+
'v24.1-ubuntu'
13+
'v24.1-ubuntu-student'
14+
'v23.2.0'
15+
'v23.2-ubuntu'
16+
'v23.1.0'
17+
'v23.1-ubuntu'
18+
'v22.2.1'
19+
'v22.2-ubuntu'
20+
)
21+
22+
LATEST=2 # for 'latest-ubuntu' and 'latest-ubuntu-student'
23+
24+
# Run only ubuntu jobs
25+
ONLY_UBUNTU="${ONLY_UBUNTU:-false}"
26+
27+
# Do not process more than the $AUTH_USER_LIMIT_VERSIONS versions in above list
28+
AUTH_USER_LIMIT_VERSIONS="${AUTH_USER_LIMIT_VERSIONS:-3}"
29+
AUTH_USER_LIMIT=$((LATEST+AUTH_USER_LIMIT_VERSIONS*3))
30+
31+
# Students licenses only last a year, hence $NON_AUTH_USER_LIMIT_VERSIONS cannot be more than 2.
32+
NON_AUTH_USER_LIMIT_VERSIONS="${NON_AUTH_USER_LIMIT_VERSIONS:-2}"
33+
NON_AUTH_USER_LIMIT=$((LATEST+NON_AUTH_USER_LIMIT_VERSIONS*3))
34+
35+
# Hard limit version. Generally do not process more than $HARD_LIMIT_VERSION
36+
LIMIT_VERSIONS="${LIMIT_VERSIONS:-0}"
37+
HARD_LIMIT_VERSION=$((LATEST+LIMIT_VERSIONS*3))
38+
39+
# Checking if extended testing must be done
40+
#
41+
42+
if [[ $ON_SCHEDULE || ( $ON_WORKFLOW_DISPATCH && $RUN_ALL_TEST ) || ( $ON_PUSH && $HAS_TAG ) ]]; then
43+
extended_testing=true
44+
else
45+
extended_testing=false
46+
fi
47+
48+
## Start
49+
JSON="{\"include\":["
50+
counter=0
51+
52+
# Loop through each version
53+
for version in "${versions[@]}"; do
54+
55+
# 1 based counter
56+
((counter++))
57+
58+
# Checking hardlimit
59+
if [[ $LIMIT_VERSIONS -ne 0 && $counter -gt $HARD_LIMIT_VERSION ]]; then
60+
echo "Reached limit."
61+
break
62+
fi
63+
64+
# checking version config
65+
if [[ "$version" == *"ubuntu"* ]]; then
66+
ON_UBUNTU=true;
67+
else
68+
ON_UBUNTU=false;
69+
fi
70+
71+
if [[ "$version" == *"student"* ]]; then
72+
ON_STUDENT=true;
73+
else
74+
ON_STUDENT=false;
75+
fi
76+
77+
# Printing
78+
echo "Processing $counter"
79+
echo " - Version: $version"
80+
echo " - extended_testing: $extended_testing"
81+
echo " - auth_user: $auth_user"
82+
echo " - Student: $ON_STUDENT"
83+
echo " - Ubuntu: $ON_UBUNTU"
84+
85+
# Early exiting if on Ubuntu only
86+
if [[ "$ON_UBUNTU" != "true" && "$ONLY_UBUNTU" == "true" ]]; then
87+
echo "Skipping non-ubuntu versions"
88+
continue
89+
fi
90+
91+
# main logic
92+
if [[ "$auth_user" == "true" ]]; then
93+
if [[ "$extended_testing" == "true" ]]; then
94+
# runs everything
95+
add_line="true";
96+
else
97+
# Runs only "latest" and last two versions.
98+
# Last 6 entries in the list above.
99+
if [[ $counter -le $AUTH_USER_LIMIT ]]; then
100+
add_line="true";
101+
else
102+
add_line="false";
103+
fi
104+
fi
105+
else
106+
if [[ $ON_STUDENT == "true" && $counter -le $NON_AUTH_USER_LIMIT ]]; then
107+
add_line="true";
108+
else
109+
add_line="false";
110+
fi
111+
fi
112+
113+
# Add line to json
114+
if [[ "$add_line" == "true" ]]; then
115+
JSONline="{\"mapdl-version\": \"$version\"},"
116+
117+
echo "ADDED line: $JSONline"
118+
119+
# checks that the line is not repeated before adding it.
120+
if [[ "$JSON" != *"$JSONline"* ]]; then
121+
JSON="$JSON$JSONline"
122+
fi
123+
else
124+
echo "NOT added line"
125+
fi
126+
echo ""
127+
128+
done
129+
130+
# Remove last "," and add closing brackets
131+
if [[ $JSON == *, ]]; then
132+
JSON="${JSON%?}"
133+
fi
134+
JSON="$JSON]}"
135+
echo "$JSON"
136+
137+
# Set output
138+
echo "matrix=$( echo "$JSON" )" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)