From 1a17cecee0d4b5373b697f019cc08716a9a3473b Mon Sep 17 00:00:00 2001 From: Leopoldthecoder Date: Thu, 24 Aug 2023 10:35:35 +0800 Subject: [PATCH] test(*): add pipeline for EE features --- .github/workflows/.reusable_e2e_tests_ee.yml | 95 +++++++++++++++++++ ..._tests.yml => .reusable_e2e_tests_oss.yml} | 8 +- .github/workflows/.reusable_test_image.yml | 14 ++- .github/workflows/release.yml | 33 +++++-- .github/workflows/test.yml | 31 ++++-- tests/playwright/playwright.config.ts | 2 +- .../specs-ee/plugins/01-Plugins.spec.ts | 11 +++ 7 files changed, 173 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/.reusable_e2e_tests_ee.yml rename .github/workflows/{.reusable_e2e_tests.yml => .reusable_e2e_tests_oss.yml} (94%) create mode 100644 tests/playwright/specs-ee/plugins/01-Plugins.spec.ts diff --git a/.github/workflows/.reusable_e2e_tests_ee.yml b/.github/workflows/.reusable_e2e_tests_ee.yml new file mode 100644 index 00000000..a1bff8da --- /dev/null +++ b/.github/workflows/.reusable_e2e_tests_ee.yml @@ -0,0 +1,95 @@ +# This is a BASE reusable workflow used by other workflows for E2E testing with Gateway EE + +name: Run E2E Tests - EE + +on: + workflow_call: + inputs: + base-url: + type: string + default: http://localhost:8002 + gateway-image: + type: string + default: kong/kong:nightly-ubuntu + retries: + type: number + default: 0 + +env: + GATEWAY_IMAGE: ${{ inputs.gateway-image }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN_PRIVATE_READ }} + +jobs: + e2e-tests: + strategy: + matrix: + suite: + - plugins + fail-fast: false + name: ${{ matrix.suite }} + runs-on: ${{ vars.RUNS_ON }} + + steps: + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Download assets + timeout-minutes: 5 + uses: actions/download-artifact@v3 + with: + name: assets + + - name: Unpack assets + run: tar xzvf ./assets.tar.gz + + - id: setup-node + name: Setup Node + timeout-minutes: 5 + uses: actions/setup-node@v3 + with: + node-version-file: ".nvmrc" + + - name: Install Playwright + timeout-minutes: 10 + run: | + npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}" + yarn install:e2e + yarn playwright install chromium + + - name: Log in to GitHub Container Registry + timeout-minutes: 1 + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Start Kong + timeout-minutes: 10 + working-directory: ${{ github.workspace }} + run: | + echo "Using image: $GATEWAY_IMAGE" + docker_compose_exit_code=0 + docker compose -f .ci/docker-compose.yml up -d kong --wait || docker_compose_exit_code=$? + docker compose -f .ci/docker-compose.yml logs + exit $compose_exit + + - name: Run E2E tests - EE + timeout-minutes: 10 + env: + KM_TEST_GUI_URL: ${{ inputs.base-url }} + run: | + yarn test:e2e \ + --pass-with-no-tests \ + --retries ${{ inputs.retries }} \ + --reporter=list \ + ${{ format('specs-ee/{0}/', matrix.suite) }} + + - name: Upload results + if: ${{ !cancelled() }} + continue-on-error: true + uses: actions/upload-artifact@v3 + with: + name: results-${{ matrix.suite }} + path: tests/playwright/test-results/ + retention-days: 1 diff --git a/.github/workflows/.reusable_e2e_tests.yml b/.github/workflows/.reusable_e2e_tests_oss.yml similarity index 94% rename from .github/workflows/.reusable_e2e_tests.yml rename to .github/workflows/.reusable_e2e_tests_oss.yml index 3492b4c3..f5e72a3f 100644 --- a/.github/workflows/.reusable_e2e_tests.yml +++ b/.github/workflows/.reusable_e2e_tests_oss.yml @@ -1,6 +1,6 @@ -# This is a BASE reusable workflow used by other workflows for E2E testing +# This is a BASE reusable workflow used by other workflows for E2E testing with Gateway CE -name: Run E2E Tests +name: Run E2E Tests - OSS on: workflow_call: @@ -85,7 +85,7 @@ jobs: docker compose -f .ci/docker-compose.yml logs exit $compose_exit - - name: Run E2E tests + - name: Run E2E tests - OSS timeout-minutes: 10 env: KM_TEST_GUI_URL: ${{ inputs.base-url }} @@ -94,7 +94,7 @@ jobs: --pass-with-no-tests \ --retries ${{ inputs.retries }} \ --reporter=list \ - ${{ matrix.suite }}/ + ${{ format('specs/{0}/', matrix.suite) }} - name: Upload results if: ${{ !cancelled() }} diff --git a/.github/workflows/.reusable_test_image.yml b/.github/workflows/.reusable_test_image.yml index 0459256b..5cb990f2 100644 --- a/.github/workflows/.reusable_test_image.yml +++ b/.github/workflows/.reusable_test_image.yml @@ -12,6 +12,10 @@ on: description: Name of the Gateway image (base) to use type: string default: kong/kong:nightly-ubuntu + image-name: + description: Name of the Gateway test image being built + type: string + default: kong-manager outputs: gateway-test-image: description: Name of the Gateway test image being built @@ -19,7 +23,7 @@ on: env: GATEWAY_IMAGE: ${{ inputs.gateway-image }} # Important for the "Build image" step. Do not delete. - GATEWAY_TEST_IMAGE: ghcr.io/kong/kong-manager:${{ github.sha }} + GATEWAY_TEST_IMAGE: ghcr.io/kong/${{ inputs.image-name }}:${{ github.sha }} jobs: build-and-push-test-image: @@ -50,6 +54,14 @@ jobs: echo "KONG_MANAGER_BUILD_SHA1=${KONG_MANAGER_BUILD_SHA1}" >> $GITHUB_ENV echo "KONG_MANAGER_BUILD_SHA1 = ${KONG_MANAGER_BUILD_SHA1}" + - name: Log in to Docker Hub + if: ${{ inputs.image-name == 'kong-manager-ee' }} + timeout-minutes: 1 + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0 + with: + username: ${{ secrets.DOCKER_PULL_USER }} + password: ${{ secrets.DOCKER_PULL_PASSWORD }} + - name: Log in to GitHub Container Registry timeout-minutes: 1 uses: docker/login-action@v2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 52df429f..014fa16c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,26 +17,43 @@ jobs: uses: ./.github/workflows/.reusable_build.yml secrets: inherit - build-and-push-test-image: - name: Build and Push Test Image to GHCR + build-and-push-test-image-oss: + name: Build and Push Test Image to GHCR - OSS uses: ./.github/workflows/.reusable_test_image.yml needs: build secrets: inherit with: gateway-image: kong/kong:nightly-ubuntu - e2e-tests: - name: E2E Tests - needs: build-and-push-test-image - uses: ./.github/workflows/.reusable_e2e_tests.yml + build-and-push-test-image-ee: + name: Build and Push Test Image to GHCR - EE + uses: ./.github/workflows/.reusable_test_image.yml + needs: build + secrets: inherit + with: + gateway-image: kong/kong-gateway-internal:nightly-ubuntu + image-name: kong-manager-ee + + e2e-tests-oss: + name: E2E Tests - OSS + needs: build-and-push-test-image-oss + uses: ./.github/workflows/.reusable_e2e_tests_oss.yml + with: + gateway-image: ${{ needs.build-and-push-test-image-oss.outputs.gateway-test-image }} + secrets: inherit + + e2e-tests-ee: + name: E2E Tests - EE + needs: build-and-push-test-image-ee + uses: ./.github/workflows/.reusable_e2e_tests_ee.yml with: - gateway-image: ${{ needs.build-and-push-test-image.outputs.gateway-test-image }} + gateway-image: ${{ needs.build-and-push-test-image-ee.outputs.gateway-test-image }} secrets: inherit release: name: Release runs-on: ${{ vars.RUNS_ON }} - needs: e2e-tests + needs: [e2e-tests-oss, e2e-tests-ee] env: NPM_TOKEN: ${{ secrets.NPM_TOKEN_PRIVATE_READ }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d10afb77..e4f0413b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,18 +13,35 @@ jobs: uses: ./.github/workflows/.reusable_build.yml secrets: inherit - build-and-push-test-image: - name: Build and Push Test Image to GHCR + build-and-push-test-image-oss: + name: Build and Push Test Image to GHCR - OSS uses: ./.github/workflows/.reusable_test_image.yml needs: build secrets: inherit with: gateway-image: kong/kong:nightly-ubuntu - e2e-tests: - name: E2E Tests - needs: build-and-push-test-image - uses: ./.github/workflows/.reusable_e2e_tests.yml + build-and-push-test-image-ee: + name: Build and Push Test Image to GHCR - EE + uses: ./.github/workflows/.reusable_test_image.yml + needs: build + secrets: inherit + with: + gateway-image: kong/kong-gateway-internal:nightly-ubuntu + image-name: kong-manager-ee + + e2e-tests-oss: + name: E2E Tests - OSS + needs: build-and-push-test-image-oss + uses: ./.github/workflows/.reusable_e2e_tests_oss.yml + with: + gateway-image: ${{ needs.build-and-push-test-image-oss.outputs.gateway-test-image }} + secrets: inherit + + e2e-tests-ee: + name: E2E Tests - EE + needs: build-and-push-test-image-ee + uses: ./.github/workflows/.reusable_e2e_tests_ee.yml with: - gateway-image: ${{ needs.build-and-push-test-image.outputs.gateway-test-image }} + gateway-image: ${{ needs.build-and-push-test-image-ee.outputs.gateway-test-image }} secrets: inherit diff --git a/tests/playwright/playwright.config.ts b/tests/playwright/playwright.config.ts index 4d1af576..5ece3c51 100644 --- a/tests/playwright/playwright.config.ts +++ b/tests/playwright/playwright.config.ts @@ -5,7 +5,7 @@ dotenv.config({ path: '../../.env' }) const config: PlaywrightTestConfig = { reporter: [['junit', { outputFile: './test-results/playwright.xml' }]], - testDir: './specs', + testDir: '.', // Using default value here. Let's keep it here to prevent it from being forgotten in future migrations. retries: 1, workers: 1, use: { diff --git a/tests/playwright/specs-ee/plugins/01-Plugins.spec.ts b/tests/playwright/specs-ee/plugins/01-Plugins.spec.ts new file mode 100644 index 00000000..7939ed47 --- /dev/null +++ b/tests/playwright/specs-ee/plugins/01-Plugins.spec.ts @@ -0,0 +1,11 @@ +import { expect } from '@playwright/test' +import baseTest from '@pw/base-test' + +const test = baseTest() + +test.describe('PLACEHOLDER', () => { + test('is enterprise edition', async ({ page }) => { + await page.goto('/') + await expect(page.locator('[aria-label="Gateway"] .info-list')).toContainText('enterprise') + }) +})