diff --git a/ansible/roles_ocp_workloads/ocp4_workload_coolstore_apac_summit/templates/cicd/unit-test-task.yaml.j2 b/ansible/roles_ocp_workloads/ocp4_workload_coolstore_apac_summit/templates/cicd/unit-test-task.yaml.j2 new file mode 100644 index 00000000000..d91aa7c1f26 --- /dev/null +++ b/ansible/roles_ocp_workloads/ocp4_workload_coolstore_apac_summit/templates/cicd/unit-test-task.yaml.j2 @@ -0,0 +1,56 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: unit-test + namespace: "{{ ocp4_workload_coolstore_apac_summit_coolstore_namespace }}" +spec: + params: + - default: 'docker.io/sonarsource/sonar-scanner-cli:latest' + name: scanImage + type: string + - default: >- + https://gitea.apps.cluster-hlw9j.sandbox2180.opentlc.com/dev-user/coolstore-microservice + name: gitRepositoryUrl + type: string + - default: main + name: gitRepositoryRevision + type: string + - default: 'true' + name: verbose + type: string + steps: + - image: 'alpine/git:v2.26.2' + name: git-checkout + resources: {} + script: | + #!/usr/bin/env sh + + set -eu -o pipefail + + if [[ "$(params.verbose)" == "true" ]] ; then + set -x + echo "**** Cloning $(params.gitRepositoryUrl) into $(pwd)/repository" + fi + + git clone "$(params.gitRepositoryUrl)" $(pwd)/repository + cd repository + git checkout "$(params.gitRepositoryRevision)" + volumeMounts: + - mountPath: /workspace/repository + name: repository + workingDir: /workspace + - name: unit-test + image: docker.io/node:current-alpine + script: | + set -x + npm i jest-cli@21.2.1 + npm i angular-mocks@1.6.6 + cd coolstore-ui + npm test + volumeMounts: + - mountPath: /workspace/repository + name: repository + workingDir: /workspace/repository + volumes: + - emptyDir: {} + name: repository diff --git a/ansible/roles_ocp_workloads/ocp4_workload_coolstore_apac_summit/templates/cicd/web-ui-ci-pipeline.yaml.j2 b/ansible/roles_ocp_workloads/ocp4_workload_coolstore_apac_summit/templates/cicd/web-ui-ci-pipeline.yaml.j2 index 606e771a5ac..9586f0f83ff 100644 --- a/ansible/roles_ocp_workloads/ocp4_workload_coolstore_apac_summit/templates/cicd/web-ui-ci-pipeline.yaml.j2 +++ b/ansible/roles_ocp_workloads/ocp4_workload_coolstore_apac_summit/templates/cicd/web-ui-ci-pipeline.yaml.j2 @@ -39,7 +39,7 @@ spec: kind: ClusterTask name: openshift-client runAfter: - - scan-code + - unit-test - name: generate-tag runAfter: - image-check @@ -122,6 +122,17 @@ spec: taskRef: kind: Task name: scan-code + - name: unit-test + params: + - name: gitRepositoryUrl + value: $(params.GIT_MICROSERVICES_REPO_URL) + - name: gitRepositoryRevision + value: $(params.GIT_REPO_REVISION) + taskRef: + kind: Task + name: unit-test + runAfter: + - scan-code workspaces: - name: workspace