Skip to content
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

Add a library to check code coverage #631

Merged
merged 7 commits into from
Mar 24, 2025

Conversation

gaiksaya
Copy link
Member

@gaiksaya gaiksaya commented Mar 21, 2025

Description

Add a library to check code coverage for all the components in the release. Currently this will only report components missing the code coverage. Regarding meeting the threshold or not, we will be adding in next iteration once we know everyone is on-board.
This change also add a new utility to parse the template using GStringTemplateEngine that would help replacing the values and also add conditions based on values within the template much easier in the future.

Issues Resolved

closes opensearch-project/opensearch-build#5332

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@gaiksaya gaiksaya changed the title Add code cov Add a library to check code coverage Mar 21, 2025

Verified

This commit was signed with the committer’s verified signature.
gaiksaya Sayali Gaikawad
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
Fix param

Verified

This commit was signed with the committer’s verified signature.
gaiksaya Sayali Gaikawad
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>

Verified

This commit was signed with the committer’s verified signature.
gaiksaya Sayali Gaikawad
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
Copy link

codecov bot commented Mar 21, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 5 lines in your changes missing coverage. Please review.

Project coverage is 89.04%. Comparing base (7ebe7d2) to head (8af4484).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/jenkins/ComponentRepoData.groovy 84.21% 1 Missing and 2 partials ⚠️
src/utils/TemplateProcessor.groovy 86.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #631      +/-   ##
============================================
- Coverage     89.15%   89.04%   -0.12%     
- Complexity      111      118       +7     
============================================
  Files           116      118       +2     
  Lines           544      575      +31     
  Branches         30       32       +2     
============================================
+ Hits            485      512      +27     
- Misses           29       31       +2     
- Partials         30       32       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Verified

This commit was signed with the committer’s verified signature.
gaiksaya Sayali Gaikawad
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
refactor

Verified

This commit was signed with the committer’s verified signature.
gaiksaya Sayali Gaikawad
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
revert

Verified

This commit was signed with the committer’s verified signature.
gaiksaya Sayali Gaikawad
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
@@ -0,0 +1,6 @@
Hi, </br>

This component is not reporting code-coverage for branch [$BRANCH]($CODECOV_URL). </br>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to insert the component name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are directly commenting on the component's issue. But sure just to be clear let me add it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the change here: 8af4484
Thanks!


def process(String pathToTemplate, def bindings, String outputDir) {
try {
def randomName = getRandomName()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why random name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same environment can lead to overwriting the file so just getting random name. The file is used as a parameter passed in gh comment command as --body-file <file_name>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this will always run in jenkins context, can we just use component-build_id for naming?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much hassle to pass the component name here again or parse the bindings again. Just needed a unique id so used random method.

def process(String pathToTemplate, def bindings, String outputDir) {
try {
def randomName = getRandomName()
def content = this.script.libraryResource pathToTemplate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Load the script from the resource. Groovy code under src does not have direct access to jenkins env. So all the inbuild functions like echo, sh, etc needs jenkins object. We are passing the instance in the constructor. See https://github.com/opensearch-project/opensearch-build-libraries/pull/631/files#diff-7a4ffa30ad30b3c57f651a0f7b007cab18cf1bd50594694fb181505e3eb62ab8R98

Verified

This commit was signed with the committer’s verified signature.
gaiksaya Sayali Gaikawad
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
@gaiksaya gaiksaya merged commit 3766071 into opensearch-project:main Mar 24, 2025
8 of 9 checks passed
@gaiksaya gaiksaya deleted the add-code-cov branch March 24, 2025 22:06
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 24, 2025
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
(cherry picked from commit 3766071)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
gaiksaya pushed a commit that referenced this pull request Mar 25, 2025

Verified

This commit was signed with the committer’s verified signature.
gaiksaya Sayali Gaikawad
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
(cherry picked from commit 3766071)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Check, take action or notify and auto-update Entrance criteria for releases
2 participants