Skip to content

Commit a7c1723

Browse files
committed
Merge branch 'firebase-sessions' into sessions-workflow
# Conflicts: # .github/workflows/sessions-e2e.yml
2 parents 92e3705 + 3dc6211 commit a7c1723

File tree

12 files changed

+121
-55
lines changed

12 files changed

+121
-55
lines changed

.github/workflows/merge-to-main.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,5 @@ jobs:
2626
using a feature branch first, and only merge into the main
2727
branch when the code complete and ready to be released.
2828
29-
30-
**Add the 'main-merge-ack' label to your PR to confirm
31-
merging into the main branch is intended.**
32-
33-
- name: Label checker
34-
if: "!contains( github.event.pull_request.labels.*.name, 'main-merge-ack')"
35-
run: |
36-
echo Missing 'main-merge-ack' label. Read the comment about merging to master in your PR for more information.
37-
exit 1
38-
3929
- name: Success
4030
run: exit 0

.github/workflows/sessions-e2e.yml

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Firebase Sessions E2E Tests
22

33
on:
4-
workflow_dispatch: # allow triggering the workflow manually
4+
workflow_dispatch: # allow triggering the workflow manually
55

66
concurrency:
77
group: ${{ github.workflow }}
@@ -10,26 +10,29 @@ env:
1010
SESSIONS_E2E_GOOGLE_SERVICES: ${{ secrets.SESSIONS_E2E_GOOGLE_SERVICES }}
1111

1212
jobs:
13-
test:
13+
build:
14+
1415
runs-on: ubuntu-latest
15-
strategy:
16-
matrix:
17-
environment: [ prod, autopush ]
16+
1817
steps:
19-
- name: Checkout firebase-android-sdk
20-
uses: actions/checkout@v3
21-
22-
- name: Set up JDK 11
23-
uses: actions/setup-java@v2
24-
with:
25-
java-version: 11
26-
distribution: temurin
27-
cache: gradle
28-
29-
- name: Add google-services.json
30-
run: |
31-
echo $SESSIONS_E2E_GOOGLE_SERVICES | base64 -d > google-services.json
32-
33-
- name: Run sessions end-to-end tests
34-
run: |
35-
./gradlew firebase-sessions:deviceCheck withErrorProne -PtargetBackend="prod"
18+
- name: Checkout firebase-sessions
19+
uses: actions/checkout@v3
20+
with:
21+
ref: 'firebase-sessions'
22+
23+
- name: set up JDK 11
24+
uses: actions/setup-java@v3
25+
with:
26+
java-version: '11'
27+
distribution: 'temurin'
28+
cache: gradle
29+
30+
- name: Add google-services.json
31+
run: |
32+
echo $SESSIONS_E2E_GOOGLE_SERVICES | base64 -d > google-services.json
33+
34+
- name: Grant execute permission for gradlew
35+
run: chmod +x gradlew
36+
37+
- name: Run sessions end-to-end tests
38+
run: ./gradlew firebase-sessions:deviceCheck withErrorProne -PtargetBackend="prod"

buildSrc/src/main/java/com/google/firebase/gradle/plugins/LibraryGroupRegistrar.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ class LibraryGroupRegistrar {
2626
librariesByGroup
2727
.get(libraryGroup)
2828
.map { it.project.version.toString() }
29-
.filter { it.first().isDigit() } // to filter out any flag values
29+
.mapNotNull { ModuleVersion.fromStringOrNull(it) }
3030
.maxOrNull()
31-
?: "unspecified"
32-
librariesByGroup.get(libraryGroup).forEach { it.project.version = maxVersion }
31+
if (maxVersion != null) {
32+
librariesByGroup
33+
.get(libraryGroup)
34+
.filter { ModuleVersion.fromStringOrNull(it.project.version.toString()) == null }
35+
.forEach { it.project.version = maxVersion.toString() }
36+
}
3337
}
3438

3539
fun getLibrariesForGroup(name: String) = librariesByGroup.get(name)

buildSrc/src/main/java/com/google/firebase/gradle/plugins/ModuleVersion.kt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ enum class PreReleaseVersionType {
5757
*
5858
* Note that `build` will always be present as starting at one by defalt. That is, the following
5959
* transform occurs:
60-
*
6160
* ```
6261
* "12.13.1-beta" // 12.13.1-beta01
6362
* ```
6463
*
6564
* @see fromStringsOrNull
66-
*
6765
* @property type an enum of [PreReleaseVersionType] that identifies the pre-release identifier
6866
* @property build an [Int] that specifies the build number; defaults to one
6967
*/
70-
data class PreReleaseVersion(val type: PreReleaseVersionType, val build: Int = 1) {
68+
data class PreReleaseVersion(val type: PreReleaseVersionType, val build: Int = 1) :
69+
Comparable<PreReleaseVersion> {
70+
7171
companion object {
7272

7373
/**
@@ -77,7 +77,6 @@ data class PreReleaseVersion(val type: PreReleaseVersionType, val build: Int = 1
7777
* [PreReleaseVersion].
7878
*
7979
* Example Usage:
80-
*
8180
* ```
8281
* PreReleaseVersion.fromStringsOrNull("alpha", "6") // PreReleaseVersion(ALPHA, 6)
8382
* PreReleaseVersion.fromStringsOrNull("Beta", "") // PreReleaseVersion(BETA, 1)
@@ -87,7 +86,6 @@ data class PreReleaseVersion(val type: PreReleaseVersionType, val build: Int = 1
8786
* @param type a case insensitive string of any [PreReleaseVersionType]
8887
* @param build a string number; gets automatically converted to double digits, and defaults to
8988
* one if blank
90-
*
9189
* @return a [PreReleaseVersion] created from the string, or null if the string was invalid.
9290
*/
9391
fun fromStringsOrNull(type: String, build: String): PreReleaseVersion? =
@@ -100,14 +98,16 @@ data class PreReleaseVersion(val type: PreReleaseVersionType, val build: Int = 1
10098
.getOrNull()
10199
}
102100

101+
override fun compareTo(other: PreReleaseVersion) =
102+
compareValuesBy(this, other, { it.type }, { it.build })
103+
103104
/** Returns a copy of this [PreReleaseVersion], with the [build] increased by one. */
104105
fun bump() = copy(build = build + 1)
105106

106107
/**
107108
* Formatted as `TypeBuild`
108109
*
109110
* For example:
110-
*
111111
* ```
112112
* PreReleaseVersion(ALPHA, 5).toString() // "alpha05"
113113
* PreReleaseVersion(RC, 12).toString() // "rc12"
@@ -124,21 +124,32 @@ data class PreReleaseVersion(val type: PreReleaseVersionType, val build: Int = 1
124124
*
125125
* To see rules about pre-release (`PRE`) formatting, see [PreReleaseVersion].
126126
*
127+
* @see fromStringOrNull
127128
* @property major An update that represents breaking changes
128129
* @property minor An update that represents new functionality
129130
* @property patch An update that represents bug fixes
130131
* @property pre An update that represents unstable changes not ready for a full release
131-
* @see fromStringOrNull
132132
*/
133133
data class ModuleVersion(
134134
val major: Int,
135135
val minor: Int,
136136
val patch: Int,
137137
val pre: PreReleaseVersion? = null
138-
) {
138+
) : Comparable<ModuleVersion> {
139139

140140
/** Formatted as `MAJOR.MINOR.PATCH-PRE` */
141-
override fun toString() = "$major.$minor.$patch${pre?.let { "-${it.toString()}" }}"
141+
override fun toString() = "$major.$minor.$patch${pre?.let { "-${it.toString()}" } ?: ""}"
142+
143+
override fun compareTo(other: ModuleVersion) =
144+
compareValuesBy(
145+
this,
146+
other,
147+
{ it.major },
148+
{ it.minor },
149+
{ it.patch },
150+
{ it.pre == null }, // a version with no prerelease version takes precedence
151+
{ it.pre }
152+
)
142153

143154
companion object {
144155
/**
@@ -149,15 +160,13 @@ data class ModuleVersion(
149160
* `(N digits).(N digits).(N digits)-(maybe letters)(maybe numbers)`
150161
*
151162
* For example, the following would be valid matches:
152-
*
153163
* ```
154164
* "13.1.5" // valid
155165
* "5.0.5-beta" // valid
156166
* "19.45.12-rc09" // valid
157167
* ```
158168
*
159169
* While the following would not be:
160-
*
161170
* ```
162171
* "1.3.4-" // invalid
163172
* "16.2.3-01" // invalid
@@ -181,7 +190,6 @@ data class ModuleVersion(
181190
* ```
182191
*
183192
* @param str a [String] that matches the SemVer format.
184-
*
185193
* @return a [ModuleVersion] created from the string, or null if the string was invalid.
186194
*/
187195
fun fromStringOrNull(str: String): ModuleVersion? =

buildSrc/src/test/kotlin/com/google/firebase/gradle/plugins/PublishingPluginTests.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,13 @@ licenses {
247247

248248
@Test
249249
fun `Publish project should also publish coreleased projects`() {
250-
val project1 = Project(name = "childProject1", version = "1.0", libraryGroup = "test123")
250+
val project1 = Project(name = "childProject1", version = "1.0.0", libraryGroup = "test123")
251251
val project2 =
252252
Project(
253253
name = "childProject2",
254-
version = "0.9",
255254
projectDependencies = setOf(project1),
256255
libraryGroup = "test123",
257-
expectedVersion = "1.0"
256+
expectedVersion = "1.0.0"
258257
)
259258
subprojectsDefined(project1, project2)
260259

docs/make_release_notes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_ktx_header(self):
4545
if not self.has_ktx:
4646
return ''
4747
version_str = f'{{: #{self.version_name}-ktx_v{self.version.replace(".", "-")}}}'
48-
return f'### {self.alt_name} Kotlin extensions version {self.version} {version_str}\n'
48+
return f'#### {self.alt_name} Kotlin extensions version {self.version} {version_str}\n'
4949

5050
def _get_version(self):
5151
properties = os.path.join(os.path.dirname(self.path),

firebase-crashlytics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unreleased
2+
* [feature] Added collection of version control information generated by the AGP.
23

34
# 18.3.6
45
* [feature] Added support for upcoming [crashlytics] features to report

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsController.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.os.Bundle;
2323
import android.os.Environment;
2424
import android.os.StatFs;
25+
import android.util.Base64;
2526
import androidx.annotation.NonNull;
2627
import androidx.annotation.Nullable;
2728
import com.google.android.gms.tasks.SuccessContinuation;
@@ -39,9 +40,11 @@
3940
import com.google.firebase.crashlytics.internal.persistence.FileStore;
4041
import com.google.firebase.crashlytics.internal.settings.Settings;
4142
import com.google.firebase.crashlytics.internal.settings.SettingsProvider;
43+
import java.io.ByteArrayOutputStream;
4244
import java.io.File;
4345
import java.io.FilenameFilter;
4446
import java.io.IOException;
47+
import java.io.InputStream;
4548
import java.util.ArrayList;
4649
import java.util.List;
4750
import java.util.Locale;
@@ -70,6 +73,10 @@ class CrashlyticsController {
7073

7174
private static final String GENERATOR_FORMAT = "Crashlytics Android SDK/%s";
7275

76+
private static final String VERSION_CONTROL_INFO_KEY = "com.crashlytics.version-control-info";
77+
private static final String VERSION_CONTROL_INFO_FILE = "version-control-info.textproto";
78+
private static final String META_INF_FOLDER = "META-INF/";
79+
7380
private final Context context;
7481
private final DataCollectionArbiter dataCollectionArbiter;
7582
private final CrashlyticsFileMarker crashMarker;
@@ -611,6 +618,56 @@ List<File> listAppExceptionMarkerFiles() {
611618
return fileStore.getCommonFiles(APP_EXCEPTION_MARKER_FILTER);
612619
}
613620

621+
void saveVersionControlInfo() {
622+
try {
623+
String versionControlInfo = getVersionControlInfo();
624+
if (versionControlInfo != null) {
625+
setInternalKey(VERSION_CONTROL_INFO_KEY, versionControlInfo);
626+
Logger.getLogger().i("Saved version control info");
627+
}
628+
} catch (IOException e) {
629+
Logger.getLogger().w("Unable to save version control info", e);
630+
}
631+
}
632+
633+
String getVersionControlInfo() throws IOException {
634+
InputStream is = getResourceAsStream(META_INF_FOLDER + VERSION_CONTROL_INFO_FILE);
635+
if (is == null) {
636+
return null;
637+
}
638+
639+
Logger.getLogger().d("Read version control info");
640+
return Base64.encodeToString(readResource(is), 0);
641+
}
642+
643+
private InputStream getResourceAsStream(String resource) {
644+
ClassLoader classLoader = this.getClass().getClassLoader();
645+
if (classLoader == null) {
646+
Logger.getLogger().w("Couldn't get Class Loader");
647+
return null;
648+
}
649+
650+
InputStream is = classLoader.getResourceAsStream(resource);
651+
if (is == null) {
652+
Logger.getLogger().i("No version control information found");
653+
return null;
654+
}
655+
656+
return is;
657+
}
658+
659+
private static byte[] readResource(InputStream is) throws IOException {
660+
ByteArrayOutputStream out = new ByteArrayOutputStream();
661+
byte[] buffer = new byte[1024];
662+
int length;
663+
664+
while ((length = is.read(buffer)) != -1) {
665+
out.write(buffer, 0, length);
666+
}
667+
668+
return out.toByteArray();
669+
}
670+
614671
private void finalizePreviousNativeSession(String previousSessionId) {
615672
Logger.getLogger().v("Finalizing native report for session " + previousSessionId);
616673
NativeSessionFileProvider nativeSessionFileProvider =

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsCore.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ private Task<Void> doBackgroundInitialization(SettingsProvider settingsProvider)
227227
try {
228228
breadcrumbSource.registerBreadcrumbHandler(this::log);
229229

230+
controller.saveVersionControlInfo();
231+
230232
final Settings settingsData = settingsProvider.getSettingsSync();
231233

232234
if (!settingsData.featureFlagData.collectReports) {

firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/MainActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ package com.google.firebase.testing.sessions
1919
import android.os.Bundle
2020
import android.widget.TextView
2121
import androidx.appcompat.app.AppCompatActivity
22+
import com.google.firebase.sessions.FirebaseSessions
2223

2324
class MainActivity : AppCompatActivity() {
2425
override fun onCreate(savedInstanceState: Bundle?) {
2526
super.onCreate(savedInstanceState)
2627
setContentView(R.layout.activity_main)
2728

28-
findViewById<TextView>(R.id.greeting_text).text = getString(R.string.firebase_greetings)
29+
findViewById<TextView>(R.id.greeting_text).text = FirebaseSessions.instance.greeting()
2930
}
3031
}

firebase-sessions/test-app/test-app.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
plugins {
1818
id("com.android.application")
1919
id("org.jetbrains.kotlin.android")
20+
id("com.google.gms.google-services")
2021
}
2122

2223
android {
@@ -47,5 +48,5 @@ dependencies {
4748
implementation("com.google.android.material:material:1.8.0")
4849
}
4950

50-
extra["packageName"] = "com.google.firebase.testing.sessions"
51-
apply(from = "../../gradle/googleServices.gradle")
51+
// extra["packageName"] = "com.google.firebase.testing.sessions"
52+
// apply(from = "../../gradle/googleServices.gradle")

firebase-storage/firebase-storage.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ dependencies {
102102
testImplementation "com.google.truth:truth:$googleTruthVersion"
103103
testImplementation 'androidx.test:rules:1.2.0'
104104
testImplementation 'androidx.test:core:1.2.0'
105-
testImplementation project(':appcheck:firebase-appcheck')
105+
testImplementation 'com.google.firebase:firebase-appcheck:16.1.1'
106106
}
107107

108108
// ==========================================================================

0 commit comments

Comments
 (0)