Skip to content

Commit

Permalink
Merge branch 'develop' into onboarding-language-domain-config
Browse files Browse the repository at this point in the history
  • Loading branch information
BenHenning authored Oct 18, 2024
2 parents 9d60f13 + eb16e59 commit a6bf1a6
Show file tree
Hide file tree
Showing 19 changed files with 404 additions and 44 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/wiki.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
name: Deploy to Wiki
on:
pull_request:
paths:
- 'wiki/**'
push:
branches:
- develop
paths:
- 'wiki/**'
# Triggers this workflow when the wiki is changed
# Triggers this workflow when the wiki is changed.
# (see https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#gollum).
gollum:

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

jobs:
table_of_contents_check:
# To verify that the wiki's table of contents matches the headers accurately.
name: Check Wiki Table of Contents
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Set up Bazel
uses: abhinavsingh/setup-bazel@v3
with:
version: 6.5.0

- name: Check Wiki Table of Contents
id: checkWikiToc
run: |
bazel run //scripts:wiki_table_of_contents_check -- ${GITHUB_WORKSPACE}
wiki-deploy:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }}
steps:
- uses: actions/checkout@v3
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.settings.profile
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.model.ProfileEditActivityParams
Expand Down Expand Up @@ -43,17 +44,25 @@ class ProfileEditActivity : InjectableAutoLocalizedAppCompatActivity() {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
profileEditActivityPresenter.handleOnCreate()

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
this@ProfileEditActivity.handleBackPress()
}
}
)
}

override fun onBackPressed() {
private fun handleBackPress() {
val args = intent.getProtoExtra(
PROFILE_EDIT_ACTIVITY_PARAMS_KEY,
ProfileEditActivityParams.getDefaultInstance()
)
val isMultipane = args?.isMultipane ?: false
if (isMultipane) {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
super.onBackPressed()
finish()
} else {
val intent = Intent(this, ProfileListActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class ProfileEditActivityPresenter @Inject constructor(

toolbar.setNavigationOnClickListener {
if (isMultipane) {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
activity.onBackPressedDispatcher.onBackPressed()
} else {
val intent = Intent(activity, ProfileListActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.topic.questionplayer
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.hintsandsolution.HintsAndSolutionListener
Expand Down Expand Up @@ -56,11 +57,16 @@ class QuestionPlayerActivity :
val profileId =
intent.extractCurrentUserProfileId()
questionPlayerActivityPresenter.handleOnCreate(profileId)
}

override fun onBackPressed() {
showStopExplorationDialogFragment()
questionPlayerActivityPresenter.setReadingTextSizeNormal()
onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
showStopExplorationDialogFragment()
questionPlayerActivityPresenter.setReadingTextSizeNormal()
}
}
)
}

override fun restartSession() = questionPlayerActivityPresenter.restartSession()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class QuestionPlayerActivityPresenter @Inject constructor(
activity.setSupportActionBar(binding.questionPlayerToolbar)

binding.questionPlayerToolbar.setNavigationOnClickListener {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
activity.onBackPressedDispatcher.onBackPressed()
}

retrieveReadingTextSize().observe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.topic.revisioncard
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.model.ProfileId
Expand Down Expand Up @@ -56,6 +57,15 @@ class RevisionCardActivity :
subtopicListSize
)
}
onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
revisionCardActivityPresenter.setReadingTextSizeMedium()
onReturnToTopicRequested()
}
}
)
}

override fun handleOnOptionsItemSelected(itemId: Int) {
Expand Down Expand Up @@ -115,13 +125,6 @@ class RevisionCardActivity :
revisionCardActivityPresenter.dismissConceptCard()
}

// TODO(#5404): Migrate to a back pressed dispatcher.
@Deprecated("Deprecated in Java")
override fun onBackPressed() {
revisionCardActivityPresenter.setReadingTextSizeMedium()
onReturnToTopicRequested()
}

override fun onDefaultFontSizeLoaded(readingTextSize: ReadingTextSize) {
revisionCardActivityPresenter.loadRevisionCardFragment(readingTextSize)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ class RevisionCardActivityPresenter @Inject constructor(
binding.revisionCardToolbar.setNavigationOnClickListener {
(activity as ReturnToTopicClickListener).onReturnToTopicRequested()
fontScaleConfigurationUtil.adjustFontScale(activity, ReadingTextSize.MEDIUM_TEXT_SIZE)
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
activity.onBackPressedDispatcher.onBackPressed()
}
if (!accessibilityService.isScreenReaderEnabled()) {
binding.revisionCardToolbarTitle.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.walkthrough
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.model.ProfileId
Expand All @@ -22,6 +23,15 @@ class WalkthroughActivity :
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
walkthroughActivityPresenter.handleOnCreate()

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
walkthroughActivityPresenter.handleSystemBack()
}
}
)
}

override fun currentPage(walkthroughPage: Int) {
Expand All @@ -33,10 +43,6 @@ class WalkthroughActivity :
walkthroughActivityPresenter.changePage(walkthroughPage)
}

override fun onBackPressed() {
walkthroughActivityPresenter.handleSystemBack()
}

companion object {

fun createWalkthroughActivityIntent(context: Context, internalProfileId: Int): Intent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class WalkthroughFinalFragmentPresenter @Inject constructor(
}

override fun goBack() {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
activity.onBackPressedDispatcher.onBackPressed()
}
}
9 changes: 9 additions & 0 deletions scripts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ kt_jvm_binary(
],
)

kt_jvm_binary(
name = "wiki_table_of_contents_check",
testonly = True,
main_class = "org.oppia.android.scripts.wiki.WikiTableOfContentsCheckKt",
runtime_deps = [
"//scripts/src/java/org/oppia/android/scripts/wiki:wiki_table_of_contents_check_lib",
],
)

kt_jvm_binary(
name = "run_coverage",
testonly = True,
Expand Down
18 changes: 18 additions & 0 deletions scripts/src/java/org/oppia/android/scripts/wiki/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Libraries corresponding to scripting tools that help with continuous integration workflows.
"""

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")

kt_jvm_library(
name = "wiki_table_of_contents_check_lib",
testonly = True,
srcs = [
"WikiTableOfContentsCheck.kt",
],
visibility = ["//scripts:oppia_script_binary_visibility"],
deps = [
"//scripts/src/java/org/oppia/android/scripts/common:bazel_client",
"//scripts/src/java/org/oppia/android/scripts/common:git_client",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.oppia.android.scripts.wiki

import java.io.File

/**
* Script for ensuring that the table of contents in each wiki page matches with its respective headers.
*
* Usage:
* bazel run //scripts:wiki_table_of_contents_check -- <path_to_default_working_directory>
*
* Arguments:
* - path_to_default_working_directory: The default working directory on the runner for steps, and the default location of repository.
*
* Example:
* bazel run //scripts:wiki_table_of_contents_check -- $(pwd)
*/
fun main(vararg args: String) {
// Path to the repo's wiki.
val wikiDirPath = "${args[0]}/wiki/"
val wikiDir = File(wikiDirPath)

// Check if the wiki directory exists.
if (wikiDir.exists() && wikiDir.isDirectory) {
processWikiDirectory(wikiDir)
println("WIKI TABLE OF CONTENTS CHECK PASSED")
} else {
println("No contents found in the Wiki directory.")
}
}

private fun processWikiDirectory(wikiDir: File) {
wikiDir.listFiles()?.forEach { file ->
checkTableOfContents(file)
}
}

private fun checkTableOfContents(file: File) {
val fileContents = file.readLines()
val tocStartIdx = fileContents.indexOfFirst {
it.contains(Regex("""##\s+Table\s+of\s+Contents""", RegexOption.IGNORE_CASE))
}
if (tocStartIdx == -1) {
return
}

// Skipping the blank line after the ## Table of Contents
val tocEndIdx = fileContents.subList(tocStartIdx + 2, fileContents.size).indexOfFirst {
it.startsWith("#")
}.takeIf { it != -1 }
?: error("Wiki doesn't contain headers referenced in Table of Contents.")

val tocSpecificLines = fileContents.subList(tocStartIdx, tocStartIdx + tocEndIdx + 1)

for (line in tocSpecificLines) {
if (line.trimStart().startsWith("- [") && !line.contains("https://")) {
validateTableOfContents(file, line)
}
}
}

private fun validateTableOfContents(file: File, line: String) {
val titleRegex = "\\[(.*?)\\]".toRegex()
val title = titleRegex.find(line)?.groupValues?.get(1)?.replace('-', ' ')
?.replace(Regex("[?&./:’'*!,(){}\\[\\]+]"), "")
?.trim()

val linkRegex = "\\(#(.*?)\\)".toRegex()
val link = linkRegex.find(line)?.groupValues?.get(1)?.removePrefix("#")?.replace('-', ' ')
?.replace(Regex("[?&./:’'*!,(){}\\[\\]+]"), "")
?.trim()

// Checks if the table of content title matches with the header link text.
val matches = title.equals(link, ignoreCase = true)
if (!matches) {
error(
"\nWIKI TABLE OF CONTENTS CHECK FAILED" +
"\nMismatch of Table of Content with headers in the File: ${file.name}. " +
"\nThe Title: '${titleRegex.find(line)?.groupValues?.get(1)}' " +
"doesn't match with its corresponding Link: '${linkRegex.find(line)?.groupValues?.get(1)}'."
)
}
}
16 changes: 16 additions & 0 deletions scripts/src/javatests/org/oppia/android/scripts/wiki/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Tests corresponding to wiki-related checks.
"""

load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test")

kt_jvm_test(
name = "WikiTableOfContentsCheckTest",
srcs = ["WikiTableOfContentsCheckTest.kt"],
deps = [
"//scripts/src/java/org/oppia/android/scripts/wiki:wiki_table_of_contents_check_lib",
"//testing:assertion_helpers",
"//third_party:com_google_truth_truth",
"//third_party:org_jetbrains_kotlin_kotlin-test-junit",
],
)
Loading

0 comments on commit a6bf1a6

Please sign in to comment.