diff --git a/.github/workflows/e2e-tests.yaml b/.github/workflows/e2e-tests.yaml new file mode 100644 index 00000000..8b0a3122 --- /dev/null +++ b/.github/workflows/e2e-tests.yaml @@ -0,0 +1,160 @@ +# +# Copyright (C) 2025 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +name: e2e-tests + +on: + pull_request: + types: [labeled, synchronize, opened, ready_for_review, reopened] + +jobs: + # Dedicated step to build the extension image + build-container: + if: ${{ contains(github.event.pull_request.labels.*.name, 'ci/e2e') }} + name: Build Extension Image + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v6 + - name: Build Image and Extract Files + id: build-image + run: | + podman build -t local_image -f build/Containerfile ./ + CONTAINER_ID=$(podman create localhost/local_image --entrypoint "") + mkdir -p output/plugins + podman export $CONTAINER_ID | tar -x -C output/plugins/ + podman rm -f $CONTAINER_ID + podman rmi -f localhost/local_image:latest + - name: Upload Extension Image Artifact + uses: actions/upload-artifact@v5 + with: + name: extension-plugin + path: output/plugins/ + + e2e-pr-check: + name: e2e tests smoke / ${{ matrix.os }} + needs: build-container + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ windows-2025, ubuntu-24.04 ] + env: + SKIP_INSTALLATION: true + EXTENSION_PREINSTALLED: true + PODMAN_DESKTOP_ARGS: ${{ github.workspace }}/podman-desktop + # by default playwright cache browsers binaries in ~/.cache/ms-playwright on Linux and %USERPROFILE%\AppData\Local\ms-playwright on Windows + PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/podman-desktop/pw-browsers + steps: + - uses: actions/checkout@v6 + + # ============================================== + # Installing Podman + # ============================================== + - name: Install Podman v5 using external action + uses: redhat-actions/podman-install@15cb93f5a6b78a758fd8f4d1cecbf6651d4bcea3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Revert unprivileged user namespace restrictions in Ubuntu 24.04 + if: runner.os == 'Linux' + run: | + # allow unprivileged user namespace + sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 + + # ============================================== + # Installing Podman Desktop + # ============================================== + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + run_install: false + + # Install Node.js + - uses: actions/setup-node@v6 + with: + node-version: 22 + cache: 'pnpm' + + # Install npm packages for extension + - name: Execute pnpm in Extension + run: pnpm install + + # Extract @podman-desktop/api version used (and store to $GITHUB_OUTPUT) + - name: Extract @podman-desktop/api version + id: pd-api-version + shell: bash + run: | + # Using pnpm list to get the resolved version (E.g. getting 1.15.0 when ^1.15.0) + export PD_VERSION=$(pnpm list -C packages/extension/ --json | jq -r '.[0].devDependencies."@podman-desktop/api".version') + echo "PD_VERSION=$PD_VERSION" >> $GITHUB_OUTPUT + echo "Using @podman-desktop/api $PD_VERSION" + + # Check cache for existing podman-desktop + - name: Cache Podman Desktop + id: cache-pd + uses: actions/cache@v4 + with: + path: ${{ github.workspace }}/podman-desktop + key: pd-${{ steps.pd-api-version.outputs.PD_VERSION }}-${{ runner.os }} + + # Download Podman Desktop repository based on version defined in package.json + - name: Download Podman Desktop + if: steps.cache-pd.outputs.cache-hit != 'true' + shell: bash + env: + PD_VERSION: ${{ steps.pd-api-version.outputs.PD_VERSION }} + run: | + echo "Downloading PD desktop to ${{ github.workspace }}/podman-desktop" + # Stable release are available podman-desktop/podman-desktop + # Prerelease are available under podman-desktop/prereleases + if [[ "$PD_VERSION" =~ - ]]; then + curl -sL "https://github.com/podman-desktop/prereleases/archive/refs/tags/v$PD_VERSION.tar.gz" | tar xvz + else + curl -sL "https://github.com/podman-desktop/podman-desktop/archive/refs/tags/v$PD_VERSION.tar.gz" | tar xvz + fi + # Move the extracted folder to the podman-desktop folder + mv podman-desktop-$PD_VERSION/ podman-desktop/ + + # Install and build podman-desktop + - name: Install pnpm deps and build Podman Desktop + if: steps.cache-pd.outputs.cache-hit != 'true' + shell: bash + working-directory: ${{ github.workspace }}/podman-desktop + run: | + pnpm install + pnpm test:e2e:build + + # Install the extension + - name: Download Extension Plugin + uses: actions/download-artifact@v6 + with: + name: extension-plugin + path: tests/playwright/tests/playwright/output/kubernetes-dashboard-tests/plugins/ + + - name: Run E2E Smoke tests + shell: bash + run: pnpm test:e2e:smoke + env: + NODE_OPTIONS: --no-experimental-strip-types + + - uses: actions/upload-artifact@v5 + if: always() + with: + name: e2e-pr-check-${{ matrix.os }} + path: | + tests/playwright/output/ + tests/playwright/tests/ \ No newline at end of file diff --git a/README.md b/README.md index e78c7406..f7c570be 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,9 @@ You can now make changes to the sources. The project is composed of two parts, w > Note that when you only change code in the webview part, the webview is built, and the result is included in the extension, which triggers the rebuild of the extension. After each change, you may have to restart the extension from the `Extensions > Local Extensions` page. + +## Running e2e tests + +### On the CI + +When creating a PR on the GitHub repository, the e2e tests are not executed by default. To run the e2e tests, you need to add the `ci/e2e` label to the PR.