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

Fix part of #5343: Introduce new CI workflow for Code Coverage #5465

Merged
merged 344 commits into from
Aug 10, 2024

Conversation

Rd4dev
Copy link
Collaborator

@Rd4dev Rd4dev commented Jul 19, 2024

Explanation

Fixes part of #5343

Project

[PR 2.3 of Project 4.1]

Changes Made

  • Replicated the compute affected test utility to compute changed files to acquire the list of kotlin files changed based on changes in the local Oppia Android Git repository, which will be organized into shards. It categorizes files by their paths into buckets (app, data, domain, etc.) and applies sharding strategies (large, medium, small).
  • Modified BazelClient to run coverage commands based on shard configurations.
  • Introducing a new CI workflow replicating the unit_test.yml implementation.
  • The Coverage workflow should run only after the unit test (bazel) workflow is successfully completed.
  • With [RunAllTests] added to the title this should perform code coverage on every file
  • This PR is intended only to run coverages and the storing of protos and uploading of comments are yet to be figured out with the upcoming PR.

Todo:

  • [Done] Add test cases with RunAllTests setting.
  • When a test file is provided the corresponding source file need to be mapped and provided for Build Oppia File (to pre build it before code coverage).
  • Need to look after the runs and verify them.
    • To run only if unit tests pass:
    • Below image represents the ci check where the unit test fails causing the coverage runs to skip but still throw a fail status.
      image

Essential Checklist

  • The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • Any changes to scripts/assets files have their rationale included in the PR explanation.
  • The PR follows the style guide.
  • The PR does not contain any unnecessary code changes from Android Studio (reference).
  • The PR is made from a branch that's not called "develop" and is up-to-date with "develop".
  • The PR is assigned to the appropriate reviewers (reference).

Rd4dev added 30 commits July 10, 2024 14:46
… causing any mismatched misconfiguration in ci (test pass locally)
…emoving it to see if that is actually causing the issues (may be with idle times)
… most importantly helps with max idle run time issues
…test cases for sets of success, failure and anomaly cases
… to note with 12 the run completed in just 200 seconds
@Rd4dev
Copy link
Collaborator Author

Rd4dev commented Aug 10, 2024

@BenHenning, thanks for the review, addressed the remaining comments, with just 2 requests for clarification,

  1. To understand the comment mentioning

to cover these since a regression here could be quite problematic (we'd drop re-checking code coverage for those files, leading to a potential eventual failure in the develop branch once the PR is merged).

  1. If ENABLE_CACHING: false too needs to be removed?

Can you PTAL?

@oppiabot oppiabot bot assigned BenHenning and unassigned Rd4dev Aug 10, 2024
Copy link

oppiabot bot commented Aug 10, 2024

Unassigning @Rd4dev since a re-review was requested. @Rd4dev, please make sure you have addressed all review comments. Thanks!

… status check as there is no call to the coverage reporter yet and that will only be introduced with the upcoming pr to upload the artifacts, and use them to derive a coverage status
Copy link
Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

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

Thanks @Rd4dev! Basically LGTM, but just a couple of follow-ups. PTAL.

Also, I added some clarity to your question on why the new tests you added in the most recent changes are really important (though it's in a resolved conversation thread).

Please also update the branch changes now that #5461 has been merged.

@BenHenning BenHenning assigned Rd4dev and unassigned BenHenning Aug 10, 2024
Base automatically changed from code_coverage_list_of_files to develop August 10, 2024 17:34
@Rd4dev
Copy link
Collaborator Author

Rd4dev commented Aug 10, 2024

@BenHenning, addressed the review comments, but not sure if I was clear enough on explaining on why proto is not used (for now), can you PTAL and see if that was well communicated?

@oppiabot oppiabot bot assigned BenHenning and unassigned Rd4dev Aug 10, 2024
Copy link

oppiabot bot commented Aug 10, 2024

Unassigning @Rd4dev since a re-review was requested. @Rd4dev, please make sure you have addressed all review comments. Thanks!

Copy link
Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

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

Thanks @Rd4dev. This LGTM!

.github/workflows/code_coverage.yml Show resolved Hide resolved
@BenHenning
Copy link
Member

Going ahead and merging this since everything's resolved.

@BenHenning BenHenning merged commit 3d85ce0 into develop Aug 10, 2024
28 checks passed
@BenHenning BenHenning deleted the code_coverage_ci_workflow branch August 10, 2024 21:09
BenHenning pushed a commit that referenced this pull request Aug 13, 2024
…t as comments (#5469)

## Explanation
Fixes part of #5343 

### Project
[PR 2.4 of Project 4.1]

### Changes Made

With the protos collected and stored with their respective file paths
through #5465, this PR will focus on collecting the stored proto files
and passing it to the script to generate a coverage report along with a
status check to decide the success failure case of the CI Coverage Check
run.

**Collection of protos**
- The stored protos are now being uploaded as an artifact.
- The name of the artifact is set to a dynamic value corresponding to
its shard_name.
- The shard_name is extracted from the first portion of the
`CHANGED_FILES_BUCKET_BASE64_ENCODED_SHARD` value.
- eg: The matrix job -
[app-shard0;H4sIAAAAAAAAAONiTiwoEHIFEvrFRcn6uYmZefpZi....] will save the
artifact with name **coverage-report-app-shard0**
- The dynamic or unique name is important to prevent the following
error:
```
Error: Failed to CreateArtifact: Received non-retryable error: Failed request: (409) Conflict: 
an artifact with this name already exists on the workflow run
```
- The artifacts that match the pattern of coverage-report-* are
downloaded.

```
Found 4 artifact(s)
Filtering artifacts by pattern 'coverage-report-*'
Preparing to download the following artifacts:
- coverage-report-domain-shard0 (ID: 1799350592, Size: 489)
- coverage-report-scripts-shard2 (ID: 1799348996, Size: 2075)
- coverage-report-app-shard3 (ID: 1799348891, Size: 770)
- coverage-report-generic-shard1 (ID: 1799348719, Size: 551)
```
- All the stored coverage_report.pb files are found and their paths are
stored as list.
- The list of coverage_report.pb files are then passed to the
CoverageReporter.kt script to handle the coverage report protos.
- The script combines them as one single CoverageReportContainer to
generate a Markdown report with it.
- Finally, a .md report is stored and based on the status of the
coverage check, the job either succeeds or fails.
- The stored md report is again uploaded and downloaded as an artifact
to pass it for publication of the report.
- The CoverageReport.md file is then uploaded as a comment to the
corresponding PR using -
https://github.com/peter-evans/create-or-update-comment action

>The comment will be published regardless of whether the coverage passes
or fails. The only time comments will not be published is if the unit
tests themselves fail, making the coverage checks non-functional (also
less cluttered).

#

### CI Run Data

This check was run with 4 different shards on all possible cases capable
of being produced.
Check :
https://github.com/oppia/oppia-android/actions/runs/10340867060?pr=5469
Comment Published with the above run:
#5469 (comment)

The above cases are run with custom temporary changes to the test
exemption file (testing purposes).
```
test_file_exemption {
  exempted_file_path: "scripts/src/java/org/oppia/android/scripts/testfile/TestFileCheck.kt"
  override_min_coverage_percent_required: 101
}
test_file_exemption {
  exempted_file_path: "utility/src/main/java/org/oppia/android/util/logging/ConsoleLogger.kt"
  override_min_coverage_percent_required: 30
}
```

## Essential Checklist
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants