Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cronet_http] Enables CI for cronet_http_embedded #1070

Merged
merged 21 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 25 additions & 26 deletions .github/workflows/cronet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ on:
- main
- master
paths:
- '.github/workflows/**'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe only trigger on changes to this file? So updating the monorepo spec doesn't trigger a 20 minute presubmit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure. Will update these in another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already updated this.

- 'pkgs/cronet_http/**'
- 'pkgs/http_client_conformance_tests/**'
pull_request:
paths:
- '.github/workflows/**'
- 'pkgs/cronet_http/**'
- 'pkgs/http_client_conformance_tests/**'
schedule:
Expand All @@ -19,48 +21,45 @@ env:
PUB_ENVIRONMENT: bot.github

jobs:
analyze:
name: Lint and static analysis
runs-on: ubuntu-latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this to macos? I think that there is more linux machine availability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are unknown timeouts when running on the Ubuntu runner. https://github.com/dart-lang/http/actions/runs/7270023551/job/19808487300?pr=1070

defaults:
run:
working-directory: pkgs/cronet_http
verify:
name: Format & Analyze & Test
runs-on: macos-latest
strategy:
matrix:
package: ['cronet_http', 'cronet_http_embedded']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
# TODO: Change to 'stable' when a release version of flutter
# pins version 1.21.1 or later of 'package:test'
channel: 'master'
channel: 'stable'
- name: Make cronet_http_embedded copy
if: ${{ matrix.package == 'cronet_http_embedded' }}
run: |
cp -r pkgs/cronet_http pkgs/cronet_http_embedded
cd pkgs/cronet_http_embedded
flutter pub get && dart tool/prepare_for_embedded.dart
- id: install
name: Install dependencies
working-directory: 'pkgs/${{ matrix.package }}'
run: flutter pub get
- name: Check formatting
working-directory: 'pkgs/${{ matrix.package }}'
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
working-directory: 'pkgs/${{ matrix.package }}'
run: flutter analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

test:
# Test package:cupertino_http use flutter integration tests.
needs: analyze
name: "Build and test"
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- name: Run tests
uses: reactivecircus/android-emulator-runner@v2
if: always() && steps.install.outcome == 'success'
with:
api-level: 28
target: playstore
target: ${{ matrix.package == 'cronet_http_embedded' && 'default' || 'playstore' }}
arch: x86_64
profile: pixel
script: cd ./pkgs/cronet_http/example && flutter test --timeout=1200s integration_test/
script: cd 'pkgs/${{ matrix.package }}/example' && flutter test --timeout=1200s integration_test/
11 changes: 8 additions & 3 deletions pkgs/cronet_http/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'io.flutter.plugins.cronet_http'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.7.21'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these types of upgrades should be done in a separate PR, no?

Copy link
Contributor Author

@AlexV525 AlexV525 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to reorg workflows and examples for the repo in further separate PRs. These are necessary for the current setup. 1.6.10 is already outdated for the latest Flutter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, feel free to set these to any reasonable values.

repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -25,6 +25,11 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
// Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) {
namespace 'io.flutter.plugins.cronet_http'
}

compileSdkVersion 31

compileOptions {
Expand All @@ -41,7 +46,7 @@ android {
}

defaultConfig {
minSdkVersion 16
minSdkVersion 19
}

defaultConfig {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/cronet_http/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ android {
applicationId "io.flutter.cronet_http_example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cronet_http_example">
package="io.flutter.cronet_http_example">
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cronet_http_example">
package="io.flutter.cronet_http_example">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="cronet_http_example"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@
public final class GeneratedPluginRegistrant {
private static final String TAG = "GeneratedPluginRegistrant";
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
try {
flutterEngine.getPlugins().add(new io.flutter.plugins.cronet_http.CronetHttpPlugin());
} catch(Exception e) {
Log.e(TAG, "Error registering plugin cronet_http, io.flutter.plugins.cronet_http.CronetHttpPlugin", e);
}
try {
flutterEngine.getPlugins().add(new dev.flutter.plugins.integration_test.IntegrationTestPlugin());
} catch(Exception e) {
} catch (Exception e) {
Log.e(TAG, "Error registering plugin integration_test, dev.flutter.plugins.integration_test.IntegrationTestPlugin", e);
}
try {
flutterEngine.getPlugins().add(new com.github.dart_lang.jni.JniPlugin());
} catch (Exception e) {
Log.e(TAG, "Error registering plugin jni, com.github.dart_lang.jni.JniPlugin", e);
}
try {
flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
} catch (Exception e) {
Log.e(TAG, "Error registering plugin path_provider_android, io.flutter.plugins.pathprovider.PathProviderPlugin", e);
}
try {
flutterEngine.getPlugins().add(new com.tekartik.sqflite.SqflitePlugin());
} catch (Exception e) {
Log.e(TAG, "Error registering plugin sqflite, com.tekartik.sqflite.SqflitePlugin", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.cronet_http_example
package io.flutter.cronet_http_example

import io.flutter.embedding.android.FlutterActivity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cronet_http_example">
package="io.flutter.cronet_http_example">
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
6 changes: 3 additions & 3 deletions pkgs/cronet_http/example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.7.21'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
42 changes: 38 additions & 4 deletions pkgs/cronet_http/tool/prepare_for_embedded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ final _cronetVersionUri = Uri.https(
'android/maven2/org/chromium/net/group-index.xml',
);

void main() async {
/// Runs `prepare_for_embedded.dart publish` for publishing,
/// or only the Android dependency will be modified.
void main(List<String> args) async {
if (Directory.current.path.endsWith('tool')) {
_packageDirectory = Directory.current.parent;
} else {
Expand All @@ -51,6 +53,8 @@ void main() async {
updateCronetDependency(latestVersion);
updatePubSpec();
updateReadme();
updateImports();
updateEntryPoint();
}

Future<String> _getLatestCronetVersion() async {
Expand All @@ -69,7 +73,7 @@ Future<String> _getLatestCronetVersion() async {
return versions.last;
}

/// Update android/build.gradle
/// Update android/build.gradle.
void updateCronetDependency(String latestVersion) {
final fBuildGradle = File('${_packageDirectory.path}/android/build.gradle');
final gradleContent = fBuildGradle.readAsStringSync();
Expand All @@ -88,18 +92,48 @@ void updateCronetDependency(String latestVersion) {
fBuildGradle.writeAsStringSync(newGradleContent);
}

/// Update pubspec.yaml
/// Update pubspec.yaml and example/pubspec.yaml.
void updatePubSpec() {
print('Updating pubspec.yaml');
final fPubspec = File('${_packageDirectory.path}/pubspec.yaml');
final yamlEditor = YamlEditor(fPubspec.readAsStringSync())
..update(['name'], _packageName)
..update(['description'], _packageDescription);
fPubspec.writeAsStringSync(yamlEditor.toString());
print('Updating example/pubspec.yaml');
final examplePubspec = File('${_packageDirectory.path}/example/pubspec.yaml');
final replaced = examplePubspec
.readAsStringSync()
.replaceAll('cronet_http:', 'cronet_http_embedded:');
examplePubspec.writeAsStringSync(replaced);
}

/// Move README_EMBEDDED.md to replace README.md
/// Move README_EMBEDDED.md to replace README.md.
void updateReadme() {
print('Updating README.md from README_EMBEDDED.md');
File('${_packageDirectory.path}/README.md').deleteSync();
File('${_packageDirectory.path}/README_EMBEDDED.md')
.renameSync('${_packageDirectory.path}/README.md');
}

void updateImports() {
print('Updating imports in Dart files');
for (final file in _packageDirectory.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.dart')) {
final updatedSource = file.readAsStringSync().replaceAll(
'package:cronet_http/cronet_http.dart',
'package:cronet_http_embedded/cronet_http_embedded.dart',
);
file.writeAsStringSync(updatedSource);
}
}
}

void updateEntryPoint() {
print('Renaming cronet_http.dart to cronet_http_embedded.dart');
File(
'${_packageDirectory.path}/lib/cronet_http.dart',
).renameSync(
'${_packageDirectory.path}/lib/cronet_http_embedded.dart',
);
}