-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf1f0c3
commit ed5e303
Showing
2 changed files
with
206 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# | ||
# Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved. | ||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
# | ||
# This code is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License version 2 only, as | ||
# published by the Free Software Foundation. Alibaba designates this | ||
# particular file as subject to the "Classpath" exception as provided | ||
# by Oracle in the LICENSE file that accompanied this code. | ||
# | ||
# This code is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
# version 2 for more details (a copy is included in the LICENSE file that | ||
# accompanied this code). | ||
# | ||
# You should have received a copy of the GNU General Public License version | ||
# 2 along with this work; if not, write to the Free Software Foundation, | ||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
|
||
name: 'Coverage test' | ||
|
||
inputs: | ||
reset-commit-id: | ||
required: false | ||
type: string | ||
outputs: | ||
data: | ||
value: ${{ steps.get-cov-report.outputs.data }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: 'Checkout source code' | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 100 | ||
|
||
- name: 'Reset to specific commit' | ||
run: | | ||
echo "${{ inputs.reset-commit-id }}" | ||
git reset --hard ${{ inputs.reset-commit-id }} | ||
shell: bash | ||
if: ${{ inputs.reset-commit-id }} != "" | ||
|
||
- name: 'Install dependencies' | ||
run: | | ||
apt --help &>/dev/null | ||
if [ $? -eq 0 ];then | ||
sudo apt-get install -y openssl libssl-dev llvm | ||
else | ||
yum --help &>/dev/null | ||
if [ $? -eq 0 ];then | ||
sudo yum install -y openssl openssl-devel llvm | ||
else | ||
exit 1 | ||
fi | ||
fi | ||
shell: bash | ||
|
||
- name: 'Install newer clang' | ||
run: | | ||
apt --help &>/dev/null | ||
if [ $? -eq 0 ];then | ||
sudo rm /etc/apt/sources.list.d/microsoft-prod.list | ||
sudo apt-get update -y | ||
else | ||
yum --help &>/dev/null | ||
[ $? -eq 0 ] && sudo yum update -y | ||
fi | ||
wget https://apt.llvm.org/llvm.sh -O llvm.sh | ||
chmod +x ./llvm.sh | ||
sudo ./llvm.sh 17 | ||
shell: bash | ||
|
||
- name: 'Build and test' | ||
id: get-cov-report | ||
run: | | ||
cp -r src/coro_rpc/tests/openssl_files . | ||
rm -rf build | ||
mkdir -p build | ||
cd build | ||
CC=clang-17 CXX=clang++-17 cmake .. -DCOVERAGE_TEST=ON -DYLT_ENABLE_SSL=ON -DBUILD_EXAMPLES=OFF -DBUILD_BENCHMARK=OFF | ||
make -j | ||
export LLVM_PROFILE_FILE="test_ylt-%m.profraw" | ||
cd output/tests | ||
find . -maxdepth 1 -type f -executable | xargs -I {} sh -c '{}' | ||
llvm-profdata merge -sparse test_ylt-*.profraw -o test_ylt.profdata | ||
if [ -n "${{ inputs.reset-commit-id }}" ];then | ||
report=base-ylt-cov-report | ||
else | ||
report=ylt-cov-report | ||
fi | ||
llvm-cov show $(find . -maxdepth 1 -type f -executable | awk '{print "-object " $0}' | xargs) -instr-profile=test_ylt.profdata -format=html -output-dir=$report -ignore-filename-regex='thirdparty|src|template_switch' -show-instantiations=false | ||
echo "path=build/output/tests/$report" >> $GITHUB_OUTPUT | ||
cov_data=$(grep -w '<pre>Totals</pre>' $report/index.html | awk -F 'Totals' '{print $NF}' | cut -d ')' -f 2 | awk -F '>' '{print $NF}' | awk -F '%' '{print $1}') | ||
echo "coverage data: $cov_data" | ||
echo "report=$report" >> $GITHUB_OUTPUT | ||
echo "data=$cov_data" >> $GITHUB_OUTPUT | ||
shell: bash | ||
|
||
- name: 'Upload coverage results' | ||
uses: actions/[email protected] | ||
with: | ||
name: ${{ steps.get-cov-report.outputs.report }} | ||
path: ${{ steps.get-cov-report.outputs.path }} | ||
|
||
#- name: 'Create code coverage report' | ||
# working-directory: ${{github.workspace}}/build/output/tests | ||
# run: | | ||
# echo "Code Coverage Report" > tmp.log | ||
# echo "for detail, [goto summary](https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{github.run_id}}) download Artifacts `${{ steps.get-cov-report.outputs.report }}`" >> tmp.log | ||
# echo "\`\`\`" >> tmp.log | ||
# llvm-cov report $(find . -maxdepth 1 -type f -executable | awk '{print "-object " $0}' | xargs) -instr-profile=test_ylt.profdata -ignore-filename-regex="thirdparty\|src\|template_switch" -show-region-summary=false >> tmp.log | ||
# echo "\`\`\`" >> tmp.log | ||
# shell: bash | ||
# if: ${{ inputs.reset-commit-id }} == "" | ||
|
||
#- name: 'Create comment' | ||
# uses: peter-evans/create-or-update-comment@v4 | ||
# with: | ||
# issue-number: ${{ github.event.pull_request.number }} | ||
# body-file: '${{github.workspace}}/build/output/tests/tmp.log' | ||
# if: ${{ github.event.pull_request.number }} != "" && ${{ inputs.reset-commit-id }} == "" | ||
|
||
- name: 'Checkout source code' | ||
uses: actions/checkout@v4 | ||
if: ${{ inputs.reset-commit-id }} != "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,93 @@ | ||
# | ||
# Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved. | ||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
# | ||
# This code is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License version 2 only, as | ||
# published by the Free Software Foundation. Alibaba designates this | ||
# particular file as subject to the "Classpath" exception as provided | ||
# by Oracle in the LICENSE file that accompanied this code. | ||
# | ||
# This code is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
# version 2 for more details (a copy is included in the LICENSE file that | ||
# accompanied this code). | ||
# | ||
# You should have received a copy of the GNU General Public License version | ||
# 2 along with this work; if not, write to the Free Software Foundation, | ||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
|
||
name: Ubuntu 22.04 (llvm cov) | ||
|
||
on: | ||
pull_request_target: | ||
pull_request: | ||
branches: | ||
- main | ||
- fix_coverage_show | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
prerequisites: | ||
runs-on: ubuntu-22.04 | ||
|
||
outputs: | ||
id: ${{ steps.get-base-commit.outputs.id }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Dependencies | ||
- name: 'Get Base Commit id' | ||
id: get-base-commit | ||
run: | | ||
sudo apt-get install openssl | ||
sudo apt-get install libssl-dev | ||
sudo apt-get install llvm | ||
sudo apt install -y jq | ||
base_commit_id=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .base.sha) | ||
echo "::set-output name=id::$base_commit_id" | ||
shell: bash | ||
if: ${{ github.event_name == 'pull_request' }} | ||
|
||
- name: Install newer Clang | ||
run: | | ||
sudo rm /etc/apt/sources.list.d/microsoft-prod.list | ||
sudo apt-get update | ||
wget https://apt.llvm.org/llvm.sh | ||
chmod +x ./llvm.sh | ||
sudo ./llvm.sh 17 | ||
- name: Run Coverage | ||
run: | | ||
ls | ||
cp -r src/coro_rpc/tests/openssl_files . | ||
ls | ||
mkdir build && cd build | ||
CC=clang-17 CXX=clang++-17 cmake .. -DCOVERAGE_TEST=ON -DYLT_ENABLE_SSL=ON -DBUILD_EXAMPLES=OFF -DBUILD_BENCHMARK=OFF | ||
make -j | ||
export LLVM_PROFILE_FILE="test_ylt-%m.profraw" | ||
cd output | ||
cd tests | ||
./coro_io_test | ||
./coro_rpc_test | ||
./easylog_test | ||
./struct_pack_test | ||
./struct_pack_test_with_optimize | ||
./metric_test | ||
./struct_pb_test | ||
./reflection_test | ||
./coro_http_test | ||
llvm-profdata merge -sparse test_ylt-*.profraw -o test_ylt.profdata | ||
llvm-cov show -object coro_io_test -object coro_rpc_test -object easylog_test -object struct_pack_test -object struct_pack_test_with_optimize -object metric_test -object struct_pb_test -object reflection_test -object coro_http_test -instr-profile=test_ylt.profdata -format=html -output-dir=../../.coverage_llvm_cov -ignore-filename-regex="thirdparty|src|template_switch" -show-instantiations=false | ||
echo "Done!" | ||
- name: List files in the repository | ||
run: | | ||
echo "workspace" | ||
ls ${{ github.workspace }} | ||
echo "workspace/build" | ||
ls ${{ github.workspace }}/build | ||
base-cov-test: | ||
needs: prerequisites | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
data: ${{ steps.base-cov.outputs.data }} | ||
steps: | ||
- name: 'Checkout source code' | ||
uses: actions/checkout@v4 | ||
- name: 'Base coverage test' | ||
id: base-cov | ||
uses: ./.github/actions/coverage | ||
with: | ||
reset-commit-id: ${{ needs.prerequisites.outputs.id }} | ||
if: ${{ github.event_name == 'pull_request' }} | ||
|
||
- name: Upload Coverage Results | ||
uses: actions/[email protected] | ||
cov-test: | ||
needs: prerequisites | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
data: ${{ steps.cov.outputs.data }} | ||
steps: | ||
- name: 'Checkout source code' | ||
uses: actions/checkout@v4 | ||
- name: 'Coverage test' | ||
id: cov | ||
uses: ./.github/actions/coverage | ||
with: | ||
name: llvm-cov | ||
path: ${{github.workspace}}/build/.coverage_llvm_cov | ||
reset-commit-id: "" | ||
|
||
- name: Create Code Coverage Report | ||
working-directory: ${{github.workspace}}/build/output/tests | ||
compare-cov-data: | ||
needs: | ||
- base-cov-test | ||
- cov-test | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: 'Compare data' | ||
run: | | ||
echo "Code Coverage Report" > tmp.log | ||
echo "for detail, [goto summary](https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{github.run_id}}) download Artifacts `llvm-cov`" >> tmp.log | ||
echo "\`\`\`" >> tmp.log | ||
llvm-cov report -object coro_io_test -object coro_rpc_test -object easylog_test -object struct_pack_test -object struct_pack_test_with_optimize -object metric_test -object struct_pb_test -object reflection_test -object coro_http_test -instr-profile=test_ylt.profdata -ignore-filename-regex="thirdparty|src|template_switch" -show-region-summary=false >> tmp.log | ||
echo "\`\`\`" >> tmp.log | ||
- name: Create Comment | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body-file: '${{github.workspace}}/build/output/tests/tmp.log' | ||
sudo apt install -y bc | ||
result=$(echo "${{ needs.cov-test.outputs.data }} > $(echo "${{ needs.base-cov-test.outputs.data}} * 0.97" | bc)" | bc) | ||
if [ "$result" -ne 1 ];then | ||
echo "coverage has decreased over 3%!" | ||
exit 1 | ||
fi | ||
shell: bash | ||
if: ${{ github.event_name == 'pull_request' }} |