forked from SEAME-pt/SEAME-Course-24-25
-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (141 loc) · 5.72 KB
/
coverage_compare.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# yamllint disable rule:line-length
---
name: Coverage
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']
jobs:
compare:
runs-on: ubuntu-latest
container:
image: t4seame/app:latest
permissions:
contents: write
pull-requests: write
repository-projects: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for rebase
- name: Configure Git Safe Directory
run: |
git config --global --add safe.directory $(pwd)
- name: Set Git user identity
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions"
- name: Fetch main branch
run: |
git fetch origin main
- name: Rebase PR branch onto main
run: |
git rebase origin/main || (git rebase --abort && exit 1)
- name: Find affected files
run: |
git fetch origin ${{ github.base_ref }} --depth=1
git diff --diff-filter=ACM --name-only origin/${{ github.base_ref }} > affected_files.txt
echo "Affected files:"
cat affected_files.txt
- name: Find affected cpp files
run: |
> affected_cpp_files.txt
while read file; do
if [[ "$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx ]]; then
echo "$file" >> affected_cpp_files.txt
fi
done < affected_files.txt
sort -u affected_cpp_files.txt -o affected_cpp_files.txt
echo "Affected cpp files:"
cat affected_cpp_files.txt
echo "cpp_files=$(cat affected_cpp_files.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash
- name: Find affected Bazel targets
if: ${{ env.bazel_files == '' }}
run: |
> affected_targets.txt
while read file; do
if [[ "$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx ]]; then
echo "Finding targets for: $file"
targets=$(bazelisk query --output=package "$file")/...
echo "$targets" >> affected_targets.txt
fi
done < affected_files.txt
sort -u affected_targets.txt -o affected_targets.txt
echo "Affected targets:"
cat affected_targets.txt
echo "targets=$(cat affected_targets.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash
- name: Create coverage directory
if: env.cpp_files != ''
run: |
mkdir -p "./lcov_report/gcno_gcda"
- name: Generate coverage report
if: env.cpp_files != ''
run: |
TARGETS=$(bazel query 'kind("(cc_binary|cc_library)", deps(//:release_bins_filegroup)) except kind(".*test", deps(//:release_bins_filegroup)) intersect filter("^//", deps(//:release_bins_filegroup))')
TARGETS_STR=$(echo "$TARGETS" | tr '\n' ' ')
echo "Targets used for coverage baseline: $TARGETS_STR"
BAZEL_BIN=$(bazel info bazel-bin)
TEST_LOGS=$(bazel info bazel-testlogs)
echo "Bazel bin directory: $BAZEL_BIN"
echo "Test logs directory: $TEST_LOGS"
bazelisk run //tools/coverage:lcov \
--platforms=//bazel/platforms:x86_64_linux -- \
-b "$TARGETS_STR" \
-t //:unit_tests \
-c "$BAZEL_BIN" \
-d "$TEST_LOGS" \
-o "./lcov_report"
shell: bash
- name: Download main branch coverage report
if: env.cpp_files != ''
run: |
curl -L -o ./lcov_report/main_coverage.info https://seame-pt.github.io/Team04/coverage.info
- name: Compare coverage reports
if: env.cpp_files != ''
run: |
bazelisk run //tools/coverage/utils:lcov_compare -- \
-c1 "$(pwd)/lcov_report/main_coverage.info" \
-c2 "$(pwd)/lcov_report/coverage.info" \
-t $cpp_files \
-o "$(pwd)/lcov_report/compare_report.txt"
shell: bash
- name: Read compare report
if: env.cpp_files != ''
run: |
FILE_PATH="$(pwd)/lcov_report/compare_report.txt"
if [ -f "$FILE_PATH" ]; then
echo "File exists"
content=$(cat "$FILE_PATH")
echo "CONTENT<<EOF" >> $GITHUB_ENV
echo "$content" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
else
echo "Compare report does not exist"
fi
- name: Find Bot coverage comment
id: find_comment
if: env.CONTENT != ''
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Coverage for impacted relevant source files
- name: Post new comment
if: env.CONTENT != '' && steps.find_comment.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Coverage for impacted relevant source files:
${{ env.CONTENT }}
- name: Update comment
if: env.CONTENT != '' && steps.find_comment.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find_comment.outputs.comment-id }}
body: |
Coverage for impacted relevant source files:
${{ env.CONTENT }}
edit-mode: replace