|
| 1 | +name: Build & Test Pull Requests UI Tests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + end-to-end-tests: |
| 10 | + runs-on: ${{ matrix.os }} |
| 11 | + strategy: |
| 12 | + matrix: |
| 13 | + platform: [android] #, ios, windows] |
| 14 | + include: |
| 15 | + - platform: android |
| 16 | + os: ubuntu-latest |
| 17 | + - platform: ios |
| 18 | + os: macos-latest |
| 19 | + - platform: windows |
| 20 | + os: windows-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + ############################## |
| 27 | + # Setup .NET and Dependencies |
| 28 | + ############################## |
| 29 | + - name: Set up .NET |
| 30 | + uses: actions/setup-dotnet@v3 |
| 31 | + with: |
| 32 | + dotnet-version: 8.0.x |
| 33 | + |
| 34 | + - name: Install MAUI Workloads for Android |
| 35 | + if: matrix.platform == 'android' |
| 36 | + run: dotnet workload install android --ignore-failed-sources |
| 37 | + |
| 38 | + - name: Install MAUI Workloads for iOS |
| 39 | + if: matrix.platform == 'ios' |
| 40 | + run: dotnet workload install maui --ignore-failed-sources |
| 41 | + |
| 42 | + - name: Install MAUI Workloads for Windows |
| 43 | + if: matrix.platform == 'windows' |
| 44 | + run: dotnet workload install maui --ignore-failed-sources |
| 45 | + |
| 46 | + ########################### |
| 47 | + # 🐳 Start Backend System (Docker) |
| 48 | + ########################### |
| 49 | + - name: Install Docker Desktop (macOS only) |
| 50 | + if: runner.os == 'macOS' |
| 51 | + run: | |
| 52 | + brew install docker |
| 53 | + # Install Docker daemon (Docker CLI can work with a running daemon) |
| 54 | + brew install --cask colima # Colima is a lightweight Docker alternative |
| 55 | + colima start # Start Colima which runs the Docker daemon |
| 56 | + # Wait for Docker to initialize |
| 57 | + sleep 30 # Wait for Docker to be ready |
| 58 | + docker info || (echo "Docker is not running" && exit 1) |
| 59 | +
|
| 60 | + - name: Set up Docker (Ubuntu) |
| 61 | + if: runner.os == 'Linux' |
| 62 | + run: | |
| 63 | + #sudo apt-get purge -y containerd.io |
| 64 | +
|
| 65 | + # Update package information and install Docker |
| 66 | + #sudo apt-get update |
| 67 | + #sudo apt-get install -y docker.io |
| 68 | +
|
| 69 | + # Enable Docker service to start on boot (in case it's required) |
| 70 | + #sudo systemctl enable --now docker |
| 71 | +
|
| 72 | + # Check Docker version to ensure it's installed properly |
| 73 | + docker --version |
| 74 | + docker info |
| 75 | +
|
| 76 | + # Allow current user to access Docker without sudo (optional, for convenience) |
| 77 | + sudo usermod -aG docker $USER |
| 78 | +
|
| 79 | + # Restart Docker service to apply changes |
| 80 | + sudo systemctl restart docker |
| 81 | +
|
| 82 | + ########################### |
| 83 | + # 🛠 Install Appium & Drivers |
| 84 | + ########################### |
| 85 | + - name: Install Node.js |
| 86 | + uses: actions/setup-node@v3 |
| 87 | + with: |
| 88 | + node-version: 18 |
| 89 | + |
| 90 | + - name: Install Appium and Drivers |
| 91 | + run: | |
| 92 | + npm install -g appium |
| 93 | + appium driver install uiautomator2 |
| 94 | + appium driver install xcuitest |
| 95 | + appium driver install windows |
| 96 | +
|
| 97 | + - name: Start Appium Server |
| 98 | + run: | |
| 99 | + nohup appium --log appium.log & |
| 100 | +
|
| 101 | + ############################## |
| 102 | + # 🟢 Android: Start Emulator |
| 103 | + ############################## |
| 104 | + - name: Install Android SDK & Start Emulator (Linux) |
| 105 | + if: matrix.platform == 'android' |
| 106 | + run: | |
| 107 | + # Install dependencies |
| 108 | + sudo apt-get update |
| 109 | + sudo apt-get install -y unzip wget libglu1-mesa |
| 110 | +
|
| 111 | + # Set up Android SDK directory |
| 112 | + export ANDROID_HOME=$HOME/android-sdk |
| 113 | + export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH |
| 114 | + mkdir -p $ANDROID_HOME/cmdline-tools |
| 115 | +
|
| 116 | + # Download and install Android command-line tools |
| 117 | + wget -q https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O cmdline-tools.zip |
| 118 | + unzip -q cmdline-tools.zip -d $ANDROID_HOME/cmdline-tools |
| 119 | + rm cmdline-tools.zip |
| 120 | + mv $ANDROID_HOME/cmdline-tools/cmdline-tools $ANDROID_HOME/cmdline-tools/latest |
| 121 | +
|
| 122 | + # Accept licenses |
| 123 | + yes | sdkmanager --licenses || true |
| 124 | +
|
| 125 | + # Install required Android SDK packages |
| 126 | + sdkmanager --sdk_root=$ANDROID_HOME --install "platform-tools" "emulator" "system-images;android-31;google_apis;x86_64" |
| 127 | +
|
| 128 | + # Verify installation |
| 129 | + sdkmanager --list | grep "system-images;android-31;google_apis;x86_64" |
| 130 | +
|
| 131 | + # Create and start emulator |
| 132 | + echo "no" | avdmanager create avd -n testEmulator -k "system-images;android-31;google_apis;x86_64" --device "pixel_4" |
| 133 | +
|
| 134 | + echo "⏳ Pausing for 10 seconds to ensure AVD registration..." |
| 135 | + sleep 30 |
| 136 | +
|
| 137 | + # Start the emulator in the background |
| 138 | + nohup emulator -avd testEmulator -no-window -no-audio -gpu swiftshader_indirect -no-snapshot -no-boot-anim & |
| 139 | +
|
| 140 | + # Wait up to 5 minutes (300 seconds) for the emulator to be ready |
| 141 | + timeout=300 |
| 142 | + while [[ $timeout -gt 0 ]]; do |
| 143 | + boot_status=$(adb shell getprop sys.boot_completed 2>&1) |
| 144 | + echo "Waiting for emulator... Boot status: $boot_status" |
| 145 | + if [[ "$boot_status" == "1" ]]; then |
| 146 | + echo "✅ Emulator booted successfully!" |
| 147 | + exit 0 |
| 148 | + fi |
| 149 | + sleep 5 |
| 150 | + ((timeout -= 5)) |
| 151 | + done |
| 152 | +
|
| 153 | + echo "❌ Emulator failed to boot within timeout!" |
| 154 | + exit 1 |
| 155 | +
|
| 156 | +
|
| 157 | + ############################## |
| 158 | + # 🍏 iOS: Start Simulator |
| 159 | + ############################## |
| 160 | + - name: Start iOS Simulator |
| 161 | + if: matrix.platform == 'ios' |
| 162 | + run: | |
| 163 | + open -a Simulator & |
| 164 | + xcrun simctl list |
| 165 | + xcrun simctl boot "iPhone 14" |
| 166 | + xcrun simctl list devices |
| 167 | +
|
| 168 | + ############################## |
| 169 | + # 🔨 Build .NET MAUI App |
| 170 | + ############################## |
| 171 | + - name: Build MAUI App for Android |
| 172 | + if: matrix.platform == 'android' |
| 173 | + run: dotnet build TransactionMobile.Maui/TransactionMobile.Maui.csproj -f net8.0-android -c Release --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json |
| 174 | + |
| 175 | + - name: Build MAUI App for iOS |
| 176 | + if: matrix.platform == 'ios' |
| 177 | + run: dotnet build TransactionMobile.Maui/TransactionMobile.Maui.csproj -f net8.0-ios -c Release --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json |
| 178 | + |
| 179 | + - name: Build MAUI App for Windows |
| 180 | + if: matrix.platform == 'windows' |
| 181 | + run: dotnet build TransactionMobile.Maui/TransactionMobile.Maui.csproj -f net8.0-windows -c Release --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json |
| 182 | + |
| 183 | + ############################## |
| 184 | + # 🚀 Run Appium UI Tests |
| 185 | + ############################## |
| 186 | + - name: Run Appium Tests (Android) |
| 187 | + if: matrix.platform == 'android' |
| 188 | + run: dotnet test TransactionMobile.Maui.UiTests/TransactionMobile.Maui.UiTests.csproj --filter (Category=PRTest)&(Category=Android) |
| 189 | + |
| 190 | + - name: Run Appium Tests (iOS) |
| 191 | + if: matrix.platform == 'ios' |
| 192 | + run: dotnet test TransactionMobile.Maui.UiTests/TransactionMobile.Maui.UiTests.csproj --filter (Category=PRTest)&(Category=iOS) |
| 193 | + |
| 194 | + - name: Run Appium Tests (Windows) |
| 195 | + if: matrix.platform == 'windows' |
| 196 | + run: dotnet test TransactionMobile.Maui.UiTests/TransactionMobile.Maui.UiTests.csproj --filter "Category=PRTest&Category=Windows" |
| 197 | + |
| 198 | + ############################## |
| 199 | + # 📤 Upload Logs if Tests Fail |
| 200 | + ############################## |
| 201 | + - name: Upload logs if tests fail |
| 202 | + if: failure() |
| 203 | + uses: actions/upload-artifact@v4 |
| 204 | + with: |
| 205 | + name: appium-logs-${{ matrix.test-type }} |
| 206 | + path: artifacts/appium-logs-${{ matrix.test-type }}.log |
0 commit comments