|
| 1 | +# |
| 2 | +# Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved. |
| 3 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | +# |
| 5 | +# This code is free software; you can redistribute it and/or modify it |
| 6 | +# under the terms of the GNU General Public License version 2 only, as |
| 7 | +# published by the Free Software Foundation. Alibaba designates this |
| 8 | +# particular file as subject to the "Classpath" exception as provided |
| 9 | +# by Oracle in the LICENSE file that accompanied this code. |
| 10 | +# |
| 11 | +# This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | +# version 2 for more details (a copy is included in the LICENSE file that |
| 15 | +# accompanied this code). |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License version |
| 18 | +# 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | +# |
| 21 | + |
1 | 22 | name: Ubuntu 22.04 (llvm cov)
|
2 | 23 |
|
3 | 24 | on:
|
4 |
| - pull_request_target: |
| 25 | + pull_request: |
5 | 26 | branches:
|
6 | 27 | - main
|
7 | 28 | - fix_coverage_show
|
8 | 29 |
|
| 30 | +concurrency: |
| 31 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 32 | + cancel-in-progress: true |
| 33 | + |
9 | 34 | jobs:
|
10 |
| - build: |
| 35 | + prerequisites: |
11 | 36 | runs-on: ubuntu-22.04
|
12 |
| - |
| 37 | + outputs: |
| 38 | + id: ${{ steps.get-base-commit.outputs.id }} |
13 | 39 | steps:
|
14 |
| - - name: Checkout |
15 |
| - uses: actions/checkout@v4 |
16 |
| - |
17 |
| - - name: Install Dependencies |
| 40 | + - name: 'Get Base Commit id' |
| 41 | + id: get-base-commit |
18 | 42 | run: |
|
19 |
| - sudo apt-get install openssl |
20 |
| - sudo apt-get install libssl-dev |
21 |
| - sudo apt-get install llvm |
| 43 | + sudo apt install -y jq |
| 44 | + 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) |
| 45 | + echo "::set-output name=id::$base_commit_id" |
| 46 | + shell: bash |
| 47 | + if: ${{ github.event_name == 'pull_request' }} |
22 | 48 |
|
23 |
| - - name: Install newer Clang |
24 |
| - run: | |
25 |
| - sudo rm /etc/apt/sources.list.d/microsoft-prod.list |
26 |
| - sudo apt-get update |
27 |
| - wget https://apt.llvm.org/llvm.sh |
28 |
| - chmod +x ./llvm.sh |
29 |
| - sudo ./llvm.sh 17 |
30 |
| -
|
31 |
| - - name: Run Coverage |
32 |
| - run: | |
33 |
| - ls |
34 |
| - cp -r src/coro_rpc/tests/openssl_files . |
35 |
| - ls |
36 |
| - mkdir build && cd build |
37 |
| - CC=clang-17 CXX=clang++-17 cmake .. -DCOVERAGE_TEST=ON -DYLT_ENABLE_SSL=ON -DBUILD_EXAMPLES=OFF -DBUILD_BENCHMARK=OFF |
38 |
| - make -j |
39 |
| - export LLVM_PROFILE_FILE="test_ylt-%m.profraw" |
40 |
| - cd output |
41 |
| - cd tests |
42 |
| - ./coro_io_test |
43 |
| - ./coro_rpc_test |
44 |
| - ./easylog_test |
45 |
| - ./struct_pack_test |
46 |
| - ./struct_pack_test_with_optimize |
47 |
| - ./metric_test |
48 |
| - ./struct_pb_test |
49 |
| - ./reflection_test |
50 |
| - ./coro_http_test |
51 |
| - llvm-profdata merge -sparse test_ylt-*.profraw -o test_ylt.profdata |
52 |
| - 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 |
53 |
| - echo "Done!" |
54 |
| -
|
55 |
| -
|
56 |
| - - name: List files in the repository |
57 |
| - run: | |
58 |
| - echo "workspace" |
59 |
| - ls ${{ github.workspace }} |
60 |
| - echo "workspace/build" |
61 |
| - ls ${{ github.workspace }}/build |
| 49 | + base-cov-test: |
| 50 | + needs: prerequisites |
| 51 | + runs-on: ubuntu-22.04 |
| 52 | + permissions: |
| 53 | + contents: read |
| 54 | + issues: write |
| 55 | + pull-requests: write |
| 56 | + outputs: |
| 57 | + data: ${{ steps.base-cov.outputs.data }} |
| 58 | + steps: |
| 59 | + - name: 'Checkout source code' |
| 60 | + uses: actions/checkout@v4 |
| 61 | + - name: 'Base coverage test' |
| 62 | + id: base-cov |
| 63 | + uses: ./.github/actions/coverage |
| 64 | + with: |
| 65 | + reset-commit-id: ${{ needs.prerequisites.outputs.id }} |
| 66 | + if: ${{ github.event_name == 'pull_request' }} |
62 | 67 |
|
63 |
| - - name: Upload Coverage Results |
64 |
| - |
| 68 | + cov-test: |
| 69 | + needs: prerequisites |
| 70 | + runs-on: ubuntu-22.04 |
| 71 | + permissions: |
| 72 | + contents: read |
| 73 | + issues: write |
| 74 | + pull-requests: write |
| 75 | + outputs: |
| 76 | + data: ${{ steps.cov.outputs.data }} |
| 77 | + steps: |
| 78 | + - name: 'Checkout source code' |
| 79 | + uses: actions/checkout@v4 |
| 80 | + - name: 'Coverage test' |
| 81 | + id: cov |
| 82 | + uses: ./.github/actions/coverage |
65 | 83 | with:
|
66 |
| - name: llvm-cov |
67 |
| - path: ${{github.workspace}}/build/.coverage_llvm_cov |
| 84 | + reset-commit-id: "" |
68 | 85 |
|
69 |
| - - name: Create Code Coverage Report |
70 |
| - working-directory: ${{github.workspace}}/build/output/tests |
| 86 | + compare-cov-data: |
| 87 | + needs: |
| 88 | + - base-cov-test |
| 89 | + - cov-test |
| 90 | + runs-on: ubuntu-22.04 |
| 91 | + steps: |
| 92 | + - name: 'Compare data' |
71 | 93 | run: |
|
72 |
| - echo "Code Coverage Report" > tmp.log |
73 |
| - 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 |
74 |
| - echo "\`\`\`" >> tmp.log |
75 |
| - 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 |
76 |
| - echo "\`\`\`" >> tmp.log |
77 |
| -
|
78 |
| - - name: Create Comment |
79 |
| - uses: peter-evans/create-or-update-comment@v4 |
80 |
| - with: |
81 |
| - issue-number: ${{ github.event.pull_request.number }} |
82 |
| - body-file: '${{github.workspace}}/build/output/tests/tmp.log' |
| 94 | + sudo apt install -y bc |
| 95 | + result=$(echo "${{ needs.cov-test.outputs.data }} > 70" | bc) |
| 96 | + if [ "$result" -ne 1 ];then |
| 97 | + echo "coverage cannot be lower than 70%!" |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | + result=$(echo "${{ needs.cov-test.outputs.data }} > $(echo "${{ needs.base-cov-test.outputs.data}} * 0.97" | bc)" | bc) |
| 101 | + if [ "$result" -ne 1 ];then |
| 102 | + echo "coverage has decreased over 3%!" |
| 103 | + exit 1 |
| 104 | + fi |
| 105 | + shell: bash |
| 106 | + if: ${{ github.event_name == 'pull_request' }} |
0 commit comments