diff --git a/tools/ci_build/github/azure-pipelines/stages/jobs/react-natvie-andriod-e2e-test-job.yml b/tools/ci_build/github/azure-pipelines/stages/jobs/react-natvie-andriod-e2e-test-job.yml new file mode 100644 index 0000000000000..5a060a8fcd4fa --- /dev/null +++ b/tools/ci_build/github/azure-pipelines/stages/jobs/react-natvie-andriod-e2e-test-job.yml @@ -0,0 +1,211 @@ +parameters: +- name: PackageName + displayName: 'Package name' + type: string + default: 'NPM_packages' + +- name: ArtifactName + type: string + default: 'onnxruntime-android-full-aar' + +- name: NpmPackagingMode + displayName: 'NPM packages publish configuration' + type: string + default: 'dev' + +jobs: +- job: ReactNative_CI_Android + pool: 'onnxruntime-Ubuntu2204-AMD-CPU' + variables: + runCodesignValidationInjection: false + timeoutInMinutes: 90 + steps: + - task: UsePythonVersion@0 + displayName: Use python 3.12 + inputs: + versionSpec: "3.12" + addToPath: true + architecture: "x64" + + - task: JavaToolInstaller@0 + displayName: Use jdk 17 + inputs: + versionSpec: '17' + jdkArchitectureOption: 'x64' + jdkSourceOption: 'PreInstalled' + + - task: NodeTool@0 + inputs: + versionSpec: '20.x' + + - script: | + sudo apt install coreutils ninja-build nodejs npm yarn + npm install --global yarn + displayName: Install coreutils, ninja, npm, and yarn + + - task: DownloadPipelineArtifact@2 + inputs: + buildType: 'current' + artifactName: '${{parameters.ArtifactName}}' + targetPath: '$(Build.BinariesDirectory)/android-full-aar' + displayName: Download Android AAR artifacts + + - task: CopyFiles@2 + inputs: + sourceFolder: $(Build.BinariesDirectory)/android-full-aar + contents: onnxruntime-android-*.aar + targetFolder: $(Build.SourcesDirectory)/js/react_native/android/libs + displayName: Copy Android package to React Native directory + + - script: | + npm ci + workingDirectory: '$(Build.SourcesDirectory)/js' + displayName: npm ci js + + - script: | + npm ci + workingDirectory: '$(Build.SourcesDirectory)/js/common' + displayName: npm ci js/common + + - script: | + yarn + workingDirectory: '$(Build.SourcesDirectory)/js/react_native' + displayName: yarn js/react_native + + - task: PowerShell@2 + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/js/pack-npm-packages.ps1' + arguments: '"-dev.$(Get-Date -Format yyyyMMdd)-$(git rev-parse --short HEAD)" $(Build.SourcesDirectory) react_native' + workingDirectory: '$(Build.SourcesDirectory)' + errorActionPreference: stop + env: + ORT_JS_PACK_MODE: e2e + displayName: Pack NPM packages + + - script: | + mv $(Build.SourcesDirectory)/js/common/onnxruntime-common*.tgz onnxruntime-common.tgz + yarn add --no-lockfile file:./onnxruntime-common.tgz + mv $(Build.SourcesDirectory)/js/react_native/onnxruntime-react-native*.tgz onnxruntime-react-native.tgz + yarn add --no-lockfile file:./onnxruntime-react-native.tgz + yarn + workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e' + displayName: Bootstrap Android and iOS e2e tests + + - script: | + yarn add --dev jest-junit + workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e' + displayName: install jest junit reporter js/react_native/e2e + + - script: | + keytool -genkey -v -keystore debug.keystore -alias androiddebugkey -storepass android \ + -keypass android -keyalg RSA -keysize 2048 -validity 999999 -dname "CN=Android Debug,O=Android,C=US" + workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e/android' + displayName: Generate a debug keystore + + - task: CopyFiles@2 + inputs: + sourceFolder: $(Build.BinariesDirectory)/android-full-aar + contents: onnxruntime-*.aar + targetFolder: $(Build.SourcesDirectory)/js/react_native/e2e/android/app/libs + displayName: Copy Android package to Android e2e test directory + + - script: | + yarn global add detox-cli + echo "Path: $PATH" + echo "##vso[task.prependpath]$(yarn global bin)" + echo "Updated PATH: $PATH" + echo "Detox bin directory: $(yarn global bin)" + ls $(yarn global bin) + displayName: Install detox cli tools and prepend to PATH + + - script: | + detox build --configuration android.emu.release + workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e' + displayName: Build React Native Detox Android e2e Tests + + # + # Unit tests and E2E tests with Android emulator + # + - template: ../../templates/use-android-emulator.yml + parameters: + create: true + start: true + + - template: ../../templates/android-dump-logs-from-steps.yml + parameters: + steps: + - task: Gradle@3 + inputs: + gradleWrapperFile: '$(Build.SourcesDirectory)/js/react_native/android/gradlew' + workingDirectory: '$(Build.SourcesDirectory)/js/react_native/android' + options: '--stacktrace' + tasks: 'connectedDebugAndroidTest' + publishJUnitResults: true + testResultsFiles: '**/TEST-*.xml' + testRunTitle: 'React Native Android Instrumented Test results' + sonarQubeRunAnalysis: false + spotBugsAnalysis: false + displayName: Run React Native Android Instrumented Tests + + - script: | + JEST_JUNIT_OUTPUT_FILE=$(Build.SourcesDirectory)/js/react_native/e2e/android-test-results.xml \ + detox test --record-logs all \ + --configuration android.emu.release \ + --loglevel trace \ + --take-screenshots failing + workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e' + displayName: Run React Native Detox Android e2e Tests + + - template: ../../templates/use-android-emulator.yml + parameters: + stop: true + + - task: PublishTestResults@2 + inputs: + testResultsFiles: '$(Build.SourcesDirectory)/js/react_native/e2e/android-test-results.xml' + failTaskOnFailedTests: true + testRunTitle: 'React Native Detox Android e2e Test Results' + condition: succeededOrFailed() + displayName: Publish React Native Detox Android e2e Test Results + + - script: | + git restore . + workingDirectory: '$(Build.SourcesDirectory)/js' + displayName: Restore git changes + + - task: PowerShell@2 + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/js/pack-npm-packages.ps1' + arguments: '"${{parameters.NpmPackagingMode}}" $(Build.SourcesDirectory) react_native' + workingDirectory: '$(Build.SourcesDirectory)' + errorActionPreference: stop + displayName: Pack NPM packages + + - task: CopyFiles@2 + inputs: + sourceFolder: $(Build.SourcesDirectory)/js/common + contents: onnxruntime-common*.tgz + targetFolder: $(Build.ArtifactStagingDirectory) + displayName: 'Create Artifacts onnxruntime-common' + + - task: CopyFiles@2 + inputs: + sourceFolder: $(Build.SourcesDirectory)/js/react_native + contents: onnxruntime-react-native*.tgz + targetFolder: $(Build.ArtifactStagingDirectory) + displayName: Create Artifacts onnxruntime-react-native + + - task: PublishPipelineArtifact@1 + inputs: + artifact: android_e2e_test_logs_$(Build.BuildId)_$(Build.BuildNumber)_$(System.JobAttempt) + targetPath: '$(Build.SourcesDirectory)/js/react_native/e2e/artifacts' + condition: succeededOrFailed() + displayName: Publish React Native Detox E2E test logs + + - task: PublishPipelineArtifact@0 + inputs: + artifactName: '${{parameters.PackageName}}' + targetPath: '$(Build.ArtifactStagingDirectory)' + displayName: Publish Pipeline Artifact + + - template: ../../templates/explicitly-defined-final-tasks.yml \ No newline at end of file diff --git a/tools/ci_build/github/azure-pipelines/templates/react-native-ci.yml b/tools/ci_build/github/azure-pipelines/templates/react-native-ci.yml index b412b7e43affe..b46fae79899e2 100644 --- a/tools/ci_build/github/azure-pipelines/templates/react-native-ci.yml +++ b/tools/ci_build/github/azure-pipelines/templates/react-native-ci.yml @@ -44,203 +44,13 @@ stages: packageName: 'onnxruntime-android' - stage: ReactNative_CI_Android displayName: ReactNative_CI_Android - dependsOn: - - Build_Android_Packages + dependsOn: Build_Android_Packages jobs: - - job: ReactNative_CI_Android - pool: - vmImage: 'macOS-13' - variables: - runCodesignValidationInjection: false - timeoutInMinutes: 90 - steps: - - task: UsePythonVersion@0 - displayName: Use python 3.12 - inputs: - versionSpec: "3.12" - addToPath: true - architecture: "x64" - - - task: JavaToolInstaller@0 - displayName: Use jdk 17 - inputs: - versionSpec: '17' - jdkArchitectureOption: 'x64' - jdkSourceOption: 'PreInstalled' - - - task: NodeTool@0 - inputs: - versionSpec: '20.x' - - - script: - brew install coreutils ninja npm yarn - displayName: Install coreutils, ninja, npm, and yarn - - - script: - yarn global add detox-cli - displayName: Install detox cli tools - - - script: - brew tap wix/brew - displayName: brew tap wix/brew - - - task: DownloadPipelineArtifact@2 - inputs: - buildType: 'current' - artifactName: 'onnxruntime-android-full-aar' - targetPath: '$(Build.BinariesDirectory)/android-full-aar' - displayName: Download Android AAR artifacts - - - task: CopyFiles@2 - inputs: - sourceFolder: $(Build.BinariesDirectory)/android-full-aar - contents: onnxruntime-android-*.aar - targetFolder: $(Build.SourcesDirectory)/js/react_native/android/libs - displayName: Copy Android package to React Native directory - - - script: | - npm ci - workingDirectory: '$(Build.SourcesDirectory)/js' - displayName: npm ci js - - - script: | - npm ci - workingDirectory: '$(Build.SourcesDirectory)/js/common' - displayName: npm ci js/common - - - script: | - yarn - workingDirectory: '$(Build.SourcesDirectory)/js/react_native' - displayName: yarn js/react_native - - - task: PowerShell@2 - inputs: - filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/js/pack-npm-packages.ps1' - arguments: '"-dev.$(Get-Date -Format yyyyMMdd)-$(git rev-parse --short HEAD)" $(Build.SourcesDirectory) react_native' - workingDirectory: '$(Build.SourcesDirectory)' - errorActionPreference: stop - env: - ORT_JS_PACK_MODE: e2e - displayName: Pack NPM packages - - - script: | - mv $(Build.SourcesDirectory)/js/common/onnxruntime-common*.tgz onnxruntime-common.tgz - yarn add --no-lockfile file:./onnxruntime-common.tgz - mv $(Build.SourcesDirectory)/js/react_native/onnxruntime-react-native*.tgz onnxruntime-react-native.tgz - yarn add --no-lockfile file:./onnxruntime-react-native.tgz - yarn - workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e' - displayName: Bootstrap Android and iOS e2e tests - - - script: | - yarn add --dev jest-junit - workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e' - displayName: install jest junit reporter js/react_native/e2e - - - script: | - keytool -genkey -v -keystore debug.keystore -alias androiddebugkey -storepass android \ - -keypass android -keyalg RSA -keysize 2048 -validity 999999 -dname "CN=Android Debug,O=Android,C=US" - workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e/android' - displayName: Generate a debug keystore - - - task: CopyFiles@2 - inputs: - sourceFolder: $(Build.BinariesDirectory)/android-full-aar - contents: onnxruntime-*.aar - targetFolder: $(Build.SourcesDirectory)/js/react_native/e2e/android/app/libs - displayName: Copy Android package to Android e2e test directory - - - script: | - detox build --configuration android.emu.release - workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e' - displayName: Build React Native Detox Android e2e Tests - - # - # Unit tests and E2E tests with Android emulator - # - - template: use-android-emulator.yml - parameters: - create: true - start: true - - - template: android-dump-logs-from-steps.yml - parameters: - steps: - - task: Gradle@3 - inputs: - gradleWrapperFile: '$(Build.SourcesDirectory)/js/react_native/android/gradlew' - workingDirectory: '$(Build.SourcesDirectory)/js/react_native/android' - options: '--stacktrace' - tasks: 'connectedDebugAndroidTest' - publishJUnitResults: true - testResultsFiles: '**/TEST-*.xml' - testRunTitle: 'React Native Android Instrumented Test results' - sonarQubeRunAnalysis: false - spotBugsAnalysis: false - displayName: Run React Native Android Instrumented Tests - - - script: | - JEST_JUNIT_OUTPUT_FILE=$(Build.SourcesDirectory)/js/react_native/e2e/android-test-results.xml \ - detox test --record-logs all \ - --configuration android.emu.release \ - --loglevel trace \ - --take-screenshots failing - workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e' - displayName: Run React Native Detox Android e2e Tests - - - template: use-android-emulator.yml - parameters: - stop: true - - - task: PublishTestResults@2 - inputs: - testResultsFiles: '$(Build.SourcesDirectory)/js/react_native/e2e/android-test-results.xml' - failTaskOnFailedTests: true - testRunTitle: 'React Native Detox Android e2e Test Results' - condition: succeededOrFailed() - displayName: Publish React Native Detox Android e2e Test Results - - - script: | - git restore . - workingDirectory: '$(Build.SourcesDirectory)/js' - displayName: Restore git changes - - - task: PowerShell@2 - inputs: - filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/js/pack-npm-packages.ps1' - arguments: '"${{parameters.NpmPackagingMode}}" $(Build.SourcesDirectory) react_native' - workingDirectory: '$(Build.SourcesDirectory)' - errorActionPreference: stop - displayName: Pack NPM packages - - - task: CopyFiles@2 - inputs: - sourceFolder: $(Build.SourcesDirectory)/js/common - contents: onnxruntime-common*.tgz - targetFolder: $(Build.ArtifactStagingDirectory) - displayName: 'Create Artifacts onnxruntime-common' - - - task: CopyFiles@2 - inputs: - sourceFolder: $(Build.SourcesDirectory)/js/react_native - contents: onnxruntime-react-native*.tgz - targetFolder: $(Build.ArtifactStagingDirectory) - displayName: Create Artifacts onnxruntime-react-native - - - task: PublishPipelineArtifact@1 - inputs: - artifact: android_e2e_test_logs_$(Build.BuildId)_$(Build.BuildNumber)_$(System.JobAttempt) - targetPath: '$(Build.SourcesDirectory)/js/react_native/e2e/artifacts' - condition: succeededOrFailed() - displayName: Publish React Native Detox E2E test logs - - - task: PublishPipelineArtifact@0 - inputs: - artifactName: '${{parameters.PackageName}}' - targetPath: '$(Build.ArtifactStagingDirectory)' - displayName: Publish Pipeline Artifact - - - template: explicitly-defined-final-tasks.yml + - template: ../stages/jobs/react-natvie-andriod-e2e-test-job.yml + parameters: + PackageName: '${{parameters.PackageName}}' + ArtifactName: 'onnxruntime-android-full-aar' + NpmPackagingMode: '${{parameters.NpmPackagingMode}}' - stage: ReactNative_CI_iOS displayName: ReactNative_CI_iOS @@ -269,7 +79,7 @@ stages: - script: | pip install -r tools/ci_build/github/apple/ios_packaging/requirements.txt displayName: "Install Python requirements" -# Build the iOS package + # Build the iOS package - template: mac-build-step-with-cache.yml parameters: WithCache: true @@ -292,7 +102,7 @@ stages: CCACHE_DEPEND: 1 CCACHE_SLOPPINESS: modules CCACHE_DIR: $(ORT_CACHE_DIR) -# Test the iOS package + # Test the iOS package - task: NodeTool@0 inputs: versionSpec: '20.x' @@ -338,6 +148,7 @@ stages: displayName: Pack NPM packages - script: | + set -x -e mv $(Build.SourcesDirectory)/js/common/onnxruntime-common*.tgz onnxruntime-common.tgz yarn add --no-lockfile file:./onnxruntime-common.tgz mv $(Build.SourcesDirectory)/js/react_native/onnxruntime-react-native*.tgz onnxruntime-react-native.tgz