From f89c52e3d6b728218c210c92e08350384a5484e8 Mon Sep 17 00:00:00 2001 From: Mohsin Zaidi <2236875+smrz2001@users.noreply.github.com> Date: Tue, 23 Jan 2024 21:21:11 -0500 Subject: [PATCH] feat: post-deployment tests (#242) --- .github/workflows/cd-to-infra.yml | 7 ++++ .github/workflows/manual-deploy-to-infra.yml | 11 +++-- Makefile | 7 ++++ ci-scripts/schedule_tests.sh | 42 ++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100755 ci-scripts/schedule_tests.sh diff --git a/.github/workflows/cd-to-infra.yml b/.github/workflows/cd-to-infra.yml index 8966ee022..50d382167 100644 --- a/.github/workflows/cd-to-infra.yml +++ b/.github/workflows/cd-to-infra.yml @@ -65,10 +65,17 @@ jobs: elif [[ "${{ github.event.action }}" == "released" ]]; then DEPLOY_ENV="prod" fi + # Run fast tests post-deployment + TEST_SELECTOR="fast" else DEPLOY_ENV="qa" + # Run all tests post-deployment to QA + TEST_SELECTOR="." fi if [[ -n "$DEPLOY_ENV" ]]; then + # Schedule deployment make DEPLOY_ENV="$DEPLOY_ENV" DEPLOY_TAG=${{ needs.publish.outputs.deploy_tag }} schedule-k8s-deployment + # Schedule post-deployment tests + make DEPLOY_ENV="$DEPLOY_ENV" TEST_SELECTOR="$TEST_SELECTOR" schedule-tests fi echo "DEPLOY_ENV is $DEPLOY_ENV" diff --git a/.github/workflows/manual-deploy-to-infra.yml b/.github/workflows/manual-deploy-to-infra.yml index 28db88c58..71fc1ab73 100644 --- a/.github/workflows/manual-deploy-to-infra.yml +++ b/.github/workflows/manual-deploy-to-infra.yml @@ -26,12 +26,17 @@ env: jobs: deploy: runs-on: ubuntu-latest + env: + DEPLOY_ENV: ${{ github.event.inputs.environment }} + DEPLOY_TAG: ${{ github.event.inputs.tag }} steps: - uses: actions/checkout@v3 - name: Schedule k8s deployment - env: - DEPLOY_ENV: ${{ github.event.inputs.environment }} - DEPLOY_TAG: ${{ github.event.inputs.tag }} run: make schedule-k8s-deployment + - + name: Schedule post-deployment tests + run: | + # Just run "fast" tests for manual deployments + make TEST_SELECTOR="fast" schedule-tests diff --git a/Makefile b/Makefile index ab96d5f65..0252a1d90 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,9 @@ DEPLOY_TAG ?= latest # Whether or not this is a manual deployment MANUAL_DEPLOY ?= false +# Test selector +TEST_SELECTOR ?= . + .PHONY: all all: build check-fmt check-clippy test @@ -98,3 +101,7 @@ schedule-ecs-deployment: .PHONY: schedule-k8s-deployment schedule-k8s-deployment: ./ci-scripts/schedule_k8s_deploy.sh "${DEPLOY_ENV}" "${DEPLOY_TAG}" + +.PHONY: schedule-tests +schedule-tests: + ./ci-scripts/schedule_tests.sh "${DEPLOY_ENV}" "${TEST_SELECTOR}" diff --git a/ci-scripts/schedule_tests.sh b/ci-scripts/schedule_tests.sh new file mode 100755 index 000000000..71b68b95b --- /dev/null +++ b/ci-scripts/schedule_tests.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +id=$(uuidgen) +job_id=$(uuidgen) +# Schedule tests for 10 minutes in the future to allow the network to stabilize. This assumes that the deployment is +# successful with the right image being deployed, which might not always be the case if the deployment fails for some +# reason. In the future, this can be done better via the CD manager, which will check for the network being ready with +# the right image before scheduling tests. +now=$(date +%s%N -d "10 minutes") +ttl=$(date +%s -d "14 days") +network=${1-dev} +test_selector=${2-.} + +docker run --rm -i \ + -e "AWS_REGION=$AWS_REGION" \ + -e "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" \ + -e "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" \ + -v ~/.aws:/root/.aws \ + -v "$PWD":/aws \ + amazon/aws-cli dynamodb put-item --table-name "ceramic-$network-ops" --item \ + "{ \ + \"id\": {\"S\": \"$id\"}, \ + \"job\": {\"S\": \"$job_id\"}, \ + \"ts\": {\"N\": \"$now\"}, \ + \"ttl\": {\"N\": \"$ttl\"}, \ + \"stage\": {\"S\": \"queued\"}, \ + \"type\": {\"S\": \"workflow\"}, \ + \"params\": { \ + \"M\": { \ + \"name\": {\"S\": \"Post-Deployment Tests\"}, \ + \"org\": {\"S\": \"3box\"}, \ + \"repo\": {\"S\": \"ceramic-tests\"}, \ + \"ref\": {\"S\": \"main\"}, \ + \"workflow\": {\"S\": \"run-durable.yml\"}, \ + \"inputs\": { \ + \"M\": { \ + \"test_selector\": {\"S\": \"$test_selector\"} \ + } \ + } \ + } \ + } \ + }"