Merge pull request #7 from Rocketseat/qstash-publish-receive #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Production | |
env: | |
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
on: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
deploy-production: | |
permissions: write-all | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
run_install: false | |
- name: Get pnpm store directory | |
id: pnpm-cache | |
shell: bash | |
run: | | |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | |
- uses: actions/cache@v3 | |
name: Setup pnpm cache | |
with: | |
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} | |
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm-store- | |
- name: Install dependencies | |
run: pnpm install | |
- 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: Run Prisma Migrate | |
run: | | |
touch .env | |
echo DATABASE_URL="${{ secrets.DATABASE_URL}}" >> .env | |
echo DIRECT_DATABASE_URL="${{ secrets.DIRECT_DATABASE_URL}}" >> .env | |
pnpm dlx prisma migrate deploy | |
- name: Install Vercel CLI | |
run: pnpm i -g vercel@latest | |
- name: Pull Vercel Environment Information | |
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} | |
- name: Build Project Artifacts | |
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} | |
- name: Deploy Project Artifacts to Vercel | |
run: vercel deploy --prebuilt --prod --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 }} |