diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000..6037cd9 --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,121 @@ +name: E2E Test + +on: + pull_request: + branches: + - main + - "release-*" + paths-ignore: + - "docs/**" + - "**.md" + - "sec-scanners-config.yaml" + +env: + EPP_IMAGE: europe-docker.pkg.dev/kyma-project/dev/eventing-publisher-proxy:PR-${{ github.event.number }} + +jobs: + e2e-nats: + runs-on: ubuntu-latest + steps: + - name: Checkout EPP repository + uses: actions/checkout@v4 + with: + path: main + + - name: Checkout EM repository + uses: actions/checkout@v4 + with: + repository: kyma-project/eventing-manager + path: eventing-manager + + - name: Cache binaries + id: cache-binaries + uses: actions/cache@v3 + with: + path: bin + key: ${{ runner.os }}-bin + + - name: Install k3d tools + run: | + make -C eventing-manager/hack/ci/ install-k3d-tools + + - name: Install Kyma CLI & setup k3d cluster using Kyma CLI + run: | + make -C eventing-manager kyma + make -C main/hack/ci/ create-k3d + kubectl version + kubectl cluster-info + + - name: Create Namespace + run: | + kubectl create ns kyma-system + + - name: Deploy NATS Manager + run: | + kubectl apply -f https://github.com/kyma-project/nats-manager/releases/latest/download/nats-manager.yaml + kubectl apply -f https://github.com/kyma-project/nats-manager/releases/latest/download/nats_default_cr.yaml + echo "Using NATS Manager image:" + kubectl get -n kyma-system deployment nats-manager -o=jsonpath='{$.spec.template.spec.containers[:1].image}' + + - name: Deploy Eventing Manager + run: | + kubectl apply -f https://github.com/kyma-project/eventing-manager/releases/latest/download/eventing-manager.yaml + kubectl apply -f https://github.com/kyma-project/eventing-manager/releases/latest/download/eventing_default_cr.yaml + echo "Using Eventing Manager image:" + kubectl get -n kyma-system deployment eventing-manager -o=jsonpath='{$.spec.template.spec.containers[:1].image}' + + - name: Wait for build job to succeed + uses: kyma-project/wait-for-commit-status-action@2b3ffe09af8b6f40e1213d5fb7f91a7bd41ffb20 + with: + context: "pull-eventing-publisher-proxy-build" + commit_ref: "${{ github.event.pull_request.head.sha }}" # Note: 'github.event.pull_request.head.sha' is not same as 'github.sha' on pull requests. + timeout: 600000 # 10 minutes in milliseconds + # The check interval is kept long otherwise it will exhaust the GitHub rate limit (More info: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting) + check_interval: 60000 # 1 minute in milliseconds + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + GITHUB_OWNER: "${{ github.repository_owner }}" + GITHUB_REPO: "eventing-publisher-proxy" + + - name: Setup Eventing Manager with new EPP image + run: | + kubectl get deployment eventing-manager -n kyma-system -o=json | + jq --arg new_image "$EPP_IMAGE" \ + '.spec.template.spec.containers[0].env |= map(if .name == "PUBLISHER_IMAGE" then .value = $new_image else . end)' | + kubectl apply -f - + kubectl rollout status deployment/eventing-manager -n kyma-system --timeout=120s + kubectl rollout status deployment/eventing-publisher-proxy -n kyma-system --timeout=120s + + - name: Check if EPP image successfully applied + run: | + DEPLOYMENT_IMAGE=$(kubectl get deployment -n kyma-system eventing-publisher-proxy -o=jsonpath='{$.spec.template.spec.containers[:1].image}') + if [ "$DEPLOYMENT_IMAGE" != "$EPP_IMAGE" ]; then + echo "EPP images do not match." + echo "Desired EPP image: $EPP_IMAGE. Image in EPP deployment: $DEPLOYMENT_IMAGE" + echo "Updating Eventing Manager with new image failed." + exit 1 + else + echo "EPP image update successful." + fi + + - name: Setup subscriptions for testing + run: | + make -C eventing-manager e2e-eventing-setup + + - name: Test Eventing + run: | + make -C eventing-manager e2e-eventing + + - name: Cleanup test resources + run: | + make -C eventing-manager e2e-cleanup + + - name: On error get NATS CR + if: failure() + run: | + kubectl get nats -n kyma-system -o yaml + + - name: On error get Eventing CR + if: failure() + run: | + kubectl get eventing -n kyma-system -o yaml diff --git a/hack/ci/Makefile b/hack/ci/Makefile new file mode 100644 index 0000000..028c096 --- /dev/null +++ b/hack/ci/Makefile @@ -0,0 +1,7 @@ +KYMA_CLI ?= "/home/runner/work/eventing-publisher-proxy/eventing-publisher-proxy/eventing-manager/bin/kyma-unstable" +CLUSTER_NAME ?= kyma +REGISTRY_PORT ?= 5001 + +.PHONY: create-k3d +create-k3d: ## Create k3d with kyma CRDs. + "${KYMA_CLI}" provision k3d -p 8081:80@loadbalancer -p 8443:443@loadbalancer --registry-port ${REGISTRY_PORT} --name ${CLUSTER_NAME} --ci diff --git a/hack/get_kyma_file_name.sh b/hack/get_kyma_file_name.sh new file mode 100755 index 0000000..da047b7 --- /dev/null +++ b/hack/get_kyma_file_name.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +function get_kyma_file_name () { + + local _OS_TYPE=$1 + local _OS_ARCH=$2 + + [ "$_OS_TYPE" == "Linux" ] && [ "$_OS_ARCH" == "x86_64" ] && echo "kyma-linux" || + [ "$_OS_TYPE" == "Linux" ] && [ "$_OS_ARCH" == "arm64" ] && echo "kyma-linux-arm" || + [ "$_OS_TYPE" == "Windows" ] && [ "$_OS_ARCH" == "x86_64" ] && echo "kyma.exe" || + [ "$_OS_TYPE" == "Windows" ] && [ "$_OS_ARCH" == "arm64" ] && echo "kyma-arm.exe" || + [ "$_OS_TYPE" == "Darwin" ] && [ "$_OS_ARCH" == "x86_64" ] && echo "kyma-darwin" +} + +get_kyma_file_name "$@"