Skip to content

Commit

Permalink
Merge branch 'ankidroid:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tamojitdas authored Jun 26, 2024
2 parents a954b1c + 4aecb2a commit b34fd45
Show file tree
Hide file tree
Showing 615 changed files with 27,660 additions and 5,579 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ updates:
- "dependencies"
ignore:
# Ignore all Rust backend updates, these are always done as manual pulls
- dependency-name: io.github.david-allison:anki-android-backend
- dependency-name: ankiBackend
- package-ecosystem: npm
directory: "/tools/localization"
schedule:
Expand Down
112 changes: 112 additions & 0 deletions .github/workflows/compare_apk_size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: APK Size Comparison

on:
workflow_dispatch:
inputs:
prNumber:
description: "Number of PR to calculate sizes for"
required: true
type: number

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true


permissions:
contents: read
pull-requests: write


jobs:
sizeCheck:
name: APK Size Check
timeout-minutes: 30
runs-on: ubuntu-latest
env:
KEYSTORENAME: keystore
KEYSTOREPWD: testpass
KEYPWD: testpass
KEYALIAS: nrkeystorealias
steps:
- name: Configure JDK
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "21"

- name: Test Credential Prep
run: |
export KEYSTOREPATH=$HOME/$KEYSTORENAME
echo "KEYSTOREPATH=$KEYSTOREPATH" >> $GITHUB_ENV
echo y | keytool -genkeypair -dname "cn=AnkiDroid, ou=ankidroid, o=AnkiDroid, c=US" -alias $KEYALIAS -keypass $KEYPWD -keystore $KEYSTOREPATH -storepass $KEYSTOREPWD -keyalg RSA -validity 20000
shell: bash

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
timeout-minutes: 5
with:
cache-read-only: true
gradle-home-cache-cleanup: true

- name: Checkout PR
uses: actions/checkout@v4
with:
fetch-depth: 1
ref: 'refs/pull/${{ github.event.inputs.prNumber }}/head'

- name: Assemble PR APK
# This makes sure we fetch gradle network resources with a retry
uses: nick-invision/retry@v3
with:
timeout_minutes: 10
retry_wait_seconds: 60
max_attempts: 3
command: ./gradlew :AnkiDroid:assemblePlayRelease --daemon

- name: Get PR APK size
run: echo NEWSIZE=`ls -lrt AnkiDroid/build/outputs/apk/play/release/AnkiDroid-play-arm64-v8a-release.apk | awk '{print $5}'` >> $GITHUB_ENV

- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 1

- name: Assemble Baseline APK
# This makes sure we fetch gradle network resources with a retry
uses: nick-invision/retry@v3
with:
timeout_minutes: 10
retry_wait_seconds: 60
max_attempts: 3
command: ./gradlew :AnkiDroid:assemblePlayRelease --daemon

- name: Get Baseline APK size
run: echo OLDSIZE=`ls -lrt AnkiDroid/build/outputs/apk/play/release/AnkiDroid-play-arm64-v8a-release.apk | awk '{print $5}'` >> $GITHUB_ENV

- name: Post comment
uses: actions/github-script@v7
with:
script: |
var inputs = ${{ toJSON(inputs) }}
let prNumber = inputs['prNumber'];
async function getPullRequest() {
return await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
}
const pullRequestData = await getPullRequest();
async function addComment(prNumber, oldSize, newSize) {
return await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `Old APK size: ${oldSize}
New APK size: ${newSize}`
})
}
await addComment(prNumber, process.env.OLDSIZE, process.env.NEWSIZE);
1 change: 0 additions & 1 deletion .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ jobs:
"18-standard-models",
"20-search-preference",
"marketdescription",
"ankidroid-titles",
];
let stringsLabel = "Strings";
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ jobs:

- name: Credential Prep
run: |
echo "KSTOREPWD=${{ secrets.KEYSTORE_PASSWORD }}" >> $GITHUB_ENV
echo "KEYSTOREPATH=$HOME/src/android-keystore" >> $GITHUB_ENV
echo "KEYALIAS=nrkeystorealias" >> $GITHUB_ENV
echo "KEYSTOREPWD=${{ secrets.KEYSTORE_PASSWORD }}" >> $GITHUB_ENV
echo "KEYPWD=${{ secrets.KEYSTORE_KEY_PASSWORD }}" >> $GITHUB_ENV
mkdir ~/src
echo "${{ secrets.AMAZON_PUBLISH_CREDENTIALS }}" | base64 -d > ~/src/AnkiDroid-Amazon-Publish-Security-Profile.json.gz
echo "${{ secrets.GOOGLE_PUBLISH_CREDENTIALS }}" | base64 -d > ~/src/AnkiDroid-GCP-Publish-Credentials.json.gz
echo "${{ secrets.RELEASES_PUBLISH_TOKEN }}" | base64 -d > ~/src/my-github-personal-access-token.gz
echo "${{ secrets.KEYSTORE }}" | base64 -d > ~/src/android-keystore.gz
cd ~/src
gunzip *gz
echo "${{ secrets.AMAZON_PUBLISH_CREDENTIALS }}" | base64 -d > ./AnkiDroid-Amazon-Publish-Security-Profile.json.gz
echo "${{ secrets.GOOGLE_PUBLISH_CREDENTIALS }}" | base64 -d > ./AnkiDroid-GCP-Publish-Credentials.json.gz
echo "${{ secrets.RELEASES_PUBLISH_TOKEN }}" | base64 -d > ./my-github-personal-access-token.gz
echo "${{ secrets.KEYSTORE }}" | base64 -d > ./android-keystore.gz
gunzip *.gz
shell: bash

- name: Build and Release public release
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
# Do not run the scheduled jobs on forks
if: (github.event_name == 'schedule' && github.repository == 'ankidroid/Anki-Android') || (github.event_name != 'schedule')
needs: matrix_prep
timeout-minutes: 30
timeout-minutes: 35
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
strategy:
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
timeout-minutes: 5
timeout-minutes: 10
with:
# Only write to the cache for builds on the 'main' branches, stops branches evicting main cache
# Builds on other branches will only read from main branch cache writes
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ AnkiDroid/ACRA-INSTALLATION

#ignore the local insufficient memory for the Java Runtime Environment files
hs_err_pid*

# Ignore kotlin 2.0 compiler files (.salive: session-is-alive)
# https://github.com/JetBrains/kotlin/blob/ca34e5d2fd255ed0501bae4fae3d3691dc40d375/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt#L458
/.kotlin
2 changes: 2 additions & 0 deletions .idea/dictionaries/anki.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<dictionary name="anki">
<words>
<w>Ankitects</w>
<w>FSRS</w>
<w>Fsrs</w>
<w>NOTEEDITOR</w>
<w>afmt</w>
Expand Down Expand Up @@ -99,6 +100,7 @@
<w>relrn</w>
<w>replaybutton</w>
<w>resched</w>
<w>retrievability</w>
<w>revlog</w>
<w>revlogs</w>
<w>rlim</w>
Expand Down
37 changes: 27 additions & 10 deletions AnkiDroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static def gitCommitHash() {
android {
namespace "com.ichi2.anki"

compileSdk 34 // change api compileSdk at the same time
compileSdk libs.versions.compileSdk.get().toInteger()

buildFeatures {
buildConfig = true
Expand Down Expand Up @@ -74,20 +74,20 @@ android {
//
// This ensures the correct ordering between the various types of releases (dev < alpha < beta < release) which is
// needed for upgrades to be offered correctly.
versionCode=21900102
versionName="2.19alpha2"
minSdk 23 // also in testlib/build.gradle.kts
versionCode=21900107
versionName="2.19alpha7"
minSdk libs.versions.minSdk.get().toInteger()
// After #13695: change .tests_emulator.yml
targetSdk 33 // also in [api|testlib]/build.gradle.kts and ../robolectricDownloader.gradle
targetSdk libs.versions.targetSdk.get().toInteger()
testApplicationId "com.ichi2.anki.tests"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner 'com.ichi2.testutils.NewCollectionPathTestRunner'
}
signingConfigs {
release {
storeFile file("${homePath}/src/android-keystore")
keyAlias "nrkeystorealias"
storePassword System.getenv("KSTOREPWD")
storeFile file(System.getenv("KEYSTOREPATH") ?: "${homePath}/src/android-keystore")
storePassword System.getenv("KEYSTOREPWD") ?: System.getenv("KSTOREPWD")
keyAlias System.getenv("KEYALIAS") ?: "nrkeystorealias"
keyPassword System.getenv("KEYPWD")
}
}
Expand Down Expand Up @@ -264,6 +264,16 @@ tasks.register('installGitHook', Copy) {
// to run manually: `./gradlew installGitHook`
tasks.named('preBuild').configure { dependsOn('installGitHook') }

tasks.register('copyTestLibIntoAndroidTest', Copy) {
into new File(rootProject.rootDir, 'AnkiDroid/src/androidTest/java/com/ichi2/testutils')
from new File(rootProject.rootDir, 'testlib/src/main/java/com/ichi2/testutils')
into ('common') {
from 'common'
}
}
tasks.named('preBuild').configure { dependsOn('copyTestLibIntoAndroidTest') }
tasks.named('runKtlintCheckOverAndroidTestSourceSet').configure { mustRunAfter('copyTestLibIntoAndroidTest') }

// Issue 11078 - some emulators run, but run zero tests, and still report success
tasks.register('assertNonzeroAndroidTests') {
doLast {
Expand Down Expand Up @@ -306,6 +316,9 @@ dependencies {
compileOnly libs.auto.service.annotations
annotationProcessor libs.auto.service

// modules
implementation project(":common")

implementation libs.androidx.activity
implementation libs.androidx.annotation
implementation libs.androidx.appcompat
Expand Down Expand Up @@ -342,7 +355,7 @@ dependencies {
testImplementation files("../../Anki-Android-Backend/rsdroid-testing/build/libs/rsdroid-testing.jar")
} else {
implementation libs.ankiBackend.backend
implementation libs.ankiBackend.testing
testImplementation libs.ankiBackend.testing
}

// May need a resolution strategy for support libs to our versions
Expand Down Expand Up @@ -402,8 +415,12 @@ dependencies {
exclude module: "protobuf-lite"
}
testImplementation libs.androidx.work.testing
// for testing flows
testImplementation libs.cashapp.turbine

androidTestImplementation project(':testlib')
// we should depend directly on the common testlib for androidTest, but we cannot
// until coverage-breaking issue is fixed https://issuetracker.google.com/issues/332746900
// androidTestImplementation project(':testlib')

// May need a resolution strategy for support libs to our versions
androidTestImplementation libs.androidx.espresso.core
Expand Down
37 changes: 37 additions & 0 deletions AnkiDroid/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import groovy.transform.Memoized
import groovy.xml.XmlParser

apply plugin: 'jacoco'

Expand Down Expand Up @@ -167,3 +168,39 @@ def androidTestReport = tasks.register('jacocoAndroidTestReport', JacocoReport)
])
}
androidTestReport.configure { dependsOn('connectedPlayDebugAndroidTest') }

// Issue 16640 - some emulators run, but register zero coverage
tasks.register('assertNonzeroAndroidTestCoverage') {
doLast {
File jacocoReport = layout.buildDirectory.dir("reports/jacoco/jacocoAndroidTestReport/jacocoAndroidTestReport.xml").get().asFile

if (!jacocoReport.exists())
throw new FileNotFoundException("jacocoAndroidTestReport.xml was not found after running jacocoAndroidTestReport")

XmlParser xmlParser = new XmlParser()
xmlParser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
xmlParser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)

Node reportRoot = xmlParser.parse(jacocoReport)
boolean hasCovered = false

// https://github.com/jacoco/jacoco/blob/5aabb2eb60bbcd05df968005f1746ba19dcd5361/org.jacoco.report/src/org/jacoco/report/internal/xml/ReportElement.java#L190
for (Node child : reportRoot.children()) {
if (child.name() != "counter")
continue;

if (child.attribute("covered") == "0") {
logger.warn("jacoco registered zero code coverage for counter type " + child.attribute("type"), null)
} else {
hasCovered = true
}
}

if (!hasCovered)
throw new GradleScriptException("androidTest registered zero code coverage in jacocoAndroidTestReport.xml. Probably some incompatibilities in the toolchain.", null)
}
}
afterEvaluate {
tasks.named('jacocoAndroidTestReport').configure { finalizedBy('assertNonzeroAndroidTestCoverage') }
tasks.named('jacocoTestReport').configure { finalizedBy('assertNonzeroAndroidTestCoverage') }
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.anki.NoteEditor.Companion.intentLaunchedWithImage
import com.ichi2.anki.tests.InstrumentedTest
import com.ichi2.anki.testutil.GrantStoragePermission
import com.ichi2.testutils.Flaky
import com.ichi2.testutils.OS
import com.ichi2.testutils.common.Flaky
import com.ichi2.testutils.common.OS
import com.ichi2.utils.AssetHelper.TEXT_PLAIN
import junit.framework.TestCase.assertFalse
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
Expand Down Expand Up @@ -62,7 +63,7 @@ class NoteEditorIntentTest : InstrumentedTest() {
fun intentLaunchedWithNonImageIntent() {
val intent = Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
type = TEXT_PLAIN
}
assertFalse(intentLaunchedWithImage(intent))
}
Expand Down
1 change: 0 additions & 1 deletion AnkiDroid/src/androidTest/java/com/ichi2/anki/PagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import android.content.Context
import android.content.Intent
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import com.ichi2.anki.pages.CardInfo.Companion.toIntent
import com.ichi2.anki.pages.CardInfoDestination
import com.ichi2.anki.pages.DeckOptions
import com.ichi2.anki.pages.PageFragment
Expand Down
Loading

0 comments on commit b34fd45

Please sign in to comment.