Skip to content

Commit

Permalink
Add example_data:generate task and run on deploying review apps
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailMcP committed Aug 2, 2023
1 parent 341c20a commit ac3cb1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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"
20 changes: 20 additions & 0 deletions lib/tasks/example_data.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ac3cb1b

Please sign in to comment.