Skip to content

Commit

Permalink
Add smoke test post deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
RMcVelia committed Jan 17, 2024
1 parent 8e37e96 commit 81e1635
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 47 deletions.
46 changes: 5 additions & 41 deletions .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,47 +86,11 @@ runs:
TF_VAR_azure_sp_credentials: ${{ inputs.azure-credentials }}
CONFIRM_PRODUCTION: true

- name: Set up environment variables
shell: bash
run: |
case ${{ env.cluster }} in
test)
echo "cluster_rg=s189t01-tsc-ts-rg" >> $GITHUB_ENV
echo "cluster_name=s189t01-tsc-test-aks" >> $GITHUB_ENV
;;
production)
echo "cluster_rg=s189p01-tsc-pd-rg" >> $GITHUB_ENV
echo "cluster_name=s189p01-tsc-production-aks" >> $GITHUB_ENV
;;
*)
echo "unknown cluster"
;;
esac
- name: Install kubectl
uses: azure/setup-kubectl@v3
with:
version: "v1.26.1" # default is latest stable

- name: K8 setup
shell: bash
run: |
az aks get-credentials -g ${{ env.cluster_rg }} -n ${{ env.cluster_name }}
make install-konduit
# review app seeded?
# - name: Generate example data
# shell: bash
# if: inputs.environment == 'review'
# run: kubectl exec -n ${{ env.namespace }} deployment/teacher-relocation-payment-${APP_NAME} -- /bin/sh -c "cd /app && bin/rails RAILS_ENV=test db:schema:load && bin/rails RAILS_ENV=test db:seed"

# - name: Run Smoke Tests for ${{ inputs.environment }}
# uses: ./.github/actions/smoke-test_v2/
# with:
# environment: ${{ inputs.environment }}
# app-env: ${{ env.aks_app_environment }}
# pr-number: ${{ inputs.pr-number }}
# slack-webhook: ${{ inputs.slack-webhook }}
- name: Run Smoke Tests for ${{ inputs.environment }}
uses: ./.github/actions/smoke-test
with:
current-commit-sha: ${{ inputs.sha }}
url: ${{ steps.set_env_var.outputs.deploy_url }}

# - name: Notify Slack channel on job failure
# if: ${{ failure() && github.ref == 'refs/heads/main' }}
Expand Down
18 changes: 18 additions & 0 deletions .github/actions/smoke-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: smoke-test
description: runs smoke tests

inputs:
url:
description: The URL of the deployed environment.
required: true
current-commit-sha:
description: The sha of the current commit
required: true

runs:
using: composite

steps:
- name: Run smoke tests
shell: bash
run: bin/smoke ${{ inputs.url }} ${{ inputs.current-commit-sha }}
37 changes: 31 additions & 6 deletions bin/smoke
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
#!/usr/bin/env sh
#
# Application smoke test script
#
#!/usr/bin/env bash

set -e
url=$1
if [[ -z $url ]]; then
echo `date`" - smoke test failed (URL is missing)"
exit 1
fi
response=$(curl -sL $url/healthcheck/version)
response_sha=\"$(cut -d " " -f 4 <<< $response)\"

bundle exec rspec spec/features/smoke_spec.rb --tag smoke_test
current_commit_sha=\"$2\"
if [[ -z $current_commit_sha ]]; then
echo `date`" - smoke test failed (head sha is missing)"
exit 1
fi

if [[ $response_sha == $current_commit_sha ]]; then
echo "✅ Correct version deployed"
else
echo "Fail: healthcheck sha is $response_sha but current commit is $current_commit_sha"
exit 1
fi

response=$(curl -sL $url/healthcheck/database)

database_connected=$(cut -d " " -f 2 <<< $response)

if [[ $database_connected == 'PASSED' ]]; then
echo "✅ Database is connected"
else
echo "Fail: database is not connected"
exit 1
fi

0 comments on commit 81e1635

Please sign in to comment.