22
22
required : false
23
23
type : string
24
24
default : " "
25
+ MODEL_CACHE_DIR :
26
+ description : " Cache Dir Use"
27
+ required : false
28
+ type : string
29
+ default : " "
25
30
26
31
jobs :
27
32
run_tests_with_coverage :
@@ -67,56 +72,102 @@ jobs:
67
72
fd_wheel_url : ${{ inputs.FASTDEPLOY_WHEEL_URL }}
68
73
CACHE_DIR : ${{ inputs.CACHE_DIR }}
69
74
BASE_REF : ${{ github.event.pull_request.base.ref }}
75
+ MODEL_CACHE_DIR : ${{ inputs.MODEL_CACHE_DIR }}
70
76
run : |
71
- set -x
72
- runner_name="${{ runner.name }}"
73
- CARD_ID=$(echo "${runner_name}" | awk -F'-' '{print $NF}')
74
- gpu_id=$(echo "$CARD_ID" | fold -w1 | paste -sd,)
75
-
76
- CACHE_DIR="${CACHE_DIR:-$(dirname "$(dirname "${{ github.workspace }}")")}"
77
- echo "CACHE_DIR is set to ${CACHE_DIR}"
78
- if [ ! -f "${CACHE_DIR}/gitconfig" ]; then
79
- touch "${CACHE_DIR}/gitconfig"
80
- fi
81
- PARENT_DIR=$(dirname "$WORKSPACE")
82
- echo "PARENT_DIR:$PARENT_DIR"
83
- docker run --rm --net=host \
84
- --cap-add=SYS_PTRACE --privileged --shm-size=64G \
85
- -v $(pwd):/workspace -w /workspace \
86
- -v "${CACHE_DIR}/gitconfig:/etc/gitconfig:ro" \
87
- -v "${CACHE_DIR}/.cache:/root/.cache" \
88
- -v "${CACHE_DIR}/ConfigDir:/root/.config" \
89
- -e TZ="Asia/Shanghai" \
90
- -e "fd_wheel_url=${fd_wheel_url}" \
91
- -e "BASE_REF=${BASE_REF}" \
92
- --gpus "\"device=${gpu_id}\"" ${docker_image} /bin/bash -c '
93
-
94
- git config --global --add safe.directory /workspace/FastDeploy
95
- cd FastDeploy
96
- python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
97
-
98
- pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
99
-
100
-
101
- python -m pip install coverage
102
- python -m pip install diff-cover
103
- python -m pip install ${fd_wheel_url}
104
- export COVERAGE_FILE=/workspace/FastDeploy/coveragedata/.coverage
105
- export COVERAGE_RCFILE=/workspace/FastDeploy/scripts/.coveragerc
106
- TEST_EXIT_CODE=0
107
- bash scripts/coverage_run.sh || TEST_EXIT_CODE=8
108
- git diff origin/${BASE_REF}..HEAD --unified=0 > diff.txt
109
- echo "TEST_EXIT_CODE=${TEST_EXIT_CODE}" >> exit_code.env
110
- coverage combine coveragedata/
111
- coverage xml -o python_coverage_all.xml
112
- COVERAGE_EXIT_CODE=0
113
- diff-cover python_coverage_all.xml --diff-file=diff.txt --fail-under=80 --json-report diff_coverage.json || COVERAGE_EXIT_CODE=9
114
- echo "COVERAGE_EXIT_CODE=${COVERAGE_EXIT_CODE}" >> exit_code.env
115
- python scripts/generate_diff_coverage_xml.py diff.txt python_coverage_all.xml
116
- '
117
- if [ -f FastDeploy/exit_code.env ]; then
118
- cat FastDeploy/exit_code.env >> $GITHUB_ENV
119
- fi
77
+ set -x
78
+ runner_name="${{ runner.name }}"
79
+ CARD_ID=$(echo "${runner_name}" | awk -F'-' '{print $NF}')
80
+ DEVICES=$(echo "$CARD_ID" | fold -w1 | paste -sd,)
81
+ DEVICE_PORT=$(echo "$DEVICES" | cut -d',' -f1)
82
+
83
+ FLASK_PORT=$((42068 + DEVICE_PORT * 100))
84
+ FD_API_PORT=$((42088 + DEVICE_PORT * 100))
85
+ FD_ENGINE_QUEUE_PORT=$((42058 + DEVICE_PORT * 100))
86
+ FD_METRICS_PORT=$((42078 + DEVICE_PORT * 100))
87
+ echo "Test ENV Parameter:"
88
+ echo "========================================================="
89
+ echo "FLASK_PORT=${FLASK_PORT}"
90
+ echo "FD_API_PORT=${FD_API_PORT}"
91
+ echo "FD_ENGINE_QUEUE_PORT=${FD_ENGINE_QUEUE_PORT}"
92
+ echo "FD_METRICS_PORT=${FD_METRICS_PORT}"
93
+ echo "DEVICES=${DEVICES}"
94
+ echo "========================================================="
95
+
96
+ CACHE_DIR="${CACHE_DIR:-$(dirname "$(dirname "${{ github.workspace }}")")}"
97
+ echo "CACHE_DIR is set to ${CACHE_DIR}"
98
+ if [ ! -f "${CACHE_DIR}/gitconfig" ]; then
99
+ touch "${CACHE_DIR}/gitconfig"
100
+ fi
101
+
102
+ PORTS=($FLASK_PORT $FD_API_PORT $FD_ENGINE_QUEUE_PORT $FD_METRICS_PORT)
103
+ LOG_FILE="./port_cleanup_$(date +%Y%m%d_%H%M%S).log"
104
+ echo "==== LOG_FILE is ${LOG_FILE} ===="
105
+
106
+ echo "==== PORT CLEAN BEFORE TASK RUN ====" | tee -a $LOG_FILE
107
+
108
+ for port in "${PORTS[@]}"; do
109
+ PIDS=$(lsof -t -i :$port || true)
110
+ if [ -n "$PIDS" ]; then
111
+ echo "Port $port is occupied by PID(s): $PIDS" | tee -a $LOG_FILE
112
+ echo "$PIDS" | xargs -r kill -9
113
+ echo "Port $port cleared" | tee -a $LOG_FILE
114
+ else
115
+ echo "Port $port is free" | tee -a $LOG_FILE
116
+ fi
117
+ done
118
+
119
+ echo "==== PORT CLEAN COMPLETE ====" | tee -a $LOG_FILE
120
+
121
+ docker run --rm --net=host \
122
+ --cap-add=SYS_PTRACE --shm-size=64G \
123
+ -v $(pwd):/workspace -w /workspace \
124
+ -v "${CACHE_DIR}/gitconfig:/etc/gitconfig:ro" \
125
+ -v "${CACHE_DIR}/.cache:/root/.cache" \
126
+ -v "${CACHE_DIR}/ConfigDir:/root/.config" \
127
+ -v "${MODEL_CACHE_DIR}:/ModelData:ro" \
128
+ -e "MODEL_PATH=/ModelData" \
129
+ -e "FD_API_PORT=${FD_API_PORT}" \
130
+ -e "FD_ENGINE_QUEUE_PORT=${FD_ENGINE_QUEUE_PORT}" \
131
+ -e "FD_METRICS_PORT=${FD_METRICS_PORT}" \
132
+ -e "FLASK_PORT=${FLASK_PORT}" \
133
+ -e TZ="Asia/Shanghai" \
134
+ -e "fd_wheel_url=${fd_wheel_url}" \
135
+ -e "BASE_REF=${BASE_REF}" \
136
+ --gpus "\"device=${DEVICES}\"" ${docker_image} /bin/bash -c '
137
+
138
+ git config --global --add safe.directory /workspace/FastDeploy
139
+ cd FastDeploy
140
+ python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
141
+
142
+ pip config set global.extra-index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
143
+
144
+ python -m pip install coverage
145
+ python -m pip install diff-cover
146
+ python -m pip install ${fd_wheel_url}
147
+ if [ -d "test/plugins" ]; then
148
+ cd test/plugins
149
+ python setup.py install
150
+ cd ../..
151
+ else
152
+ echo "Warning: test/plugins directory not found, skipping setup.py install"
153
+ fi
154
+ export COVERAGE_FILE=/workspace/FastDeploy/coveragedata/.coverage
155
+ export COVERAGE_RCFILE=/workspace/FastDeploy/scripts/.coveragerc
156
+ TEST_EXIT_CODE=0
157
+ bash scripts/coverage_run.sh || TEST_EXIT_CODE=8
158
+ git diff origin/${BASE_REF}..HEAD --unified=0 > diff.txt
159
+ echo "TEST_EXIT_CODE=${TEST_EXIT_CODE}" >> exit_code.env
160
+ coverage combine coveragedata/
161
+ coverage xml -o python_coverage_all.xml
162
+ COVERAGE_EXIT_CODE=0
163
+ diff-cover python_coverage_all.xml --diff-file=diff.txt --fail-under=80 --json-report diff_coverage.json || COVERAGE_EXIT_CODE=9
164
+ echo "COVERAGE_EXIT_CODE=${COVERAGE_EXIT_CODE}" >> exit_code.env
165
+ python scripts/generate_diff_coverage_xml.py diff.txt python_coverage_all.xml
166
+ '
167
+ if [ -f FastDeploy/exit_code.env ]; then
168
+ cat FastDeploy/exit_code.env >> $GITHUB_ENV
169
+ fi
170
+
120
171
- name : Upload unit resule and diff coverage to bos
121
172
id : cov_upload
122
173
shell : bash
@@ -152,32 +203,40 @@ jobs:
152
203
echo "unittest_failed_url=${UNIT_TEST_RESULT_URL}" >> $GITHUB_OUTPUT
153
204
echo "unittest_failed_url=${UNIT_TEST_RESULT_URL}" >> $GITHUB_ENV
154
205
fi
155
- - name : Determine Unit Succ and whether the coverage rate reaches 80%
206
+ - name : Check Unit Test Success
156
207
shell : bash
157
208
run : |
209
+ cd FastDeploy
158
210
if [ "$TEST_EXIT_CODE" -eq 8 ]; then
211
+ filename=$(basename "$unittest_failed_url")
159
212
if [ -z "${unittest_failed_url}" ]; then
160
213
echo "No diff unit failed file URL provided."
161
214
else
162
- wget ${unittest_failed_url} || echo "Download unittest file failed, but continuing..."
215
+ rm -rf "${filename}"
216
+ wget -O ${filename} ${unittest_failed_url} || echo "Download unittest file failed, but continuing..."
163
217
fi
164
218
echo "Unit tests failed (exit code 8)"
165
- filename=$(basename "$unittest_failed_url")
166
219
if [ -f "${filename}" ];then
167
220
echo "Failed test cases:"
168
221
cat "${filename}"
169
222
fi
170
223
exit "$TEST_EXIT_CODE"
171
224
fi
225
+ echo "All tests passed"
172
226
227
+ - name : Verify Code Coverage Threshold (80%)
228
+ shell : bash
229
+ run : |
230
+ cd FastDeploy
173
231
if [ "$COVERAGE_EXIT_CODE" -eq 9 ]; then
174
232
echo "Coverage generation failed (exit code 9)"
233
+ filename=$(basename "$diff_cov_result_json_url")
175
234
if [ -z "${diff_cov_result_json_url}" ]; then
176
235
echo "No diff cov result file URL provided."
177
236
else
178
- wget ${diff_cov_result_json_url} || echo "Download cov json file failed, but continuing..."
237
+ rm -rf "${filename}"
238
+ wget -O ${filename} ${diff_cov_result_json_url} || echo "Download cov json file failed, but continuing..."
179
239
fi
180
- filename=$(basename "$diff_cov_result_json_url")
181
240
if [ -f "${filename}" ];then
182
241
echo "Failed test cases:"
183
242
if command -v jq >/dev/null 2>&1; then
@@ -188,7 +247,7 @@ jobs:
188
247
fi
189
248
exit "$COVERAGE_EXIT_CODE"
190
249
fi
191
- echo "All tests and coverage passed"
250
+ echo "coverage passed"
192
251
exit 0
193
252
194
253
diff_coverage_report :
0 commit comments