From 56230c5c623a84b21770ac81d96db7812630dae2 Mon Sep 17 00:00:00 2001 From: jo-elimu <1451036+jo-elimu@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:50:12 +0700 Subject: [PATCH 1/5] chore: Upgrade to model-2.0.62 closes #95 --- README.md | 10 +++++----- app/build.gradle | 2 +- utils/build.gradle | 2 +- .../content_provider/utils/ContentProviderUtil.java | 3 +++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2cb3c11..0bdd345 100644 --- a/README.md +++ b/README.md @@ -34,18 +34,18 @@ Here is how to use the `utils` library in another Android app: implementation 'com.github.elimu-ai:content-provider:@aar' } -See https://jitpack.io/#elimu-ai/content-provider/ +See https://jitpack.io/#elimu-ai/content-provider/ for the latest version available. ### Usage Example For an example of another Android app using the `utils` library, see the Vitabu app's Gradle configuration: - 1. https://github.com/elimu-ai/vitabu/blob/master/build.gradle - 1. https://github.com/elimu-ai/vitabu/blob/master/app/build.gradle + 1. https://github.com/elimu-ai/vitabu/blob/main/build.gradle + 1. https://github.com/elimu-ai/vitabu/blob/main/app/build.gradle --- -elimu.ai - Free personalized learning for every child on Earth 🌍🌏🌎 +elimu.ai - Free open source learning software for out-of-school children βœ¨πŸš€ -[Website 🌐](https://elimu.ai)   [Wiki πŸ“ƒ](https://github.com/elimu-ai/wiki#readme)   [Projects πŸ‘©πŸ½β€πŸ’»](https://github.com/elimu-ai/wiki/projects)   [Milestones 🎯](https://github.com/elimu-ai/wiki/milestones)   [Community πŸ‘‹πŸ½](https://github.com/elimu-ai/wiki#open-source-community) +[Website 🌐](https://elimu.ai)   [Wiki πŸ“ƒ](https://github.com/elimu-ai/wiki#readme)   [Projects πŸ‘©πŸ½β€πŸ’»](https://github.com/orgs/elimu-ai/projects?query=is%3Aopen)   [Milestones 🎯](https://github.com/elimu-ai/wiki/milestones)   [Community πŸ‘‹πŸ½](https://github.com/elimu-ai/wiki#open-source-community) diff --git a/app/build.gradle b/app/build.gradle index 9582d97..e55432b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,7 +40,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.github.elimu-ai:model:model-2.0.53' // See https://jitpack.io/#elimu-ai/model + implementation 'com.github.elimu-ai:model:model-2.0.62' // See https://jitpack.io/#elimu-ai/model implementation 'commons-io:commons-io:2.11.0' implementation 'com.google.android.material:material:1.5.0' diff --git a/utils/build.gradle b/utils/build.gradle index 2ed934c..c50662e 100644 --- a/utils/build.gradle +++ b/utils/build.gradle @@ -26,7 +26,7 @@ android { } dependencies { - implementation 'com.github.elimu-ai:model:model-2.0.53' // See https://jitpack.io/#elimu-ai/model + implementation 'com.github.elimu-ai:model:model-2.0.62' // See https://jitpack.io/#elimu-ai/model implementation 'com.github.elimu-ai:analytics:3.1.11@aar' // See https://jitpack.io/#elimu-ai/analytics } diff --git a/utils/src/main/java/ai/elimu/content_provider/utils/ContentProviderUtil.java b/utils/src/main/java/ai/elimu/content_provider/utils/ContentProviderUtil.java index 6dd97dd..6f49dfc 100644 --- a/utils/src/main/java/ai/elimu/content_provider/utils/ContentProviderUtil.java +++ b/utils/src/main/java/ai/elimu/content_provider/utils/ContentProviderUtil.java @@ -130,6 +130,9 @@ public static List getAvailableWordGsons(Context context, String conte return wordGsons; } + /** + * This method is only meant to be used for testing purposes during development. + */ public static List getAllWordGsons(Context context, String contentProviderApplicationId) { Log.i(ContentProviderUtil.class.getName(), "getAllWordGsons"); From 458b8db210a75d2848dbcbfb704177997078b644 Mon Sep 17 00:00:00 2001 From: jo-elimu <1451036+jo-elimu@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:07:03 +0700 Subject: [PATCH 2/5] chore: Upgrade to SDK 33 --- .github/workflows/{gradle.yml => gradle-build.yml} | 4 ++-- app/build.gradle | 4 ++-- utils/build.gradle | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename .github/workflows/{gradle.yml => gradle-build.yml} (82%) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle-build.yml similarity index 82% rename from .github/workflows/gradle.yml rename to .github/workflows/gradle-build.yml index d9def3a..bdb1163 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle-build.yml @@ -1,4 +1,4 @@ -name: Gradle CI +name: Gradle Build on: push: @@ -10,7 +10,7 @@ jobs: build: strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 diff --git a/app/build.gradle b/app/build.gradle index e55432b..ff8ea46 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 32 + compileSdk 33 defaultConfig { applicationId "ai.elimu.content_provider" minSdkVersion 24 - targetSdkVersion 32 + targetSdkVersion 33 versionCode 1002012 versionName "1.2.12-SNAPSHOT" setProperty("archivesBaseName", "${applicationId}-${versionCode}") diff --git a/utils/build.gradle b/utils/build.gradle index c50662e..6b2f503 100644 --- a/utils/build.gradle +++ b/utils/build.gradle @@ -4,11 +4,11 @@ plugins { } android { - compileSdkVersion 32 + compileSdk 33 defaultConfig { minSdkVersion 24 - targetSdkVersion 32 + targetSdkVersion 33 versionCode 1002012 versionName "1.2.12-SNAPSHOT" setProperty("archivesBaseName", "utils-${versionName}") From de75ee334f088ced41c10361e01f8e3c1a40777c Mon Sep 17 00:00:00 2001 From: jo-elimu <1451036+jo-elimu@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:25:21 +0700 Subject: [PATCH 3/5] chore: Add Gradle release --- .github/workflows/gradle-release.yml | 25 +++++++++++++++++ README.md | 3 ++ app/build.gradle | 41 ++++++++++++++++++++++++++++ build.gradle | 1 + 4 files changed, 70 insertions(+) create mode 100644 .github/workflows/gradle-release.yml diff --git a/.github/workflows/gradle-release.yml b/.github/workflows/gradle-release.yml new file mode 100644 index 0000000..38a9003 --- /dev/null +++ b/.github/workflows/gradle-release.yml @@ -0,0 +1,25 @@ +name: Gradle Release + +on: + workflow_dispatch: + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: gradle + + - run: git config user.name 'Nya Ξlimu' + - run: git config user.email 'info@elimu.ai' + + - run: ./gradlew releaseClean + - run: ./gradlew releasePrepare -PbumpType=patch + - run: ./gradlew releasePerform diff --git a/README.md b/README.md index 0bdd345..e8c8d44 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,9 @@ For an example of another Android app using the `utils` library, see the Vitabu 1. https://github.com/elimu-ai/vitabu/blob/main/build.gradle 1. https://github.com/elimu-ai/vitabu/blob/main/app/build.gradle +## Release πŸ“¦ + +See [.github/workflows/gradle-release.yml](.github/workflows/gradle-release.yml) --- diff --git a/app/build.gradle b/app/build.gradle index ff8ea46..38c085e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.application' +apply plugin: 'org.ajoberstar.grgit' android { compileSdk 33 @@ -67,3 +68,43 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' } + +task ensureCleanRepo { + doLast { + if (!grgit.repository.jgit.status().call().clean) { + throw new GradleException('Git status is not clean, please stash your changes!') + } + } +} + +task releaseClean(dependsOn: ensureCleanRepo) { + doLast { + def clean = true + def applicationId = android.defaultConfig.applicationId + + String headCommitMessage = grgit.head().shortMessage + while (headCommitMessage.contains("[gradle-release-task]")) { + clean = false + println "Found git commit: $headCommitMessage" + if (headCommitMessage.indexOf("$applicationId-") > -1) { + def tagName = headCommitMessage.split("$applicationId-")[1] + println "Removing the git tag: $tagName" + try { + grgit.tag.remove { + names = [tagName] + } + } catch (Exception e) { + println "Error while removing git tag:\n $e" + } + } + println "Resetting the git commit permanently!" + grgit.reset(commit: "HEAD~1", mode: "hard") + headCommitMessage = grgit.head().shortMessage + + } + if (clean){ + println "Repository is already clean" + } + println "Done!" + } +} diff --git a/build.gradle b/build.gradle index 15914cf..19fb700 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:7.1.3' + classpath 'org.ajoberstar.grgit:grgit-gradle:5.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 994811cd8c15ac3aa946f78eda9f43a0fd0a6ba2 Mon Sep 17 00:00:00 2001 From: jo-elimu <1451036+jo-elimu@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:27:41 +0700 Subject: [PATCH 4/5] chore: Gradle release prepare --- app/build.gradle | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 38c085e..a3d6a71 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -108,3 +108,70 @@ task releaseClean(dependsOn: ensureCleanRepo) { println "Done!" } } + +// Task parameters: +// bumpVersion -> if available will specify new versionName directly and ignores the `bumpType` parameter. +// bumpType[major|minor|patch] -> will specify how the version bumping occurs. +task releasePrepare(dependsOn: ensureCleanRepo) { + doLast { + def applicationId = android.defaultConfig.applicationId + def versionName = android.defaultConfig.versionName + + if (versionName.indexOf("-") > -1) { + versionName = versionName.split("-")[0] + } + + // Prepare the release commit with the specific tag. + String buildText = buildFile.getText() + buildText = buildText.replaceFirst(/versionName(\s+.*)/, "versionName '$versionName'") + buildFile.setText(buildText) //replace the build file's text + grgit.add(patterns: ['app/build.gradle']) + grgit.commit(message: "[gradle-release-task] prepare release $applicationId-$versionName") + try { + grgit.tag.add { + name = versionName + message = "Release of $versionName" + } + } catch (Exception e) { + throw new GradleException("Failed to tag the repo, error:\n $e") + } + + // Set new version name from input parameters. + def newVersionName + if (project.properties.containsKey("bumpVersion")) { + newVersionName = project.properties["bumpVersion"] + println "Bumping the version directly (bumpVersion=$newVersionName)" + } else if (project.properties.containsKey("bumpType")) { + def (major, minor, patch) = versionName.tokenize('.') + switch (bumpType) { + case "major": + major = major.toInteger() + 1 + minor = 0 + patch = 0 + break + case "minor": + minor = minor.toInteger() + 1 + break + case "patch": + patch = patch.toInteger() + 1 + break + } + newVersionName = "$major.$minor.$patch" + } else { + throw new GradleException('Either bumpType or bumpVersion parameters should be provided') + } + + // Prepare for next development iteration. + def versionCode = android.defaultConfig.versionCode + def newVersionCode = versionCode + 1 + println "Bumping versionName from $versionName to $newVersionName" + println "Bumping versionCode from $versionCode to $newVersionCode" + buildText = buildFile.getText() + buildText = buildText.replaceFirst(/versionName(\s+.*)/, "versionName '$newVersionName-SNAPSHOT'") + buildText = buildText.replaceFirst(/versionCode(\s+.*)/, "versionCode $newVersionCode") + buildFile.setText(buildText) //replace the build file's text + grgit.add(patterns: ['app/build.gradle']) + grgit.commit(message: "[gradle-release-task] prepare for next development iteration") + println "Done!" + } +} From 5a89e4a0d28fadba7b926230502147a7fcda2bea Mon Sep 17 00:00:00 2001 From: jo-elimu <1451036+jo-elimu@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:35:59 +0700 Subject: [PATCH 5/5] chore: Gradle release perform --- app/build.gradle | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index a3d6a71..af1ac09 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -175,3 +175,20 @@ task releasePrepare(dependsOn: ensureCleanRepo) { println "Done!" } } + +task releasePerform(dependsOn: ensureCleanRepo) { + doLast { + boolean force = false + if (project.properties.containsKey("force")) { + force = project.properties["force"] + } + println "Pushing the newest commits to the remote repository (force: $force)" + try { + grgit.push(force: force, tags: true) + } catch (Exception e) { + throw new GradleException("Failed to push to the repo,\n" + + " you can try using -Pforce=true parameter to force the push, error: \n$e") + } + println "Done!" + } +}