Skip to content

Staging db

Staging db #8

Workflow file for this run

name: Deploy
on:
pull_request:
types: [opened, synchronize]
jobs:
setup-db:
runs-on: ubuntu-latest
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
outputs:
db_url: ${{ steps.parse_db_password.outputs.db_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup flyctl
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Remove previous deployments
run: flyctl apps destroy echo-web-stg-db-${{ github.event.pull_request.number }} --yes
- name: Create database
if: always()
id: create_db
run: |
OUTPUT=$(flyctl postgres create \
--org personal \
--region arn \
--initial-cluster-size 1 \
--vm-size shared-cpu-1x \
--volume-size 3 \
--name echo-web-stg-db-${{ github.event.pull_request.number}})
echo "$OUTPUT" > output.txt
- name: Parse db url
id: parse_db_password
run: |
DB_URL=$(grep -oP 'Connection string:\s+\K\w+' output.txt)
echo "db_url=$DB_URL" >> $GITHUB_OUTPUT
deploy-web:
runs-on: ubuntu-latest
if: always()
needs: setup-db
steps:
- name: echo url
run: echo ${{ needs.setup-db.outputs.db_url }}