diff --git a/.github/workflows/pr-e2e.yml b/.github/workflows/pr-e2e.yml new file mode 100644 index 00000000000..96ee97e9a2e --- /dev/null +++ b/.github/workflows/pr-e2e.yml @@ -0,0 +1,104 @@ +name: pr-e2e-tests +concurrency: e2e-tests +on: + issue_comment: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + container: ghcr.io/kedacore/build-tools:main + steps: + - uses: actions/checkout@v2 + + - uses: khan/pull-request-comment-trigger@master + id: check-comment + with: + trigger: '/run-e2e' + reaction: rocket + prefix_only: true + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + + - name: Check user permission + if: steps.check-comment.outputs.triggered == 'true' + id: check-permission + uses: scherermichael-oss/action-has-permission@master + with: + required-permission: write + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout Pull Request + if: steps.check-comment.outputs.triggered == 'true' && steps.check-permission.outputs.has-permission + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + id: checkout + run: | + PR_URL="${{ github.event.issue.pull_request.url }}" + PR_NUM=${PR_URL##*/} + echo "Checking out from PR #$PR_NUM based on URL: $PR_URL" + hub pr checkout $PR_NUM + echo "::set-output name=pr_num::$PR_NUM" + + - name: Login to GitHub Container Registry + if: steps.check-comment.outputs.triggered == 'true' && steps.check-permission.outputs.has-permission + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish on GitHub Container Registry + if: steps.check-comment.outputs.triggered == 'true' && steps.check-permission.outputs.has-permission + run: make publish + env: + E2E_IMAGE_TAG: "pr-${{ steps.checkout.outputs.pr_num }}" + + - name: Run end to end tests + continue-on-error: true + if: steps.check-comment.outputs.triggered == 'true' && steps.check-permission.outputs.has-permission + id: test + env: + AZURE_SUBSCRIPTION: ${{ secrets.AZURE_SUBSCRIPTION }} + AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }} + AZURE_SP_ID: ${{ secrets.AZURE_SP_ID }} + AZURE_SP_KEY: ${{ secrets.AZURE_SP_KEY }} + AZURE_SP_TENANT: ${{ secrets.AZURE_SP_TENANT }} + TEST_STORAGE_CONNECTION_STRING: ${{ secrets.TEST_STORAGE_CONNECTION_STRING }} + TEST_LOG_ANALYTICS_WORKSPACE_ID: ${{ secrets.TEST_LOG_ANALYTICS_WORKSPACE_ID }} + OPENSTACK_USER_ID: ${{ secrets.OPENSTACK_USER_ID }} + OPENSTACK_PASSWORD: ${{ secrets.OPENSTACK_PASSWORD }} + OPENSTACK_PROJECT_ID: ${{ secrets.OPENSTACK_PROJECT_ID }} + OPENSTACK_AUTH_URL: ${{ secrets.OPENSTACK_AUTH_URL }} + AZURE_DEVOPS_BUILD_DEFINITON_ID: ${{ secrets.AZURE_DEVOPS_BUILD_DEFINITON_ID }} + AZURE_DEVOPS_ORGANIZATION_URL: ${{ secrets.AZURE_DEVOPS_ORGANIZATION_URL }} + AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }} + AZURE_DEVOPS_POOL_NAME: ${{ secrets.AZURE_DEVOPS_POOL_NAME }} + AZURE_DEVOPS_PROJECT: ${{ secrets.AZURE_DEVOPS_PROJECT }} + E2E_IMAGE_TAG: "pr-${{ steps.checkout.outputs.pr_num }}" + run: | + MESSAGE="${{ github.event.comment.body }}" + REGEX='/run-e2e (.+)' + if [[ "$MESSAGE" =~ $REGEX ]] + then + export E2E_TEST_REGEX="${BASH_REMATCH[1]}" + fi + echo "${{ steps.checkout.outputs.pr_num }}" + make e2e-test + + - name: React to comment with success + uses: dkershner6/reaction-action@v1 + if: steps.test.outcome == 'success' + with: + token: ${{ secrets.GITHUB_TOKEN }} + commentId: ${{ github.event.comment.id }} + reaction: "+1" + + - name: React to comment with failure + uses: dkershner6/reaction-action@v1 + if: steps.test.outcome != 'success' + with: + token: ${{ secrets.GITHUB_TOKEN }} + commentId: ${{ github.event.comment.id }} + reaction: "-1" diff --git a/CHANGELOG.md b/CHANGELOG.md index c27d049acf8..b7ce12835e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ - Prometheus scaler: omit `serverAddress` from generated metric name ([#2099](https://github.com/kedacore/keda/pull/2099)) - Add Makefile mockgen targets ([#2090](https://github.com/kedacore/keda/issues/2090)|[#2184](https://github.com/kedacore/keda/pull/2184)) - Drop support to `ValueMetricType` using cpu_memory_scaler ([#2218](https://github.com/kedacore/keda/issues/2218)) +- Add github action to run e2e command "on-demand" ([#2241](https://github.com/kedacore/keda/issues/2241)) ## v2.4.0 diff --git a/Makefile b/Makefile index 8fc105384ef..bc70143e24a 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,24 @@ # Variables # ################################################## SHELL = /bin/bash -VERSION ?= main + +# If E2E_IMAGE_TAG is defined, we are on pr e2e test and we have to use the new tag and append -test to the repository +ifeq '${E2E_IMAGE_TAG}' '' +VERSION = main +# SUFIX here is intentional empty to not append nothing to the repository +SUFFIX = +endif + +ifneq '${E2E_IMAGE_TAG}' '' +VERSION = ${E2E_IMAGE_TAG} +SUFFIX = -test +endif + IMAGE_REGISTRY ?= ghcr.io IMAGE_REPO ?= kedacore -IMAGE_CONTROLLER = $(IMAGE_REGISTRY)/$(IMAGE_REPO)/keda:$(VERSION) -IMAGE_ADAPTER = $(IMAGE_REGISTRY)/$(IMAGE_REPO)/keda-metrics-apiserver:$(VERSION) +IMAGE_CONTROLLER = $(IMAGE_REGISTRY)/$(IMAGE_REPO)/keda$(SUFFIX):$(VERSION) +IMAGE_ADAPTER = $(IMAGE_REGISTRY)/$(IMAGE_REPO)/keda-metrics-apiserver$(SUFFIX):$(VERSION) IMAGE_BUILD_TOOLS = $(IMAGE_REGISTRY)/$(IMAGE_REPO)/build-tools:main diff --git a/tests/run-all.sh b/tests/run-all.sh index 8a0a930af2a..d03d5d7e4ae 100755 --- a/tests/run-all.sh +++ b/tests/run-all.sh @@ -1,6 +1,8 @@ #! /bin/bash set -eu +E2E_REGEX=${E2E_TEST_REGEX:-*.test.ts} + DIR=$(dirname "$0") cd $DIR @@ -18,7 +20,7 @@ function run_setup { function run_tests { counter=0 # randomize tests order using shuf - for test_case in $(find scalers -name "*.test.ts" | shuf) + for test_case in $(find scalers -name "$E2E_REGEX" | shuf) do counter=$((counter+1)) ./node_modules/.bin/ava $test_case > "${test_case}.log" 2>&1 & diff --git a/tools/build-tools.Dockerfile b/tools/build-tools.Dockerfile index 3c2e2666f7d..bec112c61df 100644 --- a/tools/build-tools.Dockerfile +++ b/tools/build-tools.Dockerfile @@ -1,14 +1,17 @@ FROM ubuntu:18.04 # Install prerequisite -RUN apt-get update && \ - apt-get install -y wget curl build-essential git +RUN apt update && \ + apt-get install software-properties-common -y +RUN apt-add-repository ppa:git-core/ppa && \ + apt update && \ + apt install -y wget curl build-essential git # Use Bash instead of Dash RUN ln -sf bash /bin/sh # Install azure-cli -RUN apt-get install apt-transport-https lsb-release software-properties-common dirmngr -y && \ +RUN apt-get install apt-transport-https lsb-release dirmngr -y && \ curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | \ tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null && \ AZ_REPO=$(lsb_release -cs) && \ @@ -64,3 +67,8 @@ ENV PATH=${PATH}:/usr/local/go/bin \ # Install FOSSA tooling RUN curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install.sh | bash + +# Install hub +RUN curl -LJO https://github.com/github/hub/releases/download/v2.14.2/hub-linux-amd64-2.14.2.tgz && \ + tar zxvf hub-linux-amd64-2.14.2.tgz +ENV PATH="/hub-linux-amd64-2.14.2/bin:${PATH}"