chore (litmus-portal): Added Enhancements in workflow for Testing using Github Actions. (#2388)

* Added All Action Configs.

Signed-off-by: Vedant Shrotria <vedant.shrotria@mayadata.io>

* Removed Extra manifest.

Signed-off-by: Vedant Shrotria <vedant.shrotria@mayadata.io>

* Added minor fix for deprecated set-env.

Signed-off-by: Jonsy13 <vedant.shrotria@mayadata.io>
This commit is contained in:
VEDANT SHROTRIA 2021-01-08 15:00:39 +05:30 committed by GitHub
parent c5723964aa
commit cf37a796ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 136 additions and 24 deletions

31
.github/Readme.md vendored Normal file
View File

@ -0,0 +1,31 @@
# On-demand E2E Tests Commands
### Here are the different commands that can be used for triggering Tests using github-actions:
<table>
<tr>
<th>Commands</th>
<th>Description</th>
<th>Time Taken</th>
</tr>
<tr>
<td>/run-unit</td>
<td>This command is used for executing all unit tests using Cypress.</td>
<td>Moderate</td>
</tr>
<tr>
<td>/run-e2e-AuthTests</td>
<td>This Command is used for executing all Auth-Related e2e-tests (Login and Welcome Modal functionalities) using Cypress by building and deploying the respective PR in a KinD Cluster.</td>
<td>Depends on Changes in the PR ( If changes are done in frontend, It can take more than 11 mins.), moderate in other cases.</td>
</tr>
<tr>
<td>/run-e2e-Settings</td>
<td>This Command is used for executing all Settings and Teaming Related e2e-tests using Cypress by building and deploying the respective PR in a KinD Cluster.</td>
<td>Depends on Changes in the PR ( If changes are done in frontend, It can take more than 11 mins.), moderate in other cases.</td>
</tr>
<tr>
<td>/run-e2e-all</td>
<td>This Command is used for executing all e2e-tests using Cypress by building and deploying the respective PR in a KinD Cluster.</td>
<td>Depends on Changes in the PR ( If changes are done in frontend, It can take more than 11 mins.), moderate in other cases.</td>
</tr>
</table>

25
.github/filter_and_build.sh vendored Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
set -e
working_dir="litmus-portal"
# Array of Image Names
image_names=("litmusportal-frontend:ci" "litmusportal-server:ci" "litmusportal-auth-server:ci")
# Array of DockerFile Paths
dockerfile_paths=("frontend" "graphql-server/build" "authentication")
# Array of directories, for which images have to be build if changed
directory_array=("frontend" "graphql-server" "authentication")
# Building the images on the basic of changes in paths
for i in "${!directory_array[@]}"
do
current_dir=$(echo "$working_dir/${directory_array[$i]}")
nofchanges=$(echo $changed_data | jq -r '[.[]."filename"] | join("\n")' | tr -d '"' | grep ^$current_dir | wc -l)
if [ $nofchanges != 0 ]
then
docker build $current_dir -t litmuschaos/${image_names[$i]} -f $working_dir/${dockerfile_paths[$i]}/Dockerfile
kind load docker-image litmuschaos/${image_names[$i]} --name kind
fi
done

View File

@ -8,7 +8,7 @@ on:
jobs:
tests:
if: contains(github.event.comment.html_url, '/pull/') && startsWith(github.event.comment.body, '/run')
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Notification for Starting Testing.
@ -18,7 +18,6 @@ jobs:
body: |
****
**Test Status:** The testing has been started please wait for the results ...
#Using the last commit id of pull request
- uses: octokit/request-action@v2.x
id: get_PR_commits
@ -40,20 +39,73 @@ jobs:
- uses: actions/checkout@v2
with:
ref: ${{steps.getcommit.outputs.sha}}
fetch-depth: 0
- uses: octokit/request-action@v2.x
if: startsWith(github.event.comment.body, '/run-e2e')
name: Getting the files changed in current Pull-Request
id: get_files
with:
route: GET /repos/:repo/pulls/:pull_number/files
repo: ${{ github.repository }}
pull_number: ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setting up KinD Cluster
if: startsWith(github.event.comment.body, '/run-e2e')
uses: engineerd/setup-kind@v0.5.0
with:
version: "v0.7.0"
- name: Configuring and Testing the Cluster Installation
if: startsWith(github.event.comment.body, '/run-e2e')
run: |
kubectl cluster-info --context kind-kind
kind get kubeconfig --internal >$HOME/.kube/config
kubectl get nodes
kubectl get pods -n kube-system
- name: Filtering the file paths and building images on the basic of changed files
if: startsWith(github.event.comment.body, '/run-e2e')
run: |
chmod 755 ./.github/filter_and_build.sh
./.github/filter_and_build.sh
env:
changed_data: ${{steps.get_files.outputs.data}}
- name: Deploying the litmus-portal for E2E testing
if: startsWith(github.event.comment.body, '/run-e2e')
run: |
wget https://raw.githubusercontent.com/litmuschaos/litmus/master/litmus-portal/cluster-k8s-manifest.yml
sed -i 's/Always/IfNotPresent/g' cluster-k8s-manifest.yml
kubectl apply -f cluster-k8s-manifest.yml
kubectl get pods -n litmus
kubectl get deployments -o wide -n litmus
kubectl wait --for=condition=Ready pods --all --namespace litmus --timeout=120s
- name: Getting the ENV variables for using while testing
if: startsWith(github.event.comment.body, '/run-e2e')
run: |
export frontendPodName=$(kubectl get pods -l component=litmusportal-frontend --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' -n litmus)
export frontendPodPort=$(kubectl get pod $frontendPodName --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}' --namespace litmus)
kubectl port-forward $frontendPodName -n litmus 3001:$frontendPodPort &
- name: Setting Dependencies
uses: actions/setup-node@v1
if: startsWith(github.event.comment.body, '/run-unit')
with:
working-directory: litmus-portal/frontend
- name: Installing Dependencies for frontend.
if: startsWith(github.event.comment.body, '/run-unit')
run: |
HUSKY_SKIP_INSTALL=1 npm i
working-directory: litmus-portal/frontend
# Step for running all frontend Cypress unit tests.
# Step for running all frontend Cypress unit tests.
- name: Starting cypress unit tests
if: startsWith(github.event.comment.body, '/run-unit') || startsWith(github.event.comment.body, '/run-all')
if: startsWith(github.event.comment.body, '/run-unit')
uses: cypress-io/github-action@v2
continue-on-error: false
with:
@ -63,42 +115,42 @@ jobs:
# Cloning the litmus-e2e repo for E2E tests.
- name: Cloning the litmus-e2e Repo
if: startsWith(github.event.comment.body, '/run-e2e') || startsWith(github.event.comment.body, '/run-all')
if: startsWith(github.event.comment.body, '/run-e2e')
run: |
git clone https://github.com/litmuschaos/litmus-e2e.git -b litmus-portal
# Starting the React-Server for E2E tests.
- name: Starting the server
if: startsWith(github.event.comment.body, '/run-e2e') || startsWith(github.event.comment.body, '/run-all')
run: |
CHOKIDAR_USEPOLLING=1 npm start &
working-directory: litmus-portal/frontend
- name: Installing Cypress and running tests for login page
if: startsWith(github.event.comment.body, '/run-e2e-login')
- name: Running basic tests (Login and Welcome Modal Tests)
if: startsWith(github.event.comment.body, '/run-e2e-AuthTests') || startsWith(github.event.comment.body, '/run-e2e')
uses: cypress-io/github-action@v2
continue-on-error: false
with:
wait-on: http://localhost:3000
spec: cypress/integration/Login/*
spec: cypress/integration/Basic_Setup/**/*.spec.js
working-directory: litmus-e2e/CypressE2E/
config-file: cypress.prod.json
- name: Install Cypress and run all tests
if: startsWith(github.event.comment.body, '/run-e2e-all') || startsWith(github.event.comment.body, '/run-all')
- name: Teaming and Account Settings Tests
if: startsWith(github.event.comment.body, '/run-e2e-Settings')
uses: cypress-io/github-action@v2
continue-on-error: false
with:
wait-on: http://localhost:3000
spec: cypress/integration/**/*
spec: cypress/integration/Parallel_Tests/Account_Settings/*.spec.js
working-directory: litmus-e2e/CypressE2E/
config-file: cypress.prod.json
- name: Run all E2E tests
if: startsWith(github.event.comment.body, '/run-e2e-all')
uses: cypress-io/github-action@v2
continue-on-error: false
with:
spec: cypress/integration/Parallel_Tests/**/*.spec.js
working-directory: litmus-e2e/CypressE2E
config-file: cypress.prod.json
- name: Check the test run
if: |
startsWith(github.event.comment.body, '/run-unit') || startsWith(github.event.comment.body, '/run-all') ||
startsWith(github.event.comment.body, '/run-e2e-login') || startsWith(github.event.comment.body, '/run-e2e-workflow') ||
startsWith(github.event.comment.body, '/run-e2e-all')
startsWith(github.event.comment.body, '/run-unit') || startsWith(github.event.comment.body, '/run-e2e')
run: |
echo ::set-env name=TEST_RUN::true
echo "TEST_RUN=true" >> $GITHUB_ENV
- name: Check for all the jobs are succeeded
if: ${{ success() && env.TEST_RUN == 'true' }}
@ -136,6 +188,10 @@ jobs:
env:
RUN_ID: ${{ github.run_id }}
- name: Deleting KinD cluster
if: startsWith(github.event.comment.body, '/run-e2e')
run: kind delete cluster
merge:
if: contains(github.event.comment.html_url, '/pull/') && startsWith(github.event.comment.body, '/merge')
runs-on: ubuntu-latest