updated workflow

This commit is contained in:
CocoByte 2024-07-22 16:38:25 -06:00
parent 9b079811c8
commit 9b65879a4f
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F

View file

@ -31,72 +31,47 @@ on:
- rjm - rjm
- dk - dk
jobs: jobs:
connect-to-service: reset-db:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
CF_USERNAME: CF_${{ github.event.inputs.environment }}_USERNAME CF_USERNAME: CF_${{ github.event.inputs.environment }}_USERNAME
CF_PASSWORD: CF_${{ github.event.inputs.environment }}_PASSWORD CF_PASSWORD: CF_${{ github.event.inputs.environment }}_PASSWORD
steps: steps:
# - name: Delete existing data for ${{ github.event.inputs.environment }} - name: Drop Tables for ${{ github.event.inputs.environment }}
# uses: cloud-gov/cg-cli-tools@main uses: cloud-gov/cg-cli-tools@main
# with: with:
# cf_username: ${{ secrets[env.CF_USERNAME] }} cf_username: ${{ secrets[env.CF_USERNAME] }}
# cf_password: ${{ secrets[env.CF_PASSWORD] }} cf_password: ${{ secrets[env.CF_PASSWORD] }}
# cf_org: cisa-dotgov cf_org: cisa-dotgov
# cf_space: ${{ github.event.inputs.environment }} cf_space: ${{ github.event.inputs.environment }}
# cf_command: "run-task getgov-${{ github.event.inputs.environment }} --command 'python manage.py flush --no-input' --name flush" cf_command: "run-task getgov-${{ github.event.inputs.environment }} --command 'python manage.py drop_tables --no-input' --name flush"
# - name: Target organization and space - name: Run Django migrations for ${{ github.event.inputs.environment }}
# run: | uses: cloud-gov/cg-cli-tools@main
# cf target -o cisa-dotgov -s nl with:
cf_username: ${{ secrets[env.CF_USERNAME] }}
cf_password: ${{ secrets[env.CF_PASSWORD] }}
cf_org: cisa-dotgov
cf_space: ${{ github.event.inputs.environment }}
cf_command: "run-task getgov-${{ github.event.inputs.environment }} --command 'python manage.py migrate' --name migrate"
- name: Connect to service - name: Run fixtures for ${{ github.event.inputs.environment }}
id: connect uses: cloud-gov/cg-cli-tools@main
run: | with:
cf connect-to-service -no-client getgov-${{ github.event.inputs.environment }} getgov-${{ github.event.inputs.environment }}-database > connection_info.txt cf_username: ${{ secrets[env.CF_USERNAME] }}
cat connection_info.txt cf_password: ${{ secrets[env.CF_PASSWORD] }}
cf_org: cisa-dotgov
cf_space: ${{ github.event.inputs.environment }}
cf_command: "run-task getgov-${{ github.event.inputs.environment }} --command 'python manage.py load' --name load"
- name: Extract connection details - name: Create cache table for ${{ github.event.inputs.environment }}
id: extract uses: cloud-gov/cg-cli-tools@main
run: | with:
port=$(grep -oP 'port:\s*\K\d+' connection_info.txt) cf_username: ${{ secrets[env.CF_USERNAME] }}
username=$(grep -oP 'user:\s*\K\w+' connection_info.txt) cf_password: ${{ secrets[env.CF_PASSWORD] }}
broker_name=$(grep -oP 'dbname:\s*\K\w+' connection_info.txt) cf_org: cisa-dotgov
echo "::set-output name=port::$port" cf_space: ${{ github.event.inputs.environment }}
echo "::set-output name=username::$username" cf_command: "run-task getgov-${{ github.event.inputs.environment }} --command 'python manage.py createcachetable' --name createcachetable"
echo "::set-output name=broker_name::$broker_name"
- name: Connect to PostgreSQL
run: |
psql -h localhost -p ${{ steps.extract.outputs.port }} -U ${{ steps.extract.outputs.username }} -d ${{ steps.extract.outputs.broker_name }}
env:
PGPASSWORD: ${{ secrets.PG_PASSWORD }}
- name: Get table names
id: get_tables
run: |
tables=$(psql -h localhost -p ${{ steps.extract.outputs.port }} -U ${{ steps.extract.outputs.username }} -d ${{ steps.extract.outputs.broker_name }} -c "\dt" -t | awk '{print $3}')
echo "::set-output name=tables::$tables"
- name: Drop all tables
run: |
for table in ${{ steps.get_tables.outputs.tables }}
do
psql -h localhost -p ${{ steps.extract.outputs.port }} -U ${{ steps.extract.outputs.username }} -d ${{ steps.extract.outputs.broker_name }} -c "DROP TABLE IF EXISTS $table CASCADE;"
done
env:
PGPASSWORD: ${{ secrets.PG_PASSWORD }}
# - name: Migrate
# run: |
# cf ssh getgov-${{ github.event.inputs.environment }} -c "/tmp/lifecycle/shell ./manage.py migrate"
# - name: Run fixtures
# run: |
# cf ssh getgov-${{ github.event.inputs.environment }} -c "/tmp/lifecycle/shell ./manage.py load"
# - name: Create cache table
# run: |
# cf ssh getgov-${{ github.event.inputs.environment }} -c "/tmp/lifecycle/shell ./manage.py createcachetable"