diff --git a/.github/workflow-scripts/okhttp3-compat.gradle b/.github/workflow-scripts/okhttp3-compat.gradle new file mode 100644 index 000000000000..e6c576c1ed21 --- /dev/null +++ b/.github/workflow-scripts/okhttp3-compat.gradle @@ -0,0 +1,53 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import org.gradle.api.GradleException +import org.gradle.api.artifacts.component.ModuleComponentIdentifier + +// Keep the normal build on the version in the catalog. This init script is only +// used by the compatibility job, so its compile and test classpaths use OkHttp 3. +// This catches new OkHttp 4-only calls before they need reverting (e.g. #60318). +gradle.beforeProject { project -> + if (project.path != ':packages:react-native:ReactAndroid') { + return + } + + def okhttpVersion = '3.14.9' + project.configurations.configureEach { configuration -> + configuration.resolutionStrategy.eachDependency { details -> + if (details.requested.group == 'com.squareup.okhttp3') { + details.useVersion(okhttpVersion) + details.because('Check ReactAndroid source compatibility with OkHttp 3') + } + } + } + + project.plugins.withId('com.android.library') { + project.tasks.register('verifyOkHttp3Compatibility') { task -> + task.group = 'verification' + task.description = 'Compiles and tests ReactAndroid against OkHttp 3.14.9.' + task.dependsOn('testDebugUnitTest') + task.doLast { + [ + 'debugCompileClasspath', + 'debugRuntimeClasspath', + 'debugUnitTestCompileClasspath', + 'debugUnitTestRuntimeClasspath', + ].each { name -> + def configuration = project.configurations.getByName(name) + def modules = configuration.incoming.resolutionResult.allComponents + .collect { it.id } + .findAll { it instanceof ModuleComponentIdentifier && it.group == 'com.squareup.okhttp3' } + if (modules.isEmpty() || modules.any { it.version != okhttpVersion }) { + throw new GradleException("Expected OkHttp ${okhttpVersion} on ${project.path}:${name}, found: ${modules}") + } + project.logger.lifecycle("Verified ${project.path}:${name}: ${modules}") + } + } + } + } +} diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml index 34515e6e5a07..825887470456 100644 --- a/.github/workflows/test-all.yml +++ b/.github/workflows/test-all.yml @@ -399,6 +399,41 @@ jobs: release-type: dry-run gradle-cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }} + test_android_okhttp3: + runs-on: 8-core-ubuntu + needs: check_code_changes + if: | + needs.check_code_changes.outputs.any_code_change == 'true' && + needs.check_code_changes.outputs.should_test_android == 'true' + container: + image: reactnativecommunity/react-native-android:latest + env: + LC_ALL: C.UTF8 + TERM: 'dumb' + GRADLE_OPTS: '-Dorg.gradle.daemon=false' + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Setup node.js + uses: ./.github/actions/setup-node + - name: Install node dependencies + uses: ./.github/actions/yarn-install + - name: Setup gradle + uses: ./.github/actions/setup-gradle + with: + cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }} + - name: Compile and test ReactAndroid with OkHttp 3.14.9 + run: | + ./gradlew --init-script .github/workflow-scripts/okhttp3-compat.gradle \ + :packages:react-native:ReactAndroid:verifyOkHttp3Compatibility + - name: Upload test results + if: ${{ always() }} + uses: ./.github/actions/upload-artifact + with: + name: android-okhttp3-results + path: packages/react-native/ReactAndroid/build/reports/tests/testDebugUnitTest/ + if-no-files-found: ignore + test_e2e_android_rntester: needs: build_android if: ${{ needs.build_android.result == 'success' }}