Skip to content

Commit

Permalink
Introduce cypress tests (#427)
Browse files Browse the repository at this point in the history
* Introduce cypress tests

* Fix manusa/actions-setup-minikube version

* Downgrade K8s version

* Fix while loop

* Wait for resources to be available before verifying them

* Wait for resources to be available before verifying them

* Wait for resources to be available before verifying them

* Wait for resources to be available before verifying them

* Wait for resources to be available before verifying them

* Wait for resources to be available before verifying them

* Enrich operator yaml

* Add basic cypress test

* Fix CYPRESS_BASE_URL generation

* Fix CYPRESS_BASE_URL generation

* Change name of tests

* Change name of tests

* Restore aria-label

* Use custom application container

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Split generation of container images

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Use custom registry

* Test local running test

* Test local running test

* Test local running test

* Test local running test

* Test local running test

* Test local running test

* Test local running test

* Enhance release pipeline
  • Loading branch information
carlosthe19916 authored Dec 30, 2022
1 parent 3c1af7a commit 10b5888
Show file tree
Hide file tree
Showing 21 changed files with 661 additions and 87 deletions.
243 changes: 243 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,249 @@ jobs:
working-directory: application/src/main/webapp
run: npm run test -- --coverage --watchAll=false

application-container:
name: Application container
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
cache: maven
- name: Build container image
run: |
mvn -U -B package --file pom.xml -DskipTests \
-Dquarkus.native.container-build=true \
-Dquarkus.container-image.push=false \
-Dquarkus.container-image.build=true \
-Dquarkus.container-image.registry=localhost:5000 \
-Dquarkus.container-image.group="" \
-Dquarkus.container-image.name=searchpe \
-Dquarkus.container-image.tag=0.0.0 \
-P native,ui \
-pl application
- name: Save container image
run: docker save -o searchpe-application-container-image.tar localhost:5000/searchpe:0.0.0
- name: Upload container image
uses: actions/upload-artifact@v3
with:
name: artifacts
path: searchpe-application-container-image.tar

operator-container:
name: Operator container
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
cache: maven
- name: Build container image
run: |
mvn -U -B package --file pom.xml -DskipTests \
-Dquarkus.native.container-build=true \
-Dquarkus.container-image.push=false \
-Dquarkus.container-image.build=true \
-Dquarkus.container-image.registry=localhost:5000 \
-Dquarkus.container-image.group="" \
-Dquarkus.container-image.name=searchpe-operator \
-Dquarkus.container-image.tag=0.0.0 \
-P native \
-pl operator
- name: Save container image
run: docker save -o searchpe-operator-container-image.tar localhost:5000/searchpe-operator:0.0.0
- name: Upload container image
uses: actions/upload-artifact@v3
with:
name: artifacts
path: searchpe-operator-container-image.tar

catalog-container:
name: Catalog container
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
cache: maven
- name: Setup OLM CLIs
run: |
export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)
export OS=$(uname | awk '{print tolower($0)}')
# Opm
export OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-registry/releases/download/v1.26.2
curl -LO ${OPERATOR_SDK_DL_URL}/${OS}-${ARCH}-opm
chmod +x ${OS}-${ARCH}-opm && sudo mv ${OS}-${ARCH}-opm /usr/local/bin/opm
- name: Setup other tools
run: |
sudo apt-get install -y groovy
- name: Build container image
run: |
mvn -U -B package --file pom.xml -DskipTests \
-Dquarkus.native.container-build=false \
-Dquarkus.container-image.push=false \
-Dquarkus.container-image.build=false \
-Dquarkus.container-image.registry=localhost:5000 \
-Dquarkus.container-image.group="" \
-Dquarkus.container-image.name=searchpe-operator \
-Dquarkus.operator-sdk.bundle.package-name=searchpe-operator \
-Dquarkus.operator-sdk.bundle.channels=alpha \
-Dquarkus.application.version=0.0.0 \
-Dquarkus.kubernetes.image-pull-policy=if-not-present \
-Dquarkus.kubernetes.env.vars.operator-searchpe-image=localhost:5000/searchpe:0.0.0 \
-Dquarkus.kubernetes.env.vars.operator-searchpe-image-pull-policy=IfNotPresent \
-pl operator
groovy scripts/enrichCSV.groovy operator/target/bundle/searchpe-operator/manifests/searchpe-operator.clusterserviceversion.yaml 0.0.0
sed -i "/ annotations: ''/d" ./operator/target/bundle/searchpe-operator/manifests/searchpe-operator.clusterserviceversion.yaml
- name: Init local Registry
run: |
docker run -d -p 5000:5000 --name registry registry:2
sleep 5
- name: Create bundle image
run: |
# Bundle
BUNDLE_IMAGE=localhost:5000/searchpe-operator-bundle:0.0.0
docker build -t $BUNDLE_IMAGE -f operator/target/bundle/searchpe-operator/bundle.Dockerfile operator/target/bundle/searchpe-operator
docker push $BUNDLE_IMAGE
# Catalog
CATALOG_IMAGE=localhost:5000/searchpe-operator-catalog:0.0.0
opm index add --bundles $BUNDLE_IMAGE --tag $CATALOG_IMAGE --use-http --build-tool docker
# Save container images
docker save -o searchpe-bundle-container-image.tar $BUNDLE_IMAGE
docker save -o searchpe-catalog-container-image.tar $CATALOG_IMAGE
- name: Upload container image
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
searchpe-bundle-container-image.tar
searchpe-catalog-container-image.tar
ui-e2e-tests:
needs: [ application-container, operator-container, catalog-container ]
name: UI E2E Tests
runs-on: ubuntu-latest
strategy:
matrix:
k8s-version: [ v1.25.3 ]
browser: [ chrome ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: actions/download-artifact@v3
- name: Load and config images
run: |
docker load -i artifacts/searchpe-application-container-image.tar
docker load -i artifacts/searchpe-operator-container-image.tar
docker load -i artifacts/searchpe-bundle-container-image.tar
docker load -i artifacts/searchpe-catalog-container-image.tar
- name: Setup Minikube
uses: manusa/actions-setup-minikube@v2.7.2
with:
minikube version: v1.28.0
kubernetes version: ${{ matrix.k8s-version }}
start args: --insecure-registry "10.0.0.0/24" --addons=registry,ingress
github token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Minikube
run: |
# Install OLM
curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.22.0/install.sh | bash -s v0.22.0
# Load images
minikube image load localhost:5000/searchpe:0.0.0
minikube image load localhost:5000/searchpe-operator:0.0.0
minikube image load localhost:5000/searchpe-operator-bundle:0.0.0
minikube image load localhost:5000/searchpe-operator-catalog:0.0.0
# Push images to internal registry
docker push localhost:5000/searchpe:0.0.0
docker push localhost:5000/searchpe-operator:0.0.0
docker push localhost:5000/searchpe-operator-bundle:0.0.0
docker push localhost:5000/searchpe-operator-catalog:0.0.0
- name: Install Searchpe operator
run: |
kubectl create ns openubl
# Create custom catalog
kubectl create -f scripts/searchpe-operator.yaml
kubectl get pods -n olm --selector=olm.catalogSource=searchpe-catalog-source
# Verify subscription
kubectl get csv -n olm
- name: Install Postgresql Operator
run: |
kubectl create -f https://operatorhub.io/install/postgresql.yaml
PHASE=""
while [ "$PHASE" != "Succeeded" ]
do
PHASE=$(kubectl get csv -n operators -o jsonpath="{$.items[*].status.phase}")
echo "Waiting for postgresql csv. Current phase=$PHASE"
sleep 10;
done
- name: Install DB
run: |
kubectl -n openubl apply -f scripts/postgresql.yaml
POD_COUNT=0
while [ $POD_COUNT -le 3 ]
do
POD_COUNT=$(kubectl get pods -n openubl -o name | wc -l)
echo "Waiting for pods to exists. Current count=$POD_COUNT"
sleep 10;
done
echo "Resources exists, now wait for them to be ready"
kubectl wait pods -l "postgres-operator.crunchydata.com/data"="pgbackrest" -n openubl --for condition=Ready --timeout=-1s
kubectl wait pods -l "postgres-operator.crunchydata.com/data"="postgres" -n openubl --for condition=Ready --timeout=-1s
- name: Install Searchpe
run: |
kubectl -n openubl apply -f scripts/searchpe.yaml
sleep 10;
kubectl wait pods --selector "app.kubernetes.io/name"="searchpe" -n openubl --for condition=Ready --timeout=-1s
external_ip=""
while [[ -z $external_ip ]]
do
external_ip=$(kubectl get ingress searchpe-searchpe-ingress --template="{{range.status.loadBalancer.ingress}}{{.ip}}{{end}}" -n openubl);
echo "Waiting for end point...current=$external_ip"
sleep 10;
done
echo "End point ready: $external_ip"
export endpoint=$(minikube ip);
echo "CYPRESS_BASE_URL=https://$endpoint" >> $GITHUB_ENV
- name: Cypress run
uses: cypress-io/github-action@v5
with:
working-directory: application/src/main/webapp
record: false
browser: ${{ matrix.browser }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v1
if: failure()
with:
name: container-screenshots-${{ matrix.os }}-${{ matrix.browser }}
path: application/src/main/webapp/cypress/screenshots
- uses: actions/upload-artifact@v1
if: always()
with:
name: container-videos-${{ matrix.os }}-${{ matrix.browser }}
path: application/src/main/webapp/cypress/videos

# helm-tests:
# name: Helm Tests
# runs-on: ubuntu-latest
Expand Down
59 changes: 30 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,30 @@ jobs:
# Push images
docker image push --all-tags quay.io/projectopenubl/searchpe
# helm:
# needs: [ prepare ]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# with:
# ref: master
# - uses: actions/setup-java@v3
# with:
# java-version: 17
# distribution: temurin
# cache: maven
# - uses: azure/setup-helm@v3
# - name: Release Helm
# run: |
# mvn package -DskipTests
# mvn process-resources
#
# helm plugin install https://github.com/chartmuseum/helm-push
# helm repo add \
# --username ${{ secrets.GITLAB_REGISTRY_USERNAME }} \
# --password ${{ secrets.GITLAB_REGISTRY_TOKEN }} \
# openubl https://gitlab.com/api/v4/projects/36554180/packages/helm/stable
# helm cm-push --force application/target/helm openubl
# helm:
# needs: [ prepare ]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# with:
# ref: master
# - uses: actions/setup-java@v3
# with:
# java-version: 17
# distribution: temurin
# cache: maven
# - uses: azure/setup-helm@v3
# - name: Release Helm
# run: |
# mvn package -DskipTests
# mvn process-resources
#
# helm plugin install https://github.com/chartmuseum/helm-push
# helm repo add \
# --username ${{ secrets.GITLAB_REGISTRY_USERNAME }} \
# --password ${{ secrets.GITLAB_REGISTRY_TOKEN }} \
# openubl https://gitlab.com/api/v4/projects/36554180/packages/helm/stable
# helm cm-push --force application/target/helm openubl

operator:
needs: [ prepare ]
Expand Down Expand Up @@ -152,20 +152,21 @@ jobs:
java-version: 17
distribution: temurin
cache: maven
- name: Setup other tools
run: |
sudo apt-get install -y groovy
- name: Prepare files
working-directory: searchpe
run: |
sudo apt-get install -y groovy
mvn package -DskipTests \
-Doperator.searchpe.image=quay.io/projectopenubl/searchpe:v${{ github.event.inputs.version }} \
-Dquarkus.operator-sdk.bundle.package-name=searchpe-operator \
-Dquarkus.operator-sdk.bundle.channels=alpha \
-Dquarkus.application.version=v${{ github.event.inputs.version }} \
-pl operator
groovy scripts/enrichCSV.groovy \
operator/target/bundle/searchpe-operator/manifests/searchpe-operator.clusterserviceversion.yaml \
${{ github.event.inputs.version }}
groovy scripts/enrichCSV.groovy operator/target/bundle/searchpe-operator/manifests/searchpe-operator.clusterserviceversion.yaml ${{ github.event.inputs.version }}
sed -i "/ annotations: ''/d" ./operator/target/bundle/searchpe-operator/manifests/searchpe-operator.clusterserviceversion.yaml
- name: Create PR community-operators
uses: project-openubl/.github/actions/pull-request-operator@master
with:
Expand Down
2 changes: 1 addition & 1 deletion application/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ searchpe.workspace.directory=workspace
searchpe.sunat.filter=ACTIVO
searchpe.sunat.chunkSize=50000
searchpe.sunat.watchDelay=15
searchpe.sunat.padronReducidoUrl=https://raw.githubusercontent.com/project-openubl/searchpe/master/src/test/resources/padron_reducido_ruc.zip
searchpe.sunat.padronReducidoUrl=https://raw.githubusercontent.com/project-openubl/searchpe/master/application/src/test/resources/padron_reducido_ruc.zip

searchpe.scheduled.cron=0 0 1 * * ?
searchpe.scheduled.cron-clean=0 0 6 * * ?
Expand Down
10 changes: 10 additions & 0 deletions application/src/main/webapp/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: "http://localhost:3000",
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
3 changes: 0 additions & 3 deletions application/src/main/webapp/cypress.json

This file was deleted.

22 changes: 22 additions & 0 deletions application/src/main/webapp/cypress/e2e/models/consulta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="cypress" />

export class ConsultaPage {
openPage(): void {
// Interceptors
cy.intercept("GET", "/api/contribuyentes/*").as("getContribuyentes");

// Open page
cy.visit("#/");
}

consultar(numeroDocumento: string): void {
this.openPage();

cy.get("input[name='filterText']")
.clear()
.type(numeroDocumento)
.type("{enter}");

cy.wait("@getContribuyentes");
}
}
Loading

0 comments on commit 10b5888

Please sign in to comment.