Skip to content

Commit

Permalink
Merge branch 'develop' into retain-input
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwajith-Shettigar authored Aug 24, 2024
2 parents ba8d992 + a85cc50 commit 4755ca3
Show file tree
Hide file tree
Showing 14 changed files with 2,272 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- develop

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

jobs:
Expand Down
33 changes: 7 additions & 26 deletions .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- develop

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -255,10 +255,13 @@ jobs:
name: coverage-report-${{ env.SHARD_NAME }} # Saving with unique names to avoid conflict
path: coverage_reports

evaluate-code-coverage-reports:
evaluate_code_coverage_reports:
name: Evaluate Code Coverage Reports
runs-on: ubuntu-20.04
needs: code_coverage_run
# The expression if: ${{ !cancelled() }} runs a job or step regardless of its success or failure while responding to cancellations,
# serving as a cancellation-compliant alternative to if: ${{ always() }} in concurrent workflows.
if: ${{ !cancelled() }}
env:
CACHE_DIRECTORY: ~/.bazel_cache
steps:
Expand Down Expand Up @@ -305,32 +308,10 @@ jobs:
name: final-coverage-report
path: coverage_reports/CoverageReport.md

publish_coverage_report:
name: Publish Code Coverage Report
needs: evaluate-code-coverage-reports
permissions:
pull-requests: write

# The expression if: ${{ !cancelled() }} runs a job or step regardless of its success or failure while responding to cancellations,
# serving as a cancellation-compliant alternative to if: ${{ always() }} in concurrent workflows.
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- name: Download Generated Markdown Report
uses: actions/download-artifact@v4
with:
name: final-coverage-report

- name: Upload Coverage Report as PR Comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body-path: 'CoverageReport.md'

# Reference: https://github.community/t/127354/7.
check_coverage_results:
name: Check Code Coverage Results
needs: [ compute_changed_files, code_coverage_run, evaluate-code-coverage-reports ]
needs: [ compute_changed_files, code_coverage_run, evaluate_code_coverage_reports ]
# The expression if: ${{ !cancelled() }} runs a job or step regardless of its success or failure while responding to cancellations,
# serving as a cancellation-compliant alternative to if: ${{ always() }} in concurrent workflows.
if: ${{ !cancelled() }}
Expand All @@ -341,5 +322,5 @@ jobs:
run: exit 1

- name: Check that coverage status is passed
if: ${{ needs.evaluate-code-coverage-reports.result != 'success' }}
if: ${{ needs.compute_changed_files.outputs.can_skip_files != 'true' && needs.evaluate_code_coverage_reports.result != 'success' }}
run: exit 1
81 changes: 81 additions & 0 deletions .github/workflows/comment_coverage_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Contains jobs corresponding to publishing coverage reports generated by code_coverage.yml.

name: Comment Coverage Report

# Controls when the action will run. Triggers the workflow on pull request events
# (assigned, opened, synchronize, reopened)

on:
pull_request_target:
types: [assigned, opened, synchronize, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

jobs:
check_code_coverage_completed:
name: Check code coverage completed
runs-on: ubuntu-latest
steps:
- name: Wait for code coverage to complete
id: wait-for-coverage
uses: ArcticLampyrid/action-wait-for-workflow@v1.2.0
with:
workflow: code_coverage.yml
sha: auto
allowed-conclusions: |
success
failure
comment_coverage_report:
name: Comment Code Coverage Report
needs: check_code_coverage_completed
permissions:
pull-requests: write

# The expression if: ${{ !cancelled() }} runs a job or step regardless of its success or failure while responding to cancellations,
# serving as a cancellation-compliant alternative to if: ${{ always() }} in concurrent workflows.
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- name: Find CI workflow run for PR
id: find-workflow-run
uses: actions/github-script@v7
continue-on-error: true
with:
script: |
// Find the last successful workflow run for the current PR's head
const { owner, repo } = context.repo;
const runsResponse = await github.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id: 'code_coverage.yml',
event: 'pull_request',
head_sha: '${{ github.event.pull_request.head.sha }}',
});
const runs = runsResponse.data.workflow_runs;
runs.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
const run = runs[0];
if(!run) {
core.setFailed('Could not find a succesful workflow run for the PR');
return;
}
core.setOutput('run-id', run.id);
- name: Download Generated Markdown Report
uses: actions/download-artifact@v4
if: ${{ !cancelled() }} # IMPORTANT: Upload reports regardless of success or failure status
with:
name: final-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.find-workflow-run.outputs.run-id }}

- name: Upload Coverage Report as PR Comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body-path: 'CoverageReport.md'
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- develop

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

# This workflow has the following jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- develop

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- develop

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

jobs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModu
import org.oppia.android.domain.question.QuestionModule
import org.oppia.android.domain.workmanager.WorkManagerConfigurationModule
import org.oppia.android.testing.OppiaTestRule
import org.oppia.android.testing.RunOn
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.TestPlatform
import org.oppia.android.testing.espresso.EditTextInputAction
import org.oppia.android.testing.espresso.TextInputAction.Companion.hasErrorText
import org.oppia.android.testing.espresso.TextInputAction.Companion.hasNoErrorText
Expand Down Expand Up @@ -219,6 +217,7 @@ class PinPasswordActivityTest {

@Test
fun testPinPassword_withAdmin_inputCorrectPin_opensHomeActivity() {
TestPlatformParameterModule.forceEnableMultipleClassrooms(false)
ActivityScenario.launch<PinPasswordActivity>(
PinPasswordActivity.createPinPasswordActivityIntent(
context = context,
Expand All @@ -235,7 +234,6 @@ class PinPasswordActivityTest {
}

@Test
@RunOn(TestPlatform.ESPRESSO)
fun testPinPassword_enableClassrooms_withAdmin_inputCorrectPin_opensClassroomListActivity() {
TestPlatformParameterModule.forceEnableMultipleClassrooms(true)
ActivityScenario.launch<PinPasswordActivity>(
Expand All @@ -256,6 +254,7 @@ class PinPasswordActivityTest {

@Test
fun testPinPassword_withUser_inputCorrectPin_opensHomeActivity() {
TestPlatformParameterModule.forceEnableMultipleClassrooms(false)
ActivityScenario.launch<PinPasswordActivity>(
PinPasswordActivity.createPinPasswordActivityIntent(
context = context,
Expand All @@ -272,7 +271,6 @@ class PinPasswordActivityTest {
}

@Test
@RunOn(TestPlatform.ESPRESSO)
fun testPinPassword_enableClassrooms_withUser_inputCorrectPin_opensClassroomListActivity() {
TestPlatformParameterModule.forceEnableMultipleClassrooms(true)
ActivityScenario.launch<PinPasswordActivity>(
Expand Down Expand Up @@ -544,6 +542,7 @@ class PinPasswordActivityTest {

@Test
fun testPinPassword_withUser_forgot_inputAdminPinAndNewPin_opensHomeActivity() {
TestPlatformParameterModule.forceEnableMultipleClassrooms(false)
ActivityScenario.launch<PinPasswordActivity>(
PinPasswordActivity.createPinPasswordActivityIntent(
context = context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,16 +496,37 @@ class CoverageReporter(
}
}

val finalReportText = "## Coverage Report\n\n" +
"### Results\n" +
"Number of files assessed: ${coverageReportContainer.coverageReportList.size}\n" +
"Overall Coverage: **${"%.2f".format(calculateOverallCoveragePercentage())}%**\n" +
"Coverage Analysis: $status\n" +
"##" +
failureMarkdownTable +
failureMarkdownEntries +
successMarkdownEntries +
testFileExemptedSection
val wikiPageLinkNote = buildString {
val wikiPageReferenceNote = ">To learn more, visit the [Oppia Android Code Coverage]" +
"(https://github.com/oppia/oppia-android/wiki/Oppia-Android-Code-Coverage) wiki page"
append("\n\n")
append("#")
append("\n")
append(wikiPageReferenceNote)
}

val skipCoverageReportText = buildString {
append("## Coverage Report\n")
append("### Results\n")
append("Coverage Analysis: **SKIP** :next_track_button:\n\n")
append("_This PR did not introduce any changes to Kotlin source or test files._")
append(wikiPageLinkNote)
}

val finalReportText = coverageReportContainer.coverageReportList.takeIf { it.isNotEmpty() }
?.let {
"## Coverage Report\n\n" +
"### Results\n" +
"Number of files assessed: ${coverageReportContainer.coverageReportList.size}\n" +
"Overall Coverage: **${"%.2f".format(calculateOverallCoveragePercentage())}%**\n" +
"Coverage Analysis: $status\n" +
"##" +
failureMarkdownTable +
failureMarkdownEntries +
successMarkdownEntries +
testFileExemptedSection +
wikiPageLinkNote
} ?: skipCoverageReportText

val finalReportOutputPath = mdReportOutputPath
?.let { it }
Expand Down
Loading

0 comments on commit 4755ca3

Please sign in to comment.