summaryrefslogtreecommitdiff
path: root/.github/workflows/qatest.yaml
blob: 5d8894a3f4916d6f504868f49581c9a37cbb1e30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
name: Run QA Test # Runs automated tests on self-hosted QA machines

permissions:
  contents: read

on:
  workflow_run:
    workflows: ["Build"]
    types:
      - completed
  workflow_dispatch:
    inputs:
      build_id:
        description: 'Build workflow run ID (e.g. For github.com/secondlife/viewer/actions/runs/1234567890 the ID is 1234567890)'
        required: true
        default: '14806728332'

jobs:
  debug-workflow:
    runs-on: ubuntu-latest
    steps:
      - name: Debug Workflow Variables
        run: |
          echo "Workflow Conclusion: ${{ github.event.workflow_run.conclusion }}"
          echo "Workflow Head Branch: ${{ github.event.workflow_run.head_branch }}"
          echo "Workflow Run ID: ${{ github.event.workflow_run.id }}"
          echo "Head Commit Message: ${{ github.event.workflow_run.head_commit.message }}"
          echo "GitHub Ref: ${{ github.ref }}"
          echo "GitHub Ref Name: ${{ github.ref_name }}"
          echo "GitHub Event Name: ${{ github.event_name }}"
          echo "GitHub Workflow Name: ${{ github.workflow }}"

  install-viewer-and-run-tests:
    concurrency:
      group: ${{ github.workflow }}-${{ matrix.runner }}
      cancel-in-progress: false # Prevents cancellation of in-progress jobs

    strategy:
      matrix:
        include:
          - os: windows
            runner: qa-windows-atlas
            artifact: Windows-installer
            install-path: 'C:\viewer-automation-main'
          - os: windows
            runner: qa-dan-asus
            artifact: Windows-installer
            install-path: 'C:\viewer-automation-main'
          # Commented out until mac runner is available
          # - os: mac
          #   runner: qa-mac-atlas
          #   artifact: Mac-installer
          #   install-path: '$HOME/Documents/viewer-automation'
      fail-fast: false

    runs-on: [self-hosted, "${{ matrix.runner }}"]
    # Run test only on successful builds of Second_Life_X branches or on manual dispatch
    if: >
      (github.event_name == 'workflow_run' &&
      github.event.workflow_run.conclusion == 'success' &&
      startsWith(github.event.workflow_run.head_branch, 'Second_Life')) ||
      github.event_name == 'workflow_dispatch'

    steps:
      # Windows-specific steps
      - name: Set Build ID
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          if ("${{ github.event_name }}" -eq "workflow_dispatch") {
            echo "BUILD_ID=${{ github.event.inputs.build_id }}" | Out-File -FilePath $env:GITHUB_ENV -Append
            echo "ARTIFACTS_URL=https://api.github.com/repos/secondlife/viewer/actions/runs/${{ github.event.inputs.build_id }}/artifacts" | Out-File -FilePath $env:GITHUB_ENV -Append
          } else {
            echo "BUILD_ID=${{ github.event.workflow_run.id }}" | Out-File -FilePath $env:GITHUB_ENV -Append
            echo "ARTIFACTS_URL=https://api.github.com/repos/secondlife/viewer/actions/runs/${{ github.event.workflow_run.id }}/artifacts" | Out-File -FilePath $env:GITHUB_ENV -Append
          }

      - name: Temporarily Allow PowerShell Scripts (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          Set-ExecutionPolicy RemoteSigned -Scope Process -Force

      - name: Verify viewer-automation-main Exists (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          if (-Not (Test-Path -Path '${{ matrix.install-path }}')) {
            Write-Host '❌ Error: viewer-automation folder not found on runner!'
            exit 1
          }
          Write-Host '✅ viewer-automation folder is provided.'

      - name: Verify viewer-automation-main is Up-To-Date (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        continue-on-error: true
        run: |
          cd ${{ matrix.install-path }}
          Write-Host "Checking for repository updates..."

          # Check if .git directory exists
          if (Test-Path -Path ".git") {
            try {
              # Save local changes instead of discarding them
              git stash push -m "Automated stash before update $(Get-Date)"
              Write-Host "Local changes saved (if any)"

              # Update the repository
              git pull
              Write-Host "✅ Repository updated successfully"

              # Try to restore local changes if any were stashed
              $stashList = git stash list
              if ($stashList -match "Automated stash before update") {
                try {
                  git stash pop
                  Write-Host "✅ Local changes restored successfully"
                } catch {
                  Write-Host "⚠️ Conflict when restoring local changes"
                  # Save the conflicted state in a new branch for later review
                  $branchName = "conflict-recovery-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
                  git checkout -b $branchName
                  Write-Host "✅ Created branch '$branchName' with conflicted state"

                  # For test execution, revert to a clean state
                  git reset --hard HEAD
                  Write-Host "✅ Reset to clean state for test execution"
                }
              }
            } catch {
              Write-Host "⚠️ Could not update repository: $_"
              Write-Host "Continuing with existing files..."
            }
          } else {
            Write-Host "⚠️ Not a Git repository, using existing files"
          }

      - name: Verify Python Installation (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          try {
            $pythonVersion = (python --version)
            Write-Host "✅ Python found: $pythonVersion"
          } catch {
            Write-Host "❌ Error: Python not found in PATH. Please install Python on this runner."
            exit 1
          }

      - name: Setup Python Virtual Environment (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
          cd ${{ matrix.install-path }}

          if (-Not (Test-Path -Path ".venv")) {
            Write-Host "Creating virtual environment..."
            python -m venv .venv
          } else {
            Write-Host "Using existing virtual environment"
          }

          # Direct environment activation to avoid script execution issues
          $env:VIRTUAL_ENV = "$PWD\.venv"
          $env:PATH = "$env:VIRTUAL_ENV\Scripts;$env:PATH"

          # Install dependencies
          if (Test-Path -Path "requirements.txt") {
            Write-Host "Installing dependencies from requirements.txt..."
            pip install -r requirements.txt

            # Install Playwright browsers - add this line
            Write-Host "Installing Playwright browsers..."
            python -m playwright install
          } else {
            pip install outleap requests behave playwright
            # Install Playwright browsers - add this line
            Write-Host "Installing Playwright browsers..."
            python -m playwright install
          }

      - name: Fetch & Download Installer Artifact (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          $BUILD_ID = "${{ env.BUILD_ID }}"
          $ARTIFACTS_URL = "${{ env.ARTIFACTS_URL }}"

          # Fetch the correct artifact URL
          $response = Invoke-RestMethod -Headers @{Authorization="token ${{ secrets.GITHUB_TOKEN }}" } -Uri $ARTIFACTS_URL
          $ARTIFACT_NAME = ($response.artifacts | Where-Object { $_.name -eq "${{ matrix.artifact }}" }).archive_download_url

          if (-Not $ARTIFACT_NAME) {
            Write-Host "❌ Error: ${{ matrix.artifact }} artifact not found!"
            exit 1
          }

          Write-Host "✅ Artifact found: $ARTIFACT_NAME"

          # Secure download path
          $DownloadPath = "$env:TEMP\secondlife-build-$BUILD_ID"
          New-Item -ItemType Directory -Path $DownloadPath -Force | Out-Null
          $InstallerPath = "$DownloadPath\installer.zip"

          # Download the ZIP
          Invoke-WebRequest -Uri $ARTIFACT_NAME -Headers @{Authorization="token ${{ secrets.GITHUB_TOKEN }}"} -OutFile $InstallerPath

          # Ensure download succeeded
          if (-Not (Test-Path $InstallerPath)) {
            Write-Host "❌ Error: Failed to download ${{ matrix.artifact }}.zip"
            exit 1
          }

          # Set the path for other steps
          echo "DOWNLOAD_PATH=$DownloadPath" | Out-File -FilePath $env:GITHUB_ENV -Append

      - name: Extract Installer & Locate Executable (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          $BUILD_ID = "${{ env.BUILD_ID }}"
          $ExtractPath = "${{ env.DOWNLOAD_PATH }}"
          $InstallerZip = "$ExtractPath\installer.zip"

          # Print paths for debugging
          Write-Host "Extract Path: $ExtractPath"
          Write-Host "Installer ZIP Path: $InstallerZip"

          # Verify ZIP exists before extracting
          if (-Not (Test-Path $InstallerZip)) {
              Write-Host "❌ Error: ZIP file not found at $InstallerZip!"
              exit 1
          }

          Write-Host "✅ ZIP file exists and is valid. Extracting..."

          Expand-Archive -Path $InstallerZip -DestinationPath $ExtractPath -Force

          # Find installer executable
          $INSTALLER_PATH = (Get-ChildItem -Path $ExtractPath -Filter '*.exe' -Recurse | Select-Object -First 1).FullName

          if (-Not $INSTALLER_PATH -or $INSTALLER_PATH -eq "") {
            Write-Host "❌ Error: No installer executable found in the extracted files!"
            Write-Host "📂 Extracted Files:"
            Get-ChildItem -Path $ExtractPath -Recurse | Format-Table -AutoSize
            exit 1
          }

          Write-Host "✅ Installer found: $INSTALLER_PATH"
          echo "INSTALLER_PATH=$INSTALLER_PATH" | Out-File -FilePath $env:GITHUB_ENV -Append

      - name: Install Second Life (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          # Windows - Use Task Scheduler to bypass UAC
          $action = New-ScheduledTaskAction -Execute "${{ env.INSTALLER_PATH }}" -Argument "/S"
          $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
          $task = New-ScheduledTask -Action $action -Principal $principal
          Register-ScheduledTask -TaskName "SilentSLInstaller" -InputObject $task -Force
          Start-ScheduledTask -TaskName "SilentSLInstaller"

      - name: Wait for Installation to Complete (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          Write-Host "Waiting for the Second Life installer to finish..."
          do {
            Start-Sleep -Seconds 5
            $installerProcess = Get-Process | Where-Object { $_.Path -eq "${{ env.INSTALLER_PATH }}" }
          } while ($installerProcess)

          Write-Host "✅ Installation completed!"

      - name: Cleanup After Installation (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          # Cleanup Task Scheduler Entry
          Unregister-ScheduledTask -TaskName "SilentSLInstaller" -Confirm:$false
          Write-Host "✅ Task Scheduler entry removed."

          # Delete Installer ZIP
          $DeletePath = "${{ env.DOWNLOAD_PATH }}\installer.zip"

          Write-Host "Checking if installer ZIP exists: $DeletePath"

          # Ensure the ZIP file exists before trying to delete it
          if (Test-Path $DeletePath) {
              Remove-Item -Path $DeletePath -Force
              Write-Host "✅ Successfully deleted: $DeletePath"
          } else {
              Write-Host "⚠️ Warning: ZIP file does not exist, skipping deletion."
          }

      - name: Run QA Test Script (Windows)
        if: matrix.os == 'windows'
        shell: pwsh
        run: |
          Write-Host "Running QA Test script on Windows runner: ${{ matrix.runner }}..."
          cd ${{ matrix.install-path }}

          # Activate virtual environment
          Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
          $env:VIRTUAL_ENV = "$PWD\.venv"
          $env:PATH = "$env:VIRTUAL_ENV\Scripts;$env:PATH"

          # Set runner name as environment variable
          $env:RUNNER_NAME = "${{ matrix.runner }}"

          # Run the test script
          python runTests.py

      # Mac-specific steps
      - name: Set Build ID (Mac)
        if: matrix.os == 'mac'
        shell: bash
        run: |
          if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
            echo "BUILD_ID=${{ github.event.inputs.build_id }}" >> $GITHUB_ENV
            echo "ARTIFACTS_URL=https://api.github.com/repos/secondlife/viewer/actions/runs/${{ github.event.inputs.build_id }}/artifacts" >> $GITHUB_ENV
          else
            echo "BUILD_ID=${{ github.event.workflow_run.id }}" >> $GITHUB_ENV
            echo "ARTIFACTS_URL=https://api.github.com/repos/secondlife/viewer/actions/runs/${{ github.event.workflow_run.id }}/artifacts" >> $GITHUB_ENV
          fi

      - name: Verify viewer-automation-main Exists (Mac)
        if: matrix.os == 'mac'
        shell: bash
        run: |
          if [ ! -d "${{ matrix.install-path }}" ]; then
            echo "❌ Error: viewer-automation folder not found on runner!"
            exit 1
          fi
          echo "✅ viewer-automation is provided."

      - name: Verify viewer-automation-main is Up-To-Date (Mac)
        if: matrix.os == 'mac'
        shell: bash
        continue-on-error: true
        run: |
          cd ${{ matrix.install-path }}
          echo "Checking for repository updates..."

          # Check if .git directory exists
          if [ -d ".git" ]; then
            # Save local changes instead of discarding them
            git stash push -m "Automated stash before update $(date)"
            echo "Local changes saved (if any)"

            # Update the repository
            git pull || echo "⚠️ Could not update repository"
            echo "✅ Repository updated (or attempted update)"

            # Try to restore local changes if any were stashed
            if git stash list | grep -q "Automated stash before update"; then
              # Try to pop the stash, but be prepared for conflicts
              if ! git stash pop; then
                echo "⚠️ Conflict when restoring local changes"
                # Save the conflicted state in a new branch for later review
                branch_name="conflict-recovery-$(date +%Y%m%d-%H%M%S)"
                git checkout -b "$branch_name"
                echo "✅ Created branch '$branch_name' with conflicted state"

                # For test execution, revert to a clean state
                git reset --hard HEAD
                echo "✅ Reset to clean state for test execution"
              else
                echo "✅ Local changes restored successfully"
              fi
            fi
          else
            echo "⚠️ Not a Git repository, using existing files"
          fi

      - name: Verify Python Installation (Mac)
        if: matrix.os == 'mac'
        shell: bash
        run: |
          if command -v python3 &> /dev/null; then
            PYTHON_VERSION=$(python3 --version)
            echo "✅ Python found: $PYTHON_VERSION"
          else
            echo "❌ Error: Python3 not found in PATH. Please install Python on this runner."
            exit 1
          fi

      - name: Setup Python Virtual Environment (Mac)
        if: matrix.os == 'mac'
        shell: bash
        run: |
          cd ${{ matrix.install-path }}

          # Create virtual environment if it doesn't exist
          if [ ! -d ".venv" ]; then
            echo "Creating virtual environment..."
            python3 -m venv .venv
          else
            echo "Using existing virtual environment"
          fi

          # Activate virtual environment
          source .venv/bin/activate

          # Install dependencies
          if [ -f "requirements.txt" ]; then
            pip install -r requirements.txt
            echo "✅ Installed dependencies from requirements.txt"

            # Install Playwright browsers - add this line
            echo "Installing Playwright browsers..."
            python -m playwright install
          else
            pip install outleap requests behave playwright
            echo "⚠️ requirements.txt not found, installed basic dependencies"

            # Install Playwright browsers - add this line
            echo "Installing Playwright browsers..."
            python -m playwright install
          fi

      - name: Fetch & Download Installer Artifact (Mac)
        if: matrix.os == 'mac'
        shell: bash
        run: |
          # Mac-specific Bash commands
          response=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s ${{ env.ARTIFACTS_URL }})
          ARTIFACT_NAME=$(echo $response | jq -r '.artifacts[] | select(.name=="${{ matrix.artifact }}") | .archive_download_url')

          if [ -z "$ARTIFACT_NAME" ]; then
            echo "❌ Error: ${{ matrix.artifact }} artifact not found!"
            exit 1
          fi

          echo "✅ Artifact found: $ARTIFACT_NAME"

          # Secure download path
          DOWNLOAD_PATH="/tmp/secondlife-build-${{ env.BUILD_ID }}"
          mkdir -p $DOWNLOAD_PATH
          INSTALLER_PATH="$DOWNLOAD_PATH/installer.zip"

          # Download the ZIP
          curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -L $ARTIFACT_NAME -o $INSTALLER_PATH

          # Ensure download succeeded
          if [ ! -f "$INSTALLER_PATH" ]; then
            echo "❌ Error: Failed to download ${{ matrix.artifact }}.zip"
            exit 1
          fi

          # Set the path for other steps
          echo "DOWNLOAD_PATH=$DOWNLOAD_PATH" >> $GITHUB_ENV

      - name: Extract Installer & Locate Executable (Mac)
        if: matrix.os == 'mac'
        shell: bash
        run: |
          EXTRACT_PATH="${{ env.DOWNLOAD_PATH }}"
          INSTALLER_ZIP="$EXTRACT_PATH/installer.zip"

          # Debug output
          echo "Extract Path: $EXTRACT_PATH"
          echo "Installer ZIP Path: $INSTALLER_ZIP"

          # Verify ZIP exists
          if [ ! -f "$INSTALLER_ZIP" ]; then
            echo "❌ Error: ZIP file not found at $INSTALLER_ZIP!"
            exit 1
          fi

          echo "✅ ZIP file exists and is valid. Extracting..."

          # Extract the ZIP
          unzip -o "$INSTALLER_ZIP" -d "$EXTRACT_PATH"

          # Find DMG file
          INSTALLER_PATH=$(find "$EXTRACT_PATH" -name "*.dmg" -type f | head -1)

          if [ -z "$INSTALLER_PATH" ]; then
            echo "❌ Error: No installer DMG found in the extracted files!"
            echo "📂 Extracted Files:"
            ls -la "$EXTRACT_PATH"
            exit 1
          fi

          echo "✅ Installer found: $INSTALLER_PATH"
          echo "INSTALLER_PATH=$INSTALLER_PATH" >> $GITHUB_ENV

      - name: Install Second Life (Mac)
        if: matrix.os == 'mac'
        shell: bash
        run: |
          # Mac installation
          echo "Mounting DMG installer..."
          MOUNT_POINT="/tmp/secondlife-dmg"
          mkdir -p "$MOUNT_POINT"

          # Mount the DMG
          hdiutil attach "${{ env.INSTALLER_PATH }}" -mountpoint "$MOUNT_POINT" -nobrowse

          echo "✅ DMG mounted at $MOUNT_POINT"

          # Find the app in the mounted DMG
          APP_PATH=$(find "$MOUNT_POINT" -name "*.app" -type d | head -1)

          if [ -z "$APP_PATH" ]; then
            echo "❌ Error: No .app bundle found in the mounted DMG!"
            exit 1
          fi

          echo "Installing application to Applications folder..."

          # Copy the app to the Applications folder (or specified install path)
          cp -R "$APP_PATH" "${{ matrix.install-path }}"

          # Verify the app was copied successfully
          if [ ! -d "${{ matrix.install-path }}/$(basename "$APP_PATH")" ]; then
            echo "❌ Error: Failed to install application to ${{ matrix.install-path }}!"
            exit 1
          fi

          echo "✅ Application installed successfully to ${{ matrix.install-path }}"

          # Save mount point for cleanup
          echo "MOUNT_POINT=$MOUNT_POINT" >> $GITHUB_ENV

      - name: Wait for Installation to Complete (Mac)
        if: matrix.os == 'mac'
        shell: bash
        run: |
          echo "Waiting for installation to complete..."
          # Sleep to allow installation to finish (adjust as needed)
          sleep 30
          echo "✅ Installation completed"

      - name: Cleanup After Installation (Mac)
        if: matrix.os == 'mac'
        shell: bash
        run: |
          # Mac cleanup
          # Unmount the DMG
          echo "Unmounting DMG..."
          hdiutil detach "${{ env.MOUNT_POINT }}" -force

          # Clean up temporary files
          echo "Cleaning up temporary files..."
          rm -rf "${{ env.DOWNLOAD_PATH }}"
          rm -rf "${{ env.MOUNT_POINT }}"

          echo "✅ Cleanup completed"

      - name: Run QA Test Script (Mac)
        if: matrix.os == 'mac'
        shell: bash
        run: |
          echo "Running QA Test script on Mac runner: ${{ matrix.runner }}..."
          cd ${{ matrix.install-path }}

          # Activate virtual environment
          source .venv/bin/activate

          # Set runner name as environment variable
          export RUNNER_NAME="${{ matrix.runner }}"

          # Run the test script
          python runTests.py

      # - name: Upload Test Results
      #   if: always()
      #   uses: actions/upload-artifact@v4
      #   with:
      #     name: test-results-${{ matrix.runner }}
      #     path: ${{ matrix.install-path }}/regressionTest/test_results.html