Skip to content

Commit

Permalink
ci: 👷 enable multi browsers tests through cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
this-is-tobi committed Oct 28, 2023
1 parent 073d2c6 commit 5f39d36
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 20 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ on:
types:
- closed
workflow_dispatch:
inputs:
PR_NUMBER:
description: ID number of the pull request assiocited with the cache
required: false
type: string
BRANCH_NAME:
description: Branch name assiocited with the cache
required: false
type: string

jobs:
cleanup-cache:
Expand All @@ -19,7 +28,11 @@ jobs:
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
if [ -n "${{ inputs.BRANCH_NAME }}" ]; then
BRANCH="${{ inputs.BRANCH_NAME }}"
else
BRANCH="refs/pull/${{ github.event.pull_request.number || inputs.PR_NUMBER }}/merge"
fi
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
Expand All @@ -37,6 +50,7 @@ jobs:
matrix:
name: Generate matrix for build & scan
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.number || github.event.number }}
outputs:
build-matrix: ${{ steps.build-matrix.outputs.BUILD_MATRIX }}
steps:
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ on:
PNPM_VERSION:
required: false
type: string
workflow_dispatch:
inputs:
NODE_VERSION:
description: Nodejs version used to run tests
required: true
type: string
default: "18.18.0"
PNPM_VERSION:
description: Pnpm version used to run tests
required: true
type: string
default: "8"

jobs:
lint:
Expand Down
40 changes: 38 additions & 2 deletions .github/workflows/tests-component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,28 @@ on:
PNPM_VERSION:
required: true
type: string
workflow_dispatch:
inputs:
NODE_VERSION:
description: Nodejs version used to run tests
required: true
type: string
default: "18.18.0"
PNPM_VERSION:
description: Pnpm version used to run tests
required: true
type: string
default: "8"

jobs:
unit-tests:
name: Component tests
runs-on: ubuntu-latest
strategy:
matrix:
browsers:
- electron
- firefox
steps:
- name: Checks-out repository
uses: actions/checkout@v3
Expand All @@ -30,6 +47,24 @@ jobs:
with:
node-version: "${{ inputs.NODE_VERSION }}"

- name: Setup firefox
uses: browser-actions/setup-firefox@v1
if: ${{ matrix.browsers == 'firefox' }}
with:
firefox-version: latest

- name: Setup chrome
uses: browser-actions/setup-chrome@v1
if: ${{ matrix.browsers == 'chrome' }}
with:
chrome-version: latest

- name: Setup edge
uses: browser-actions/setup-edge@v1
if: ${{ matrix.browsers == 'edge' }}
with:
edge-version: latest

- name: Get pnpm store directory
id: pnpm-store
run: |
Expand All @@ -50,8 +85,9 @@ jobs:
with:
path: |
./.turbo/cache
key: turbo-component-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('apps/**/src/**','apps/client/cypress/**','packages/**/src/**') }}
key: turbo-component-${{ runner.os }}-${{ runner.arch }}-${{ matrix.browsers }}-${{ hashFiles('apps/**/src/**','apps/client/cypress/**','packages/**/src/**') }}
restore-keys: |
turbo-component-${{ runner.os }}-${{ runner.arch }}-${{ matrix.browsers }}-
turbo-component-${{ runner.os }}-${{ runner.arch }}-
- name: Install dependencies
Expand All @@ -60,7 +96,7 @@ jobs:
- name: Run component tests
run: |
./ci/scripts/init-env.sh
./ci/scripts/run-tests.sh -c
./ci/scripts/run-tests.sh -c -b "${{ matrix.browsers }}"
- name: Upload cypress artifacts
if: ${{ failure() }}
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/tests-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ on:
TAG:
required: true
type: string
workflow_dispatch:
inputs:
TAG:
description: Image tag used ti run tests
required: true
type: string
default: "latest"

jobs:
deploy-check:
Expand Down
45 changes: 43 additions & 2 deletions .github/workflows/tests-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,33 @@ on:
TAG:
required: true
type: string
workflow_dispatch:
inputs:
NODE_VERSION:
description: Nodejs version used to run tests
required: true
type: string
default: "18.18.0"
PNPM_VERSION:
description: Pnpm version used to run tests
required: true
type: string
default: "8"
TAG:
description: Image tag used ti run tests
required: true
type: string
default: "latest"

jobs:
e2e-tests:
name: End to end tests
runs-on: ubuntu-latest
strategy:
matrix:
browsers:
- electron
- firefox
steps:
- name: Checks-out repository
uses: actions/checkout@v3
Expand All @@ -33,6 +55,24 @@ jobs:
with:
node-version: "${{ inputs.NODE_VERSION }}"

- name: Setup firefox
uses: browser-actions/setup-firefox@v1
if: ${{ matrix.browsers == 'firefox' }}
with:
firefox-version: latest

- name: Setup chrome
uses: browser-actions/setup-chrome@v1
if: ${{ matrix.browsers == 'chrome' }}
with:
chrome-version: latest

- name: Setup edge
uses: browser-actions/setup-edge@v1
if: ${{ matrix.browsers == 'edge' }}
with:
edge-version: latest

- name: Get pnpm store directory
id: pnpm-store
run: |
Expand All @@ -53,8 +93,9 @@ jobs:
with:
path: |
./.turbo/cache
key: turbo-e2e-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('apps/**/src/**','apps/client/cypress/**','packages/**/src/**') }}
key: turbo-e2e-${{ runner.os }}-${{ runner.arch }}-${{ matrix.browsers }}-${{ hashFiles('apps/**/src/**','apps/client/cypress/**','packages/**/src/**') }}
restore-keys: |
turbo-e2e-${{ runner.os }}-${{ runner.arch }}-${{ matrix.browsers }}-
turbo-e2e-${{ runner.os }}-${{ runner.arch }}-
- name: Install dependencies
Expand All @@ -63,7 +104,7 @@ jobs:
- name: Run e2e tests
run: |
./ci/scripts/init-env.sh
./ci/scripts/run-tests.sh -e -t "${{ inputs.TAG }}"
./ci/scripts/run-tests.sh -e -t "${{ inputs.TAG }}" -b "${{ matrix.browsers }}"
- name: Upload cypress artifacts
if: ${{ failure() }}
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/tests-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ on:
SONAR_PROJECT_KEY:
required: false
workflow_dispatch:
inputs:
NODE_VERSION:
description: Nodejs version used to run tests
required: true
type: string
default: "18.18.0"
PNPM_VERSION:
description: Pnpm version used to run tests
required: true
type: string
default: "8"

jobs:
unit-tests:
Expand Down
16 changes: 8 additions & 8 deletions apps/client/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { defineConfig } from 'cypress'
import viteConfig from './vite.config'

const argocdUrl = process.env.ARGOCD_URL || 'https://argo-cd.readthedocs.io'
const gitlabUrl = process.env.GITLAB_URL || 'https://gitlab.com'
const harborUrl = process.env.HARBOR_URL || 'https://goharbor.io'
const nexusUrl = process.env.NEXUS_URL || 'https://sonatype.com/products/nexus-repository'
const sonarqubeUrl = process.env.SONARQUBE_URL || 'https://www.sonarqube.org'
const vaultUrl = process.env.VAULT_URL || 'https://www.vaultproject.io'
const clientHost = process.env.CLIENT_HOST || 'localhost'
const clientPort = process.env.CLIENT_PORT || '8080'
const argocdUrl = process.env.ARGOCD_URL ?? 'https://argo-cd.readthedocs.io'
const gitlabUrl = process.env.GITLAB_URL ?? 'https://gitlab.com'
const harborUrl = process.env.HARBOR_URL ?? 'https://goharbor.io'
const nexusUrl = process.env.NEXUS_URL ?? 'https://sonatype.com/products/nexus-repository'
const sonarqubeUrl = process.env.SONARQUBE_URL ?? 'https://www.sonarqube.org'
const vaultUrl = process.env.VAULT_URL ?? 'https://www.vaultproject.io'
const clientHost = process.env.CLIENT_HOST ?? 'localhost'
const clientPort = process.env.CLIENT_PORT ?? '8080'

// @ts-ignore server does exist!
viteConfig.server.host = '127.0.0.1'
Expand Down
2 changes: 1 addition & 1 deletion apps/client/cypress/components/specs/repo-form.ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useProjectStore } from '@/stores/project.js'
import { allOrganizations } from '@dso-console/shared'

describe('RepoForm.vue', () => {
it('Should mount a new repo RepoForm', () => {
it('Should mount a new repo RepoForm', { browser: '!firefox' }, () => {
cy.intercept('POST', '/api/v1/ci-files', {
'gitlab-ci-dso': 'gitlab-ci file',
node: 'node file',
Expand Down
1 change: 1 addition & 0 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "run-s type-check build-only",
"build-only": "vite build",
"clean:build": "rimraf dist",
"cypress:install": "cypress install",
"dev": "vite",
"format": "eslint . --ext .js,.cjs,.ts,vue --fix",
"format:style": "stylelint ./src/**/*.{css,vue} --fix",
Expand Down
21 changes: 15 additions & 6 deletions ci/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ RUN_STATUS_CHECK="false"
TEXT_HELPER="\nThis script aims to run application tests.
Following flags are available:
-b (Optional) Browser used for e2e components and tests
-c Run component tests
-e Run e2e tests
Expand All @@ -36,7 +38,7 @@ Following flags are available:
-s Run deployement status check
-t Tag used for docker images in e2e tests
-t (Optional) Tag used for docker images in e2e tests
-u Run unit tests
Expand All @@ -47,9 +49,11 @@ print_help() {
}

# Parse options
while getopts hcelst:u flag
while getopts hb:celst:u flag
do
case "${flag}" in
b)
BROWSER=${OPTARG};;
c)
RUN_COMPONENT_TESTS=true;;
e)
Expand Down Expand Up @@ -124,7 +128,9 @@ if [ "$RUN_COMPONENT_TESTS" == "true" ]; then
printf "\n${red}${i}.${no_color} Launch component tests\n"
i=$(($i + 1))

npm run test:ct-ci -- --cache-dir=.turbo/cache --log-order=stream
[[ -n "$BROWSER" ]] && BROWSER_ARGS="-- --browser $BROWSER"

npm run test:ct-ci -- --cache-dir=.turbo/cache --log-order=stream $BROWSER_ARGS
fi


Expand All @@ -135,11 +141,14 @@ if [ "$RUN_E2E_TESTS" == "true" ]; then
printf "\n${red}${i}.${no_color} Launch e2e tests\n"
i=$(($i + 1))

[[ -n "$TAG" ]] && TAG_ARGS="-- -t $TAG"
[[ -n "$BROWSER" ]] && BROWSER_ARGS="-- --browser $BROWSER"

npm --prefix $PROJECT_DIR/packages/shared run build
npm --prefix $PROJECT_DIR/packages/test-utils run build
./ci/kind/run.sh -i -d console.dso.local,keycloak.dso.local,pgadmin.dso.local
./ci/kind/run.sh -c create,prod -t $TAG
npm run kube:e2e-ci -- --cache-dir=.turbo/cache --log-order=stream
npm run kube:init
npm run kube:prod $TAG_ARGS
npm run kube:e2e-ci -- --cache-dir=.turbo/cache --log-order=stream $BROWSER_ARGS

printf "\n${red}${i}.${no_color} Remove resources\n"
i=$(($i + 1))
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"int": "npm run kube:dev:build; npm run kube:int",
"kube:init": "ci/kind/run.sh -i -d console.dso.local,keycloak.dso.local,pgadmin.dso.local",
"kube:dev:build": "ci/kind/run.sh -c create,build -f docker/docker-compose.dev.yml",
"kube:dev:load": "ci/kind/run.sh -c create,load -f docker/docker-compose.dev.yml",
"kube:dev": "ci/kind/run.sh -c create,dev",
"kube:int": "ci/kind/run.sh -c create,dev,int",
"kube:prod:build": "ci/kind/run.sh -c create,build -f docker/docker-compose.prod.yml",
"kube:prod:load": "ci/kind/run.sh -c create,load -f docker/docker-compose.prod.yml",
"kube:prod": "ci/kind/run.sh -c create,prod",
"kube:e2e": "npm --prefix apps/client run test:e2e",
"kube:e2e-ci": "turbo run test:e2e-ci --filter=client --color",
Expand Down

0 comments on commit 5f39d36

Please sign in to comment.