Skip to content

Commit

Permalink
Fix #4850: Bump version codes for alpha 0.10 release, and fix version…
Browse files Browse the repository at this point in the history
… code ordering (#4851)

## Explanation
Fixes #4850

This PR introduces the necessary version code updates for an upcoming
0.10 alpha release (2 different RCs). It also fixes the order of version
codes such that less stable versions of the app (i.e. build flavors)
take priority over more stable ones (so that users signed up for an
earlier pre-release will get that over later versions, e.g. users would
receive an alpha version of the app over beta if they're in both). This
happens because Play Store uses version codes as the actual comparable
versions for uploaded binaries, and it picks the binary with the highest
version code to be installed based on all that a user may qualify for
(based on which release tracks that they're participating in). The
assumption here is that newer versions maintain backward compatibility
with older versions, and this is something we will continue to aim for
(though with minimal guarantees for pre-release versions).

Note that one unfortunate side effect of this change is that local
installs of the app will require manually uninstalling when installing a
"more stable" build flavor (though technically this was an issue in the
other direction previously). This does make "upgrade" flows a little
trickier to test locally unless using pre-assembled binaries.

This PR also updates app versioning such that the version now includes
the local branch's commit rather than the common commit with develop (to
ensure RC rebuilds have properly unique version names rather than
sharing one version name for the release branch).

## 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)).

## For UI-specific PRs only
N/A -- This is an infrastructure-only change.
  • Loading branch information
BenHenning authored Mar 10, 2023
1 parent c1ce5f8 commit a541783
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private class TransformAndroidManifest(
}
val versionNameAttribute = manifestDocument.createAttribute("android:versionName").apply {
value = computeVersionName(
buildFlavor, majorVersion, minorVersion, commitHash = gitClient.branchMergeBase
buildFlavor, majorVersion, minorVersion, commitHash = gitClient.currentCommit
)
}
val applicationNameAttribute = manifestDocument.createAttribute("android:name").apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class GitClient(
) {
private val commandExecutor by lazy { CommandExecutorImpl() }

/** The commit hash of the HEAD of the local Git repository. */
val currentCommit: String by lazy { retrieveCurrentCommit() }

/** The name of the current branch of the local Git repository. */
val currentBranch: String by lazy { retrieveCurrentBranch() }

Expand All @@ -25,6 +28,10 @@ class GitClient(
*/
val changedFiles: Set<String> by lazy { retrieveChangedFilesWithPotentialDuplicates().toSet() }

private fun retrieveCurrentCommit(): String {
return executeGitCommandWithOneLineOutput("rev-parse HEAD")
}

private fun retrieveCurrentBranch(): String {
return executeGitCommandWithOneLineOutput("rev-parse --abbrev-ref HEAD")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TransformAndroidManifestTest {
@JvmField
var tempFolder = TemporaryFolder()

private val commandExecutor by lazy { CommandExecutorImpl() }
private lateinit var testGitRepository: TestGitRepository

@Before
Expand Down Expand Up @@ -349,6 +350,11 @@ class TransformAndroidManifestTest {
val manifestFile = tempFolder.newFile(TEST_MANIFEST_FILE_NAME).apply {
writeText(TEST_MANIFEST_CONTENT_WITHOUT_VERSIONS)
}
// Use a separate branch to ensure the version uses the latest commit rather than the common
// merge base with the develop branch.
testGitRepository.checkoutNewBranch("release-branch")
testGitRepository.commit(message = "Release-only commit, e.g. a cherry-pick", allowEmpty = true)
val latestCommit = getMostRecentCommitOnCurrentBranch()

runScript(
tempFolder.root.absolutePath,
Expand All @@ -367,7 +373,7 @@ class TransformAndroidManifestTest {
assertThat(transformedManifest)
.containsMatch(
"android:versionName=\"$MAJOR_VERSION\\.$MINOR_VERSION" +
"-$BUILD_FLAVOR-[a-f0-9]{10}\""
"-$BUILD_FLAVOR-${latestCommit.take(10)}\""
)
assertThat(transformedManifest)
.containsMatch("<application android:name=\"$APPLICATION_RELATIVE_QUALIFIED_CLASS\"")
Expand All @@ -386,4 +392,11 @@ class TransformAndroidManifestTest {
testGitRepository.checkoutNewBranch("develop")
testGitRepository.commit(message = "Initial commit.", allowEmpty = true)
}

private fun getMostRecentCommitOnCurrentBranch(): String {
// See https://stackoverflow.com/a/949391 for a reference to validate that this is correct.
return commandExecutor.executeCommand(
tempFolder.root, "git", "rev-parse", "HEAD"
).output.single()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,42 @@ class GitClientTest {
println(testGitRepository.status())
}

@Test
fun testCurrentCommit_forNonRepository_throwsException() {
val gitClient = GitClient(tempFolder.root, "develop")

val exception = assertThrows(IllegalStateException::class) { gitClient.currentCommit }

assertThat(exception).hasMessageThat().contains("Expected non-zero exit code")
assertThat(exception).hasMessageThat().ignoringCase().contains("not a git repository")
}

@Test
fun testCurrentCommit_forValidRepository_returnsCorrectBranch() {
initializeRepoWithDevelopBranch()
val developHash = getMostRecentCommitOnCurrentBranch()

val gitClient = GitClient(tempFolder.root, "develop")
val currentCommit = gitClient.currentCommit

assertThat(currentCommit).isEqualTo(developHash)
}

@Test
fun testCurrentCommit_switchBranch_returnsCorrectBranch() {
initializeRepoWithDevelopBranch()
val developHash = getMostRecentCommitOnCurrentBranch()
testGitRepository.checkoutNewBranch("introduce-feature")
testGitRepository.commit(message = "Test empty commit", allowEmpty = true)
val featureBranchHash = getMostRecentCommitOnCurrentBranch()

val gitClient = GitClient(tempFolder.root, "develop")
val currentCommit = gitClient.currentCommit

assertThat(currentCommit).isNotEqualTo(developHash)
assertThat(currentCommit).isEqualTo(featureBranchHash)
}

@Test
fun testCurrentBranch_forNonRepository_throwsException() {
val gitClient = GitClient(tempFolder.root, "develop")
Expand Down
19 changes: 11 additions & 8 deletions version.bzl
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
"""
Defines the latest version of the Oppia Android app.
Note that version codes must be ordered such that dev < alpha, and kitkat < lollipop+. This will
Note that version codes must be ordered such that dev > alpha, and kitkat < lollipop+. This will
ensure that the Play Store provides users with the correct version of the app in situations where
their device qualifies for more than one choice.
More unstable flavors of the app are higher version codes since they represent "newer" versions of
the app (that are potentially not broadly released yet).
"""

MAJOR_VERSION = 0
MINOR_VERSION = 10

# TODO(#4419): Remove the Kenya-specific alpha version code.
OPPIA_DEV_KITKAT_VERSION_CODE = 48
OPPIA_DEV_VERSION_CODE = 49
OPPIA_ALPHA_KITKAT_VERSION_CODE = 50
OPPIA_ALPHA_VERSION_CODE = 51
OPPIA_ALPHA_KENYA_VERSION_CODE = 52
OPPIA_BETA_VERSION_CODE = 53
OPPIA_GA_VERSION_CODE = 54
OPPIA_DEV_VERSION_CODE = 75
OPPIA_DEV_KITKAT_VERSION_CODE = 74
OPPIA_ALPHA_VERSION_CODE = 73
OPPIA_ALPHA_KITKAT_VERSION_CODE = 72
OPPIA_ALPHA_KENYA_VERSION_CODE = 71
OPPIA_BETA_VERSION_CODE = 70
OPPIA_GA_VERSION_CODE = 69

0 comments on commit a541783

Please sign in to comment.