coverage: update previous github actions PR comment #66
Workflow file for this run
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
# 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 Existing 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 |