Skip to content

Commit

Permalink
Support CI summary in PR comments (#1624)
Browse files Browse the repository at this point in the history
Signed-off-by: Sun, Xuehao <xuehao.sun@intel.com>
Signed-off-by: chensuyue <suyue.chen@intel.com>
  • Loading branch information
XuehaoSun authored Mar 4, 2024
1 parent 28e82b1 commit d4bcdd4
Show file tree
Hide file tree
Showing 31 changed files with 320 additions and 236 deletions.
52 changes: 0 additions & 52 deletions .azure-pipelines/code-scan-neural-insights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,55 +57,3 @@ stages:
codeScanFileName: "pylint"
uploadPath: "pylint.json"
scanModule: "neural_insights"

- stage: CopyRight
displayName: CopyRight Code Scan
dependsOn: []
jobs:
- job: CopyRight
displayName: CopyRight
steps:
- script: |
rm -fr $(Build.SourcesDirectory) || true
echo y | docker system prune
displayName: "Clean workspace"
- checkout: self
displayName: "Checkout out Repo"

- task: Bash@3
inputs:
targetType: "inline"
script: |
source $(Build.SourcesDirectory)/.azure-pipelines/scripts/change_color.sh
set -e
mkdir -p $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)
RESET="echo -en \\E[0m \\n" # close
supported_extensions=(py, sh, yaml)
git --no-pager diff --name-only $(git show-ref -s remotes/origin/$(System.PullRequest.TargetBranch)) $(Build.SourcesDirectory)/neural_insights > $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/diff.log
files=$(cat $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/diff.log | awk '!a[$0]++')
for file in ${files}
do
if [[ "${supported_extensions[@]}" =~ "${file##*.}" ]]; then
if [ $(grep -E -c "Copyright \\(c\\) ([0-9]{4})(-[0-9]{4})? Intel Corporation" ${file}) = 0 ]; then
echo ${file} >> $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/copyright_issue_summary.log
$BOLD_YELLOW && echo " ----------------- Current log file output start --------------------------"
cat $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/copyright_issue_summary.log
$BOLD_YELLOW && echo " ----------------- Current log file output end --------------------------" && $RESET
$BOLD_RED && echo "CopyRight has something wrong! Please click on the artifact button to download and view the error log!" && $RESET; exit 1
fi
else
$LIGHT_PURPLE && echo "Skipping ${file}" && $RESET
fi
done
displayName: "CopyRight Check"

- task: PublishPipelineArtifact@1
condition: failed()
inputs:
targetPath: $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/copyright_issue_summary.log
artifact: copyright
publishLocation: "pipeline"
displayName: "PublishPipelineArtifact"
52 changes: 0 additions & 52 deletions .azure-pipelines/code-scan-neural-solution.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,55 +57,3 @@ stages:
codeScanFileName: "pylint"
uploadPath: "pylint.json"
scanModule: "neural_solution"

- stage: CopyRight
displayName: CopyRight Code Scan
dependsOn: []
jobs:
- job: CopyRight
displayName: CopyRight
steps:
- script: |
rm -fr $(Build.SourcesDirectory) || true
echo y | docker system prune
displayName: "Clean workspace"
- checkout: self
displayName: "Checkout out Repo"

- task: Bash@3
inputs:
targetType: "inline"
script: |
source $(Build.SourcesDirectory)/.azure-pipelines/scripts/change_color.sh
set -e
mkdir -p $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)
RESET="echo -en \\E[0m \\n" # close
supported_extensions=(py, sh, yaml)
git --no-pager diff --name-only $(git show-ref -s remotes/origin/$(System.PullRequest.TargetBranch)) $(Build.SourcesDirectory)/neural_solution > $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/diff.log
files=$(cat $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/diff.log | awk '!a[$0]++')
for file in ${files}
do
if [[ "${supported_extensions[@]}" =~ "${file##*.}" ]]; then
if [ $(grep -E -c "Copyright \\(c\\) ([0-9]{4})(-[0-9]{4})? Intel Corporation" ${file}) = 0 ]; then
echo ${file} >> $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/copyright_issue_summary.log
$BOLD_YELLOW && echo " ----------------- Current log file output start --------------------------"
cat $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/copyright_issue_summary.log
$BOLD_YELLOW && echo " ----------------- Current log file output end --------------------------" && $RESET
$BOLD_RED && echo "CopyRight has something wrong! Please click on the artifact button to download and view the error log!" && $RESET; exit 1
fi
else
$LIGHT_PURPLE && echo "Skipping ${file}" && $RESET
fi
done
displayName: "CopyRight Check"

- task: PublishPipelineArtifact@1
condition: failed()
inputs:
targetPath: $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/copyright_issue_summary.log
artifact: copyright
publishLocation: "pipeline"
displayName: "PublishPipelineArtifact"
52 changes: 0 additions & 52 deletions .azure-pipelines/code-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,55 +56,3 @@ stages:
parameters:
codeScanFileName: "pylint"
uploadPath: "pylint.json"

- stage: CopyRight
displayName: CopyRight Code Scan
dependsOn: []
jobs:
- job: CopyRight
displayName: CopyRight
steps:
- script: |
rm -fr $(Build.SourcesDirectory) || true
echo y | docker system prune
displayName: "Clean workspace"
- checkout: self
displayName: "Checkout out Repo"

- task: Bash@3
inputs:
targetType: "inline"
script: |
source $(Build.SourcesDirectory)/.azure-pipelines/scripts/change_color.sh
set -e
mkdir -p $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)
RESET="echo -en \\E[0m \\n" # close
supported_extensions=(py, sh, yaml)
git --no-pager diff --name-only $(git show-ref -s remotes/origin/$(System.PullRequest.TargetBranch)) $(Build.SourcesDirectory)/neural_compressor > $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/diff.log
files=$(cat $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/diff.log | awk '!a[$0]++')
for file in ${files}
do
if [[ "${supported_extensions[@]}" =~ "${file##*.}" ]]; then
if [ $(grep -E -c "Copyright \\(c\\) ([0-9]{4})(-[0-9]{4})? Intel Corporation" ${file}) = 0 ]; then
echo ${file} >> $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/copyright_issue_summary.log
$BOLD_YELLOW && echo " ----------------- Current log file output start --------------------------"
cat $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/copyright_issue_summary.log
$BOLD_YELLOW && echo " ----------------- Current log file output end --------------------------" && $RESET
$BOLD_RED && echo "CopyRight has something wrong! Please click on the artifact button to download and view the error log!" && $RESET; exit 1
fi
else
$LIGHT_PURPLE && echo "Skipping ${file}" && $RESET
fi
done
displayName: "CopyRight Check"

- task: PublishPipelineArtifact@1
condition: failed()
inputs:
targetPath: $(Build.SourcesDirectory)/$(CODE_SCAN_LOG_PATH)/copyright_issue_summary.log
artifact: copyright
publishLocation: "pipeline"
displayName: "PublishPipelineArtifact"
11 changes: 6 additions & 5 deletions .azure-pipelines/scripts/ut/3x/collect_log_3x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ coverage_compare="/neural-compressor/log_dir/coverage_compare.html"
cd /neural-compressor/log_dir

$BOLD_YELLOW && echo "collect coverage for PR branch" && $RESET
cp ut_coverage_3x/.coverage /neural-compressor/
cp ut_3x_coverage/.coverage /neural-compressor/
mkdir -p coverage_PR
cd /neural-compressor
coverage report -m --rcfile=${COVERAGE_RCFILE} | tee ${coverage_log}
Expand All @@ -20,18 +20,19 @@ ls -l log_dir/coverage_PR/htmlcov

$BOLD_YELLOW && echo "collect coverage for baseline" && $RESET
cd /neural-compressor
cp -r /neural-compressor/.azure-pipelines .azure-pipelines-pr
git config --global --add safe.directory /neural-compressor
git fetch
git checkout master
rm -rf build dist *egg-info
echo y | pip uninstall neural_compressor_${1}
cd /neural-compressor/.azure-pipelines/scripts && bash install_nc.sh ${1}
cd /neural-compressor/.azure-pipelines-pr/scripts && bash install_nc.sh ${1}

coverage erase
cd /neural-compressor/log_dir
mkdir -p coverage_base
rm -rf /neural-compressor/.coverage || true
cp ut_coverage_3x_baseline/.coverage /neural-compressor
cp ut_3x_baseline_coverage/.coverage /neural-compressor

cd /neural-compressor
coverage report -m --rcfile=${COVERAGE_RCFILE} | tee ${coverage_log_base}
Expand Down Expand Up @@ -123,10 +124,10 @@ if [[ ${#fail_items[@]} -ne 0 ]]; then
$BOLD_RED && echo "Unit Test failed with ${item} coverage decrease ${decrease}%" && $RESET
done
$BOLD_RED && echo "compare coverage to give detail info" && $RESET
bash /neural-compressor/.azure-pipelines/scripts/ut/compare_coverage.sh ${coverage_compare} ${coverage_log} ${coverage_log_base} "FAILED" ${coverage_PR_lines_rate} ${coverage_base_lines_rate} ${coverage_PR_branches_rate} ${coverage_base_branches_rate}
bash /neural-compressor/.azure-pipelines-pr/scripts/ut/compare_coverage.sh ${coverage_compare} ${coverage_log} ${coverage_log_base} "FAILED" ${coverage_PR_lines_rate} ${coverage_base_lines_rate} ${coverage_PR_branches_rate} ${coverage_base_branches_rate}
exit 1
else
$BOLD_GREEN && echo "Unit Test success with coverage lines: ${coverage_PR_lines_rate}%, branches: ${coverage_PR_branches_rate}%" && $RESET
$BOLD_GREEN && echo "compare coverage to give detail info" && $RESET
bash /neural-compressor/.azure-pipelines/scripts/ut/compare_coverage.sh ${coverage_compare} ${coverage_log} ${coverage_log_base} "SUCCESS" ${coverage_PR_lines_rate} ${coverage_base_lines_rate} ${coverage_PR_branches_rate} ${coverage_base_branches_rate}
bash /neural-compressor/.azure-pipelines-pr/scripts/ut/compare_coverage.sh ${coverage_compare} ${coverage_log} ${coverage_log_base} "SUCCESS" ${coverage_PR_lines_rate} ${coverage_base_lines_rate} ${coverage_PR_branches_rate} ${coverage_base_branches_rate}
fi
4 changes: 3 additions & 1 deletion .azure-pipelines/scripts/ut/3x/run_3x_ort.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mkdir -p ${LOG_DIR}
ut_log_name=${LOG_DIR}/ut_3x_ort.log
pytest --cov="${inc_path}" -vs --disable-warnings --html=report.html --self-contained-html . 2>&1 | tee -a ${ut_log_name}

cp .coverage ${LOG_DIR}/.coverage
cp report.html ${LOG_DIR}/

if [ $(grep -c '== FAILURES ==' ${ut_log_name}) != 0 ] || [ $(grep -c '== ERRORS ==' ${ut_log_name}) != 0 ] || [ $(grep -c ' passed' ${ut_log_name}) == 0 ]; then
Expand All @@ -30,4 +29,7 @@ if [ $(grep -c '== FAILURES ==' ${ut_log_name}) != 0 ] || [ $(grep -c '== ERRORS
exit 1
fi

# if ut pass, collect the coverage file into artifacts
cp .coverage ${LOG_DIR}/.coverage

echo "UT finished successfully! "
4 changes: 3 additions & 1 deletion .azure-pipelines/scripts/ut/3x/run_3x_pt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mkdir -p ${LOG_DIR}
ut_log_name=${LOG_DIR}/ut_3x_pt.log
pytest --cov="${inc_path}" -vs --disable-warnings --html=report.html --self-contained-html . 2>&1 | tee -a ${ut_log_name}

cp .coverage ${LOG_DIR}/.coverage
cp report.html ${LOG_DIR}/

if [ $(grep -c '== FAILURES ==' ${ut_log_name}) != 0 ] || [ $(grep -c '== ERRORS ==' ${ut_log_name}) != 0 ] || [ $(grep -c ' passed' ${ut_log_name}) == 0 ]; then
Expand All @@ -30,4 +29,7 @@ if [ $(grep -c '== FAILURES ==' ${ut_log_name}) != 0 ] || [ $(grep -c '== ERRORS
exit 1
fi

# if ut pass, collect the coverage file into artifacts
cp .coverage ${LOG_DIR}/.coverage

echo "UT finished successfully! "
4 changes: 3 additions & 1 deletion .azure-pipelines/scripts/ut/3x/run_3x_tf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ mkdir -p report
mv *.html report
pytest_html_merger -i ./report -o ./report.html

cp .coverage ${LOG_DIR}/.coverage
cp report.html ${LOG_DIR}/

if [ $(grep -c '== FAILURES ==' ${ut_log_name}) != 0 ] || [ $(grep -c '== ERRORS ==' ${ut_log_name}) != 0 ] || [ $(grep -c ' passed' ${ut_log_name}) == 0 ]; then
Expand All @@ -43,4 +42,7 @@ if [ $(grep -c '== FAILURES ==' ${ut_log_name}) != 0 ] || [ $(grep -c '== ERRORS
exit 1
fi

# if ut pass, collect the coverage file into artifacts
cp .coverage ${LOG_DIR}/.coverage

echo "UT finished successfully! "
25 changes: 8 additions & 17 deletions .azure-pipelines/scripts/ut/collect_log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ cd /neural-compressor/log_dir

$BOLD_YELLOW && echo "collect coverage for PR branch" && $RESET
mkdir -p coverage_PR
cp ut-coverage-adaptor/.coverage.adaptor ./coverage_PR/
cp ut-coverage-api/.coverage.api ./coverage_PR/
cp ut-coverage-tf-pruning/.coverage.tf_pruning ./coverage_PR/
cp ut-coverage-pt-pruning/.coverage.pt_pruning ./coverage_PR/
cp ut-coverage-tfnewapi/.coverage.tfnewapi ./coverage_PR/
cp ut-coverage-others/.coverage.others ./coverage_PR/
cp ut-coverage-itex/.coverage.itex ./coverage_PR/
cp ut_*_coverage/.coverage.* ./coverage_PR/

cd coverage_PR
coverage combine --keep --rcfile=${COVERAGE_RCFILE}
cp .coverage /neural-compressor/.coverage
Expand All @@ -26,24 +21,20 @@ coverage xml -o log_dir/coverage_PR/coverage.xml --rcfile=${COVERAGE_RCFILE}
ls -l log_dir/coverage_PR/htmlcov

cd /neural-compressor
cp -r /neural-compressor/.azure-pipelines .azure-pipelines-pr
git config --global --add safe.directory /neural-compressor
git fetch
git checkout master
rm -rf build dist *egg-info
echo y | pip uninstall neural-compressor
cd /neural-compressor/.azure-pipelines/scripts && bash install_nc.sh
cd /neural-compressor/.azure-pipelines-pr/scripts && bash install_nc.sh

$BOLD_YELLOW && echo "collect coverage for baseline" && $RESET
coverage erase
cd /neural-compressor/log_dir
mkdir -p coverage_base
cp ut-coverage-adaptor-base/.coverage.adaptor ./coverage_base/
cp ut-coverage-api-base/.coverage.api ./coverage_base/
cp ut-coverage-tf-pruning-base/.coverage.tf_pruning ./coverage_base/
cp ut-coverage-pt-pruning-base/.coverage.pt_pruning ./coverage_base/
cp ut-coverage-tfnewapi-base/.coverage.tfnewapi ./coverage_base/
cp ut-coverage-others-base/.coverage.others ./coverage_base/
cp ut-coverage-itex-base/.coverage.itex ./coverage_base/
cp ut-base_*_coverage/.coverage.* ./coverage_base/

cd coverage_base
coverage combine --keep --rcfile=${COVERAGE_RCFILE}
cp .coverage /neural-compressor/.coverage
Expand Down Expand Up @@ -137,10 +128,10 @@ if [[ ${#fail_items[@]} -ne 0 ]]; then
$BOLD_RED && echo "Unit Test failed with ${item} coverage decrease ${decrease}%" && $RESET
done
$BOLD_RED && echo "compare coverage to give detail info" && $RESET
bash /neural-compressor/.azure-pipelines/scripts/ut/compare_coverage.sh ${coverage_compare} ${coverage_log} ${coverage_log_base} "FAILED" ${coverage_PR_lines_rate} ${coverage_base_lines_rate} ${coverage_PR_branches_rate} ${coverage_base_branches_rate}
bash /neural-compressor/.azure-pipelines-pr/scripts/ut/compare_coverage.sh ${coverage_compare} ${coverage_log} ${coverage_log_base} "FAILED" ${coverage_PR_lines_rate} ${coverage_base_lines_rate} ${coverage_PR_branches_rate} ${coverage_base_branches_rate}
exit 1
else
$BOLD_GREEN && echo "Unit Test success with coverage lines: ${coverage_PR_lines_rate}%, branches: ${coverage_PR_branches_rate}%" && $RESET
$BOLD_GREEN && echo "compare coverage to give detail info" && $RESET
bash /neural-compressor/.azure-pipelines/scripts/ut/compare_coverage.sh ${coverage_compare} ${coverage_log} ${coverage_log_base} "SUCCESS" ${coverage_PR_lines_rate} ${coverage_base_lines_rate} ${coverage_PR_branches_rate} ${coverage_base_branches_rate}
bash /neural-compressor/.azure-pipelines-pr/scripts/ut/compare_coverage.sh ${coverage_compare} ${coverage_log} ${coverage_log_base} "SUCCESS" ${coverage_PR_lines_rate} ${coverage_base_lines_rate} ${coverage_PR_branches_rate} ${coverage_base_branches_rate}
fi
Loading

0 comments on commit d4bcdd4

Please sign in to comment.