-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(feat): Add Github Action bot for litmus e2e runs on PR comment …
…basis (#1540) Signed-off-by: Udit Gaurav <uditgaurav@gmail.com>
- Loading branch information
1 parent
57f88a5
commit 993d2e7
Showing
1 changed file
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
name: Litmus-CI | ||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
tests: | ||
if: contains(github.event.comment.html_url, '/pull/') && startsWith(github.event.comment.body, '/run-e2e') | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Notification for e2e Start | ||
uses: peter-evans/create-or-update-comment@v1 | ||
with: | ||
comment-id: "${{ github.event.comment.id }}" | ||
body: | | ||
**** | ||
**Test Status:** The e2e test 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 | ||
with: | ||
route: GET /repos/:repo/pulls/:pull_number/commits | ||
repo: ${{ github.repository }} | ||
pull_number: ${{ github.event.issue.number }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: set commit to output | ||
id: getcommit | ||
run: | | ||
prsha=$(echo $response | jq '.[-1].sha' | tr -d '"') | ||
echo "::set-output name=sha::$prsha" | ||
env: | ||
response: ${{ steps.get_PR_commits.outputs.data }} | ||
|
||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{steps.getcommit.outputs.sha}} | ||
|
||
- name: Build docker image | ||
run: | | ||
sudo docker build -f build/ansible-runner/Dockerfile -t litmuschaos/ansible-runner:ci . | ||
#Install and configure a kind cluster | ||
- name: Installing Prerequisites (KinD Cluster) | ||
uses: engineerd/setup-kind@v0.4.0 | ||
with: | ||
version: "v0.7.0" | ||
|
||
- name: Configuring and testing the Installation | ||
run: | | ||
kubectl cluster-info --context kind-kind | ||
kind get kubeconfig --internal >$HOME/.kube/config | ||
kubectl get nodes | ||
- name: Load image on the nodes of the cluster | ||
run: | | ||
kind load docker-image --name=kind litmuschaos/ansible-runner:ci | ||
- name: Deploy a sample application for chaos injection | ||
run: | | ||
kubectl apply -f https://raw.githubusercontent.com/mayadata-io/chaos-ci-lib/master/app/nginx.yml | ||
sleep 30 | ||
- name: Setting up kubeconfig ENV for Github Chaos Action | ||
run: echo ::set-env name=KUBE_CONFIG_DATA::$(base64 -w 0 ~/.kube/config) | ||
|
||
- name: Running Litmus pod delete chaos experiment | ||
if: startsWith(github.event.comment.body, '/run-e2e-pod-delete') || startsWith(github.event.comment.body, '/run-e2e-all') | ||
uses: mayadata-io/github-chaos-actions@v0.1.1 | ||
env: | ||
INSTALL_LITMUS: true | ||
EXPERIMENT_NAME: pod-delete | ||
EXPERIMENT_IMAGE: litmuschaos/ansible-runner | ||
EXPERIMENT_IMAGE_TAG: ci | ||
IMAGE_PULL_POLICY: IfNotPresent | ||
LITMUS_CLEANUP: true | ||
|
||
- name: Running container kill chaos experiment | ||
if: startsWith(github.event.comment.body, '/run-e2e-container-kill') || startsWith(github.event.comment.body, '/run-e2e-all') | ||
uses: mayadata-io/github-chaos-actions@v0.1.1 | ||
env: | ||
INSTALL_LITMUS: true | ||
EXPERIMENT_NAME: container-kill | ||
EXPERIMENT_IMAGE: litmuschaos/ansible-runner | ||
EXPERIMENT_IMAGE_TAG: ci | ||
IMAGE_PULL_POLICY: IfNotPresent | ||
LITMUS_CLEANUP: true | ||
|
||
- name: Running node-cpu-hog chaos experiment | ||
if: startsWith(github.event.comment.body, '/run-e2e-node-cpu-hog') || startsWith(github.event.comment.body, '/run-e2e-all') | ||
uses: mayadata-io/github-chaos-actions@v0.1.1 | ||
env: | ||
INSTALL_LITMUS: true | ||
EXPERIMENT_NAME: node-cpu-hog | ||
EXPERIMENT_IMAGE: litmuschaos/ansible-runner | ||
EXPERIMENT_IMAGE_TAG: ci | ||
IMAGE_PULL_POLICY: IfNotPresent | ||
LITMUS_CLEANUP: true | ||
|
||
- name: Running node-memory-hog chaos experiment | ||
if: startsWith(github.event.comment.body, '/run-e2e-node-memory-hog') || startsWith(github.event.comment.body, '/run-e2e-all') | ||
uses: mayadata-io/github-chaos-actions@v0.1.1 | ||
env: | ||
INSTALL_LITMUS: true | ||
EXPERIMENT_NAME: node-memory-hog | ||
EXPERIMENT_IMAGE: litmuschaos/ansible-runner | ||
EXPERIMENT_IMAGE_TAG: ci | ||
IMAGE_PULL_POLICY: IfNotPresent | ||
LITMUS_CLEANUP: true | ||
|
||
- name: Check the test run | ||
if: | | ||
startsWith(github.event.comment.body, '/run-e2e-pod-delete') || startsWith(github.event.comment.body, '/run-e2e-container-kill') || | ||
startsWith(github.event.comment.body, '/run-e2e-node-cpu-hog') || startsWith(github.event.comment.body, '/run-e2e-node-memory-hog') | ||
run: | | ||
echo ::set-env name=TEST_RUN::true | ||
- name: Check for all the jobs are succeeded | ||
if: ${{ success() && env.TEST_RUN == 'true' }} | ||
uses: peter-evans/create-or-update-comment@v1 | ||
with: | ||
comment-id: "${{ github.event.comment.id }}" | ||
body: | | ||
**Test Result:** All tests are passed | ||
reactions: hooray | ||
|
||
- name: Check for any job failed | ||
if: ${{ failure() }} | ||
uses: peter-evans/create-or-update-comment@v1 | ||
with: | ||
comment-id: "${{ github.event.comment.id }}" | ||
body: | | ||
**Test Failed:** Some tests are failed please check | ||
reactions: confused | ||
|
||
- name: Deleting KinD cluster | ||
if: ${{ always() }} | ||
run: kind delete cluster | ||
|
||
- name: Check if any test ran or not | ||
if: env.TEST_RUN != 'true' | ||
uses: peter-evans/create-or-update-comment@v1 | ||
with: | ||
comment-id: "${{ github.event.comment.id }}" | ||
body: | | ||
**Test Result:** No test found | ||
reactions: eyes |