From 993d2e732b1e455c1fa2936444e2422b5d882338 Mon Sep 17 00:00:00 2001 From: UDIT GAURAV <35391335+uditgaurav@users.noreply.github.com> Date: Mon, 15 Jun 2020 23:07:28 +0530 Subject: [PATCH] chore(feat): Add Github Action bot for litmus e2e runs on PR comment basis (#1540) Signed-off-by: Udit Gaurav --- .github/workflows/main.yml | 150 +++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000000..aa03329a107 --- /dev/null +++ b/.github/workflows/main.yml @@ -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 \ No newline at end of file