# Copyright 2019-2024 Tauri Programme within The Commons Conservancy # SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: MIT name: test `@tauri-apps/api` e2e on: workflow_dispatch: push: branches: - dev pull_request: paths: - '.github/workflows/test-api-e2e.yml' - 'packages/api/**' - 'packages/api-e2e/**' - 'examples/api/**' env: RUST_BACKTRACE: 1 CARGO_PROFILE_DEV_DEBUG: 0 # keeps the target folder small for better cache efficiency # Incremental artifacts are dropped from the cache anyway and only slow the builds down. CARGO_INCREMENTAL: 0 concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true permissions: contents: read jobs: test: runs-on: ${{ matrix.platform.os }} strategy: fail-fast: false matrix: platform: - { name: Linux, os: ubuntu-latest } - { name: Windows, os: windows-latest } - { name: macOS, os: macos-latest } env: # macOS has no native WebDriver for WKWebView, so the app is driven through the # CrabNebula Webdriver (tauri-plugin-automation + test-runner-backend), which # authenticates with this key. Pull requests from forks do not get it, and the macOS # job then has nothing to test: the steps below skip the builds there rather than # occupy a macOS runner for them. HAS_CN_API_KEY: ${{ secrets.TAURI_E2E_CN_API_KEY != '' }} steps: - uses: actions/checkout@v7 - name: install Rust 1.90 # The MSRV, as the other jobs building the CLI use. The compiler version is part of # the rust-cache key, so a floating `stable` would also invalidate the entry below on # every Rust release. uses: dtolnay/rust-toolchain@1.90 - run: npm i -g --force corepack - name: setup node if: runner.os != 'macOS' || env.HAS_CN_API_KEY == 'true' uses: actions/setup-node@v7 with: node-version: 'lts/*' cache: 'pnpm' - name: install Linux dependencies if: runner.os == 'Linux' run: | sudo apt-get update sudo apt-get install -y \ libwebkit2gtk-4.1-dev \ webkit2gtk-driver \ libgtk-3-dev \ libayatana-appindicator3-dev \ librsvg2-dev \ xvfb \ fluxbox # WebKitGTK reads the color scheme and tao the theme from the desktop portal when a # window is created. On the runner that portal is registered with D-Bus but never # comes up (there is no desktop session for it), so both calls only return on their # timeouts, 25s and 5s: about 30s per app start, and every spec starts the app. # Without a service file the name is unknown and both calls fail at once. sudo rm -f /usr/share/dbus-1/services/org.freedesktop.portal.Desktop.service - name: install msedgedriver (Windows) if: runner.os == 'Windows' # The driver has to match the WebView2 runtime, which registers its version with # EdgeUpdate under the client id below. This is what msedgedriver-tool does, minus # compiling the tool from source on every run (a minute). run: | $ProgressPreference = 'SilentlyContinue' $client = 'Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' $version = @( "HKLM:\SOFTWARE\WOW6432Node\$client", "HKLM:\SOFTWARE\$client", "HKCU:\SOFTWARE\WOW6432Node\$client", "HKCU:\SOFTWARE\$client" ) | ForEach-Object { (Get-ItemProperty -Path $_ -ErrorAction SilentlyContinue).pv } | Where-Object { $_ } | Select-Object -First 1 if (-not $version) { throw 'no WebView2 runtime found in the registry' } $dir = Join-Path $env:RUNNER_TEMP 'msedgedriver' New-Item -ItemType Directory -Force -Path $dir | Out-Null Invoke-WebRequest "https://msedgedriver.microsoft.com/$version/edgedriver_win64.zip" -OutFile "$dir\edgedriver.zip" Expand-Archive "$dir\edgedriver.zip" -DestinationPath $dir -Force Write-Host "WebView2 $version; $(& "$dir\msedgedriver.exe" --version)" $dir >> $env:GITHUB_PATH - uses: Swatinem/rust-cache@v2 if: runner.os != 'macOS' || env.HAS_CN_API_KEY == 'true' with: # The dependencies of the CLI and of the example app, both in the dev profile. # Only `dev` writes the entry: one saved from a pull request lives on its merge # ref, where nothing else can restore it, and every write evicts a `dev` entry # that other runs would have hit (10 GB repository limit, LRU eviction). Pull # requests restore the `dev` entry, so they get everything but the workspace # crates for free. shared-key: api-e2e save-if: ${{ github.ref == 'refs/heads/dev' }} # A flaky spec on `dev` must not throw the build away. cache-on-failure: true - name: install dependencies if: runner.os != 'macOS' || env.HAS_CN_API_KEY == 'true' run: pnpm i --frozen-lockfile - name: build @tauri-apps/api if: runner.os != 'macOS' || env.HAS_CN_API_KEY == 'true' run: pnpm build:api - name: build @tauri-apps/cli if: runner.os != 'macOS' || env.HAS_CN_API_KEY == 'true' # Debug profile: the suite builds the example app with `tauri build --debug` anyway, and # a debug CLI reuses the cached dependencies instead of a from-scratch LTO build. run: pnpm build:cli:debug - name: run e2e tests (Linux) if: runner.os == 'Linux' timeout-minutes: 45 # A real window manager (fluxbox) is started so that window-state tests # (minimize/maximize/fullscreen/position) behave. env: E2E_SPEC_RETRIES: '1' run: | xvfb-run --auto-servernum -- bash -c ' fluxbox >/dev/null 2>&1 & sleep 1 pnpm test:api-e2e ' - name: run e2e tests (Windows) if: runner.os == 'Windows' timeout-minutes: 45 shell: pwsh # msedgedriver hands the app the `--remote-debugging-port` it attaches to through # `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS`, and WebView2 ignores that variable in an # elevated process, which is what the runner gives us. gsudo runs the suite at medium # integrity instead, and the workspace is opened up so the de-elevated process can use it. # See https://github.com/tauri-apps/wry/issues/1782 and # https://github.com/MicrosoftEdge/WebView2Feedback/issues/5645. env: E2E_SPEC_RETRIES: '1' run: | winget install gerardog.gsudo --accept-source-agreements --accept-package-agreements icacls "$env:GITHUB_WORKSPACE" /grant "Everyone:(OI)(CI)F" sudo --integrity Medium pnpm test:api-e2e - name: run e2e tests (macOS) if: runner.os == 'macOS' && env.HAS_CN_API_KEY == 'true' timeout-minutes: 45 env: CN_API_KEY: ${{ secrets.TAURI_E2E_CN_API_KEY }} E2E_SPEC_RETRIES: '1' # wdio.conf enables the CrabNebula Webdriver automatically on darwin and builds # the `.app` bundle it needs. run: pnpm test:api-e2e - name: collect app crash reports (macOS) if: runner.os == 'macOS' && failure() run: .scripts/ci/collect-macos-crash-reports.sh "$RUNNER_TEMP/crash-reports" - name: upload app crash reports (macOS) if: runner.os == 'macOS' && failure() uses: actions/upload-artifact@v7 with: name: macos-crash-reports path: ${{ runner.temp }}/crash-reports if-no-files-found: ignore