Skip to content

Commit 0b0f2e3

Browse files
authored
[CI] Unified diff coverage upload logic (#5127)
* [CI] fix diff_coverage_report upload
1 parent 7454480 commit 0b0f2e3

File tree

2 files changed

+64
-24
lines changed

2 files changed

+64
-24
lines changed

.github/workflows/_unit_test_coverage.yml

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ jobs:
4545
needs: check_cov_skip
4646
if: needs.check_cov_skip.outputs.can-skip != 'true'
4747
outputs:
48-
diff_cov_file_url: ${{ steps.cov_upload.outputs.diff_cov_file_url }}
48+
diff_txt_url: ${{ steps.cov_upload.outputs.diff_txt_url }}
49+
all_cov_file_url: ${{ steps.cov_upload.outputs.all_cov_file_url }}
4950
unittest_failed_url: ${{ steps.cov_upload.outputs.unittest_failed_url }}
5051
diff_cov_result_json_url: ${{ steps.cov_upload.outputs.diff_cov_result_json_url }}
5152
steps:
@@ -202,7 +203,7 @@ jobs:
202203
if [[ "$IS_PR" == "true" ]]; then
203204
echo "Running diff coverage for PR..."
204205
diff-cover python_coverage_all.xml --diff-file=diff.txt --fail-under=80 --json-report diff_coverage.json || COVERAGE_EXIT_CODE=9
205-
python scripts/generate_diff_coverage_xml.py diff.txt python_coverage_all.xml
206+
# python scripts/generate_diff_coverage_xml.py diff.txt python_coverage_all.xml
206207
else
207208
echo "Running full coverage"
208209
coverage report -m > full_coverage_report.txt
@@ -251,12 +252,12 @@ jobs:
251252
target_path_stripped="${target_path#paddle-github-action/}"
252253
253254
if [[ "$IS_PR" == "true" ]]; then
254-
diff_cov_file="diff_coverage.xml"
255-
if [ -f ${diff_cov_file} ]; then
256-
python ${push_file} ${diff_cov_file} ${target_path}/CoverageData
257-
DIFF_COV_FILE_URL=https://paddle-github-action.bj.bcebos.com/${target_path_stripped}/CoverageData/${diff_cov_file}
258-
echo "diff_cov_file_url=${DIFF_COV_FILE_URL}" >> $GITHUB_OUTPUT
259-
echo "diff_cov_file_url=${DIFF_COV_FILE_URL}" >> $GITHUB_ENV
255+
diff_txt="diff.txt"
256+
if [ -f ${diff_txt} ]; then
257+
python ${push_file} ${diff_txt} ${target_path}/CoverageData
258+
DIFF_TXT_URL=https://paddle-github-action.bj.bcebos.com/${target_path_stripped}/CoverageData/${diff_txt}
259+
echo "diff_txt_url=${DIFF_TXT_URL}" >> $GITHUB_OUTPUT
260+
echo "diff_txt_url=${DIFF_TXT_URL}" >> $GITHUB_ENV
260261
fi
261262
262263
diff_cov_result_json="diff_coverage.json"
@@ -266,6 +267,14 @@ jobs:
266267
echo "diff_cov_result_json_url=${DIFF_COV_JSON_URL}" >> $GITHUB_OUTPUT
267268
echo "diff_cov_result_json_url=${DIFF_COV_JSON_URL}" >> $GITHUB_ENV
268269
fi
270+
271+
all_coverage_file="python_coverage_all.xml"
272+
if [ -f ${all_coverage_file} ]; then
273+
python ${push_file} ${all_coverage_file} ${target_path}/CoverageData
274+
ALL_COV_FILE_URL=https://paddle-github-action.bj.bcebos.com/${target_path_stripped}/CoverageData/${all_coverage_file}
275+
echo "all_cov_file_url=${ALL_COV_FILE_URL}" >> $GITHUB_OUTPUT
276+
echo "all_cov_file_url=${ALL_COV_FILE_URL}" >> $GITHUB_ENV
277+
fi
269278
fi
270279
271280
HAS_FAILED_TESTS=false
@@ -352,28 +361,54 @@ jobs:
352361
runs-on: ubuntu-latest
353362
timeout-minutes: 15
354363
env:
355-
fd_archive_url: ${{ inputs.FASTDEPLOY_ARCHIVE_URL }}
364+
diff_txt_url: ${{ needs.run_tests_with_coverage.outputs.diff_txt_url }}
365+
all_cov_file_url: ${{ needs.run_tests_with_coverage.outputs.all_cov_file_url }}
356366
steps:
357-
- name: coverage diff file download
367+
- name: Clone FastDeploy
368+
uses: actions/checkout@v4
369+
with:
370+
fetch-depth: 0
371+
- uses: actions/setup-python@v5
372+
with:
373+
python-version: '3.10'
374+
- name: Fetch base branch
375+
run: |
376+
echo "Fetching base branch: ${{ github.event.pull_request.base.ref }}"
377+
git fetch origin ${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}
378+
379+
- name: Download diff coverage file
358380
shell: bash
359-
env:
360-
diff_cov_file_url: ${{ needs.run_tests_with_coverage.outputs.diff_cov_file_url }}
361381
run: |
362-
wget -q --no-proxy ${fd_archive_url}
363-
tar -xf FastDeploy.tar.gz
364-
cd FastDeploy
365-
if [ -z "${diff_cov_file_url}" ]; then
366-
echo "No diff coverage file URL provided."
382+
if [ -z "${diff_txt_url}" ]; then
383+
echo "No diff.txt URL provided."
384+
exit 0
385+
fi
386+
387+
echo "Downloading diff.txt ..."
388+
if ! wget --no-proxy "${diff_txt_url}" -O diff.txt; then
389+
echo "Download failed, skipping upload."
367390
exit 0
368391
fi
369-
wget "${diff_cov_file_url}" -O ./diff_coverage.xml || echo "Download cov file failed, but continuing..."
392+
393+
echo "Downloading all coverage file..."
394+
if ! wget --no-proxy "${all_cov_file_url}" -O python_coverage_all.xml; then
395+
echo "Download failed, skipping upload."
396+
exit 0
397+
fi
398+
399+
if [ ! -s diff.txt ]; then
400+
echo "Downloaded diff.txt is empty!"
401+
exit 0
402+
fi
403+
404+
sed -i 's|<source>/workspace/FastDeploy/fastdeploy</source>|<source>fastdeploy</source>|' python_coverage_all.xml
405+
370406
- name: Upload diff coverage report
371-
if: ${{ needs.run_tests_with_coverage.outputs.diff_cov_file_url != null && needs.run_tests_with_coverage.outputs.diff_cov_file_url != '' }}
372-
uses: codecov/codecov-action@v5
407+
if: always() && hashFiles('diff.txt') != ''
408+
uses: codecov/codecov-action@v4
373409
with:
374-
files: ./FastDeploy/diff_coverage.xml
410+
files: ./diff.txt, ./python_coverage_all.xml
411+
flags: diff
375412
name: python diff coverage
413+
fail_ci_if_error: false
376414
verbose: true
377-
disable_search: true
378-
commit_parent: false
379-
flags: diff

scripts/codecov.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
codecov:
2+
require_ci_to_pass: false
3+
4+
fixes:
5+
- "/workspace/FastDeploy::/home/runner/work/FastDeploy/FastDeploy/FastDeploy"

0 commit comments

Comments
 (0)