From 15b2f53402b2b48b59d104db4333e3865911319e Mon Sep 17 00:00:00 2001 From: RMcVelia Date: Fri, 1 Dec 2023 11:21:01 +0000 Subject: [PATCH] Add smoke test post deployment --- .github/actions/deploy/action.yml | 44 ++---------------- .github/actions/smoke-test/action.yml | 46 +++++++++++++++++++ .github/workflows/smoke-test.yml | 66 +++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 40 deletions(-) create mode 100644 .github/actions/smoke-test/action.yml create mode 100644 .github/workflows/smoke-test.yml diff --git a/.github/actions/deploy/action.yml b/.github/actions/deploy/action.yml index e9967d93..ab4704b6 100644 --- a/.github/actions/deploy/action.yml +++ b/.github/actions/deploy/action.yml @@ -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 + - name: Run Smoke Tests for ${{ inputs.environment }} + uses: ./.github/workflows/smoke-test.yml 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 }} + environment: ${{ inputs.environment }} + url: ${{ steps.set_env_var.outputs.deploy_url }} # - name: Notify Slack channel on job failure # if: ${{ failure() && github.ref == 'refs/heads/main' }} diff --git a/.github/actions/smoke-test/action.yml b/.github/actions/smoke-test/action.yml new file mode 100644 index 00000000..221b99d2 --- /dev/null +++ b/.github/actions/smoke-test/action.yml @@ -0,0 +1,46 @@ +name: smoke-test +description: runs smoke tests + +inputs: + environment: + description: Environment to run tests in + required: true + url: + description: APP URL + required: true + +runs: + using: composite + services: + postgres: + image: postgres:11-alpine + ports: + - '5432:5432' + env: + POSTGRES_DB: rails_test + POSTGRES_USER: rails + POSTGRES_PASSWORD: password + env: + RAILS_ENV: test + DATABASE_URL: 'postgres://rails:password@localhost:5432/rails_test' + GOVUK_NOTIFY_API_KEY: dummy + GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID: dummy + + steps: + - name: Set up Ruby 3.2.2 + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2.2 + + - name: Bundle smoke test gems + shell: bash + run: | + gem install bundler + echo 'gem "rspec"' >> Gemfile + bundle + + - name: Run smoke tests + shell: bash + run: bin/smoke + env: + SMOKE_URL: ${{ inputs.url }} diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml new file mode 100644 index 00000000..c9576d45 --- /dev/null +++ b/.github/workflows/smoke-test.yml @@ -0,0 +1,66 @@ +name: smoke-test +description: runs smoke tests + +on: + workflow_call: + inputs: + environment: + description: Environment to run tests in + required: true + url: + description: APP URL + required: true + +jobs: + smoke-test: + runs_on: ubuntu-latest + services: + postgres: + image: postgres:11-alpine + ports: + - '5432:5432' + env: + POSTGRES_DB: rails_test + POSTGRES_USER: rails + POSTGRES_PASSWORD: password + env: + RAILS_ENV: test + DATABASE_URL: 'postgres://rails:password@localhost:5432/rails_test' + GOVUK_NOTIFY_API_KEY: dummy + GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID: dummy + + steps: + - name: Checkout code + uses: actions/checkout@v4 + # - name: Setup Node.js + # uses: actions/setup-node@v4 + # with: + # node-version: '18.18.2' + # - name: Setup yarn + # run: npm install -g yarn + # - name: Install Node packages + # run: yarn install + - name: Set up Ruby 3.2.2 + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2.2 + # - name: Precompile assets + # run: bundle exec rails assets:precompile + # - name: Set up database schema + # run: bin/rails db:schema:load + # - name: Copy env file + # run: cp .env.example .env + + + - name: Bundle smoke test gems + shell: bash + run: | + gem install bundler + echo 'gem "rspec"' >> Gemfile + bundle + + - name: Run smoke tests + shell: bash + run: bin/smoke + env: + SMOKE_URL: ${{ inputs.url }}