-
Notifications
You must be signed in to change notification settings - Fork 84
ci(l1,l2): lines of code report #3764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves the accuracy of the lines of code (LOC) comparison in the CI workflow by changing the comparison baseline from the PR base branch to the merge base commit between the PR and base branches. This prevents inaccurate results when the PR branch is not up-to-date with the main branch.
- Updates the checkout process to first checkout the PR code, then find and checkout the merge base commit
- Adds a new step to calculate the merge base between head and base branches using
git merge-base
- Replaces direct base branch comparison with merge base comparison for more accurate LOC reporting
run: | | ||
git fetch --depth=100000 origin $HEAD_REF | ||
git fetch --depth=100000 origin $BASE_REF | ||
MERGE_BASE=$(git merge-base origin/$HEAD_REF origin/$BASE_REF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The git merge-base
command could fail if the branches don't share common history or if the fetch operations didn't retrieve sufficient commits. Add error handling to check if the merge base was found successfully.
MERGE_BASE=$(git merge-base origin/$HEAD_REF origin/$BASE_REF) | |
MERGE_BASE=$(git merge-base origin/$HEAD_REF origin/$BASE_REF || echo "") | |
if [ -z "$MERGE_BASE" ]; then | |
echo "Error: Unable to find a merge base between $HEAD_REF and $BASE_REF." >&2 | |
exit 1 | |
fi |
Copilot uses AI. Check for mistakes.
This reverts commit 2c31708.
Lines of code reportTotal lines added: Detailed view
|
Motivation
The lines of code CI compares directly with main, so if the branch is not updated it gives fake results
Description
Now the CI compares to the most common commit between the branches
How to Test
This PR is not up to date with main, without the changes on the CI we would see a code report with the new changes on main.
Since this PR only changes the CI there should be no code changes on the report, but in order to show that it works, a commit was added where one line changed, a report was generated, and then the commit was reverted.
The old report is still present since the new run of the CI detected that there are no changes, so the comment is not updated.