Skip to content

refactor(NP-87): Add Neon deployment workflows #2

refactor(NP-87): Add Neon deployment workflows

refactor(NP-87): Add Neon deployment workflows #2

name: Deploy Production
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
push:
branches:
- 'main'
- 'develop'
workflow_dispatch:
pull_request:
jobs:
deploy-production:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get last commit SHA
id: get_sha
run: |
echo sha="${{ github.event.before }}" | cut -c1-8 >> $GITHUB_OUTPUT
- name: Search branch by name
id: get_branch_id
# list all branches and filter by name
run: |
branch_id=$(curl --silent \
"https://console.neon.tech/api/v2/projects/${{ secrets.NEON_PROJECT_ID }}/branches" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${{ secrets.NEON_API_KEY }}" \
| jq -r .branches \
| jq -c '.[] | select(.name | contains("'${{ steps.get_sha.outputs.sha }}'")) .id' \
| jq -r \
) \
echo "branch_id=${branch_id}" >> $GITHUB_OUTPUT
- name: Install Vercel CLI
run: npm install --global vercel@latest
# - name: Deploy Production to Vercel
# id: deploy
# run: vercel deploy --prod --public --yes --token=${{ secrets.VERCEL_TOKEN }}
- name: Delete Neon Branch
uses: neondatabase/delete-branch-action@v2
with:
project_id: ${{ secrets.NEON_PROJECT_ID }}
branch_id: ${{ steps.get_branch_id.outputs.branch_id }}
api_key: ${{ secrets.NEON_API_KEY }}