From ac3cb1ba9670fcbafbc2d4bad5762f3611be56f7 Mon Sep 17 00:00:00 2001 From: Abigail McPhillips Date: Wed, 2 Aug 2023 17:02:16 +0300 Subject: [PATCH] Add example_data:generate task and run on deploying review apps --- .github/actions/deploy/action.yml | 6 ++++++ lib/tasks/example_data.rake | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 lib/tasks/example_data.rake diff --git a/.github/actions/deploy/action.yml b/.github/actions/deploy/action.yml index 73926553..c96f060a 100644 --- a/.github/actions/deploy/action.yml +++ b/.github/actions/deploy/action.yml @@ -38,6 +38,7 @@ runs: echo "key_vault_name=$(jq -r '.key_vault_name' $TFVARS)" >> $GITHUB_ENV echo "key_vault_app_secret_name=$(jq -r '.key_vault_app_secret_name' $TFVARS)" >> $GITHUB_ENV echo "key_vault_infra_secret_name=$(jq -r '.key_vault_infra_secret_name' $TFVARS)" >> $GITHUB_ENV + echo "namespace=$(jq -r '.namespace' $TFVARS)" >> $GITHUB_ENV if [ -n "${{ inputs.pr-number }}" ]; then APP_NAME=pr-${{ inputs.pr-number }} @@ -111,3 +112,8 @@ runs: run: | az aks get-credentials -g ${{ env.cluster_rg }} -n ${{ env.cluster_name }} make install-konduit + + - name: Generate example data + shell: bash + if: inputs.environment == 'review' + run: kubectl exec -n ${{ env.namespace }} deployment/check-childrens-barred-list-${APP_NAME} -- /bin/sh -c "cd /app && bundle exec rails example_data:generate" diff --git a/lib/tasks/example_data.rake b/lib/tasks/example_data.rake new file mode 100644 index 00000000..77c93208 --- /dev/null +++ b/lib/tasks/example_data.rake @@ -0,0 +1,20 @@ +namespace :example_data do + desc "Create example data for testing" + task generate: :environment do + if HostingEnvironment.production? + raise "THIS TASK CANNOT BE RUN IN PRODUCTION" + end + + if ChildrensBarredListEntry.any? + puts "Noop as DB already contains data" + exit + end + + # Running `bundle exec rails db:migrate example_data:generate` can sometimes + # use cached column information. This forces rails to reload column + # information before attempting to generate factories + ChildrensBarredListEntry.reset_column_information + + FactoryBot.create(:childrens_barred_list_entry, date_of_birth: Date.new(1980, 1, 1)) + end +end