Skip to content

Playwright Tests

Playwright Tests #371

Workflow file for this run

name: Playwright Tests
on:
workflow_dispatch:
inputs:
rancher:
type: choice
default: 'rc'
description: Rancher
required: true
options:
- rc
- released
kubewarden:
type: choice
default: 'rc'
description: Kubewarden
required: true
options:
- source
- rc
- released
testsuite:
type: choice
default: 'install'
description: Testsuite
required: true
options:
- install (10 min)
- install + policies (10+30 min)
policyfilter:
type: string
description: Policy Filter
pull_request:
branches: main
paths: pkg/kubewarden/**
push:
tags:
- '*'
schedule:
- cron: "0 2 * * *"
env:
K3S_VERSION: v1.25.9-k3s1
K3D_CLUSTER_NAME: ${{ github.repository_owner }}-${{ github.event.repository.name }}-runner
jobs:
e2e:
# run schedule workflows only on original repo, not forks
if: github.repository_owner == 'rancher' || github.event_name != 'schedule'
runs-on: self-hosted
steps:
# ==================================================================================================
# Check out code and install requirements
- uses: actions/checkout@v3
- uses: azure/setup-kubectl@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install playwright
working-directory: tests
run: |
yarn
yarn playwright install chromium # --with-deps
# ==================================================================================================
# Set up parameters and ENV
- name: Setup global ENV
run: |
case ${{github.event_name}} in
pull_request)
RANCHER=rc
KUBEWARDEN=source
TESTSUITE=install
;;
schedule)
RANCHER=rc
KUBEWARDEN=released
TESTSUITE=policies
;;
workflow_dispatch)
RANCHER="${{ inputs.rancher }}"
KUBEWARDEN="${{ inputs.kubewarden }}"
TESTSUITE="${{ inputs.testsuite }}"
;;
push)
RANCHER=released
KUBEWARDEN=rc
TESTSUITE=policies
esac
echo "Event: ${{github.event_name}}"
echo RANCHER=$RANCHER | tee -a $GITHUB_ENV
echo KUBEWARDEN=$KUBEWARDEN | tee -a $GITHUB_ENV
echo TESTSUITE="$TESTSUITE" | tee -a $GITHUB_ENV
# ==================================================================================================
# Create k3d cluster and install rancher
- name: "Create kubernetes cluster"
uses: AbsaOSS/[email protected]
with:
cluster-name: ${{ env.K3D_CLUSTER_NAME }}
args: "--agents 1 --image rancher/k3s:${{ env.K3S_VERSION }}"
- name: Install Rancher
run: |
RANCHER_FQDN=$(k3d cluster list ${{ env.K3D_CLUSTER_NAME }} -o json | jq -r '[.[].nodes[] | select(.role == "server").IP.IP] | first').nip.io
# Wait for kube-system
for i in {1..20}; do
output=$(kubectl get pods --no-headers -o wide -n kube-system | grep -vw Completed || echo 'Fail')
grep -vE '([0-9]+)/\1 +Running' <<< $output || break
[ $i -ne 20 ] && sleep 10 || { echo "Godot: pods not running"; exit 1; }
done
# Wait for cert-manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.11.0/cert-manager.yaml
kubectl wait --for=condition=Available deployment --timeout=2m -n cert-manager --all
[ "${{ env.RANCHER }}" == 'rc' ] && RANCHER_DEVEL=1
RANCHER_PSP=$(kubectl version -o json | jq -r '.serverVersion.minor <= "24"')
helm repo add --force-update rancher-latest https://releases.rancher.com/server-charts/latest
helm upgrade --install rancher rancher-latest/rancher --wait \
--namespace cattle-system --create-namespace \
--set hostname=$RANCHER_FQDN \
--set bootstrapPassword=sa \
--set global.cattle.psp.enabled=$RANCHER_PSP \
${RANCHER_DEVEL:+--devel}
# Wait for rancher
for i in {1..20}; do
output=$(kubectl get pods --no-headers -o wide -n cattle-system -l app=rancher-webhook | grep -vw Completed || echo 'Wait: cattle-system')$'\n'
output+=$(kubectl get pods --no-headers -o wide -n cattle-system | grep -vw Completed || echo 'Wait: cattle-system')$'\n'
output+=$(kubectl get pods --no-headers -o wide -n cattle-fleet-system | grep -vw Completed || echo 'Wait: cattle-fleet-system')$'\n'
grep -vE '([0-9]+)/\1 +Running|^$' <<< $output || break
[ $i -ne 20 ] && sleep 30 || { echo "Godot: pods not running"; exit 1; }
done
echo "RANCHER_FQDN=$RANCHER_FQDN" >> $GITHUB_ENV
# ==================================================================================================
# Setup playwright ENV and run tests
# https://rancher.github.io/dashboard/testing/e2e-test#setup-for-local-tests
- name: Build Kubewarden extension
if: env.KUBEWARDEN == 'source'
run: |
yarn install --ignore-engines
VERSION=0.0.1 yarn build-pkg kubewarden
- name: Install Kubewarden
working-directory: tests
run: |
yarn playwright test "/[0-9]0-" -x
env:
RANCHER_URL: https://${{env.RANCHER_FQDN}}
ORIGIN: ${{ env.KUBEWARDEN }}
PLAYWRIGHT_HTML_REPORT: installation-report
- name: Install policies
if: ${{ contains(env.TESTSUITE, 'policies') || inputs.policyfilter }}
timeout-minutes: 90
working-directory: tests
run: |
yarn playwright test /policies -g "${{ inputs.policyfilter || '' }}" -x
env:
RANCHER_URL: https://${{env.RANCHER_FQDN}}
ORIGIN: ${{ env.KUBEWARDEN }}
PLAYWRIGHT_HTML_REPORT: policies-report
# ==================================================================================================
# Artifacts & Summary
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: |
tests/installation-report/
tests/policies-report/
retention-days: 30
- name: Clean Up
if: always()
run: |
k3d cluster delete ${{ env.K3D_CLUSTER_NAME }}