From 2ccc661cc98c53f3d7123fd738826d601b8dfda6 Mon Sep 17 00:00:00 2001 From: piyush-jaiswal Date: Sat, 2 Aug 2025 13:50:57 +0530 Subject: [PATCH 1/6] Block vercel deployment on test success --- .github/workflows/deploy_preview.yml | 34 +++++++++++++++++++++++++ .github/workflows/deploy_production.yml | 34 +++++++++++++++++++++++++ .github/workflows/tests.yml | 5 +--- 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/deploy_preview.yml create mode 100644 .github/workflows/deploy_production.yml diff --git a/.github/workflows/deploy_preview.yml b/.github/workflows/deploy_preview.yml new file mode 100644 index 0000000..6a8a72e --- /dev/null +++ b/.github/workflows/deploy_preview.yml @@ -0,0 +1,34 @@ +name: Vercel Preview Deployment + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +on: + pull_request: + branches: [ "master" ] + workflow_dispatch: + +jobs: + test: + uses: ./.github/workflows/tests.yml + + deploy-preview: + needs: [test] + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Vercel CLI + run: npm install --global vercel@canary + + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build Project Artifacts + run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + + - name: Deploy Project Artifacts to Vercel + run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} diff --git a/.github/workflows/deploy_production.yml b/.github/workflows/deploy_production.yml new file mode 100644 index 0000000..1b77979 --- /dev/null +++ b/.github/workflows/deploy_production.yml @@ -0,0 +1,34 @@ +name: Vercel Production Deployment + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +on: + push: + branches: [ "master" ] + workflow_dispatch: + +jobs: + test: + uses: ./.github/workflows/tests.yml + + deploy-production: + needs: [test] + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Vercel CLI + run: npm install --global vercel@canary + + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build Project Artifacts + run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + + - name: Deploy Project Artifacts to Vercel + run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d973520..eacaf27 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,10 +1,7 @@ name: Tests on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] + workflow_call: workflow_dispatch: jobs: From 54fd1acb45670211e39fb18e68762622e154aad1 Mon Sep 17 00:00:00 2001 From: piyush-jaiswal Date: Sat, 2 Aug 2025 14:42:41 +0530 Subject: [PATCH 2/6] Cancel the previous running deployment of PR if new deployment detected --- .github/workflows/deploy_preview.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/deploy_preview.yml b/.github/workflows/deploy_preview.yml index 6a8a72e..4d80313 100644 --- a/.github/workflows/deploy_preview.yml +++ b/.github/workflows/deploy_preview.yml @@ -9,6 +9,10 @@ on: branches: [ "master" ] workflow_dispatch: +concurrency: + group: "vercel-preview-${{ github.event.pull_request.number }}" + cancel-in-progress: true + jobs: test: uses: ./.github/workflows/tests.yml From 90cfa87b4345cb840b4dfd15334dc3a218faef04 Mon Sep 17 00:00:00 2001 From: piyush-jaiswal Date: Sat, 2 Aug 2025 14:45:26 +0530 Subject: [PATCH 3/6] Wait for previous deployment in prod to finish before running current --- .github/workflows/deploy_production.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/deploy_production.yml b/.github/workflows/deploy_production.yml index 1b77979..5689451 100644 --- a/.github/workflows/deploy_production.yml +++ b/.github/workflows/deploy_production.yml @@ -9,6 +9,10 @@ on: branches: [ "master" ] workflow_dispatch: +concurrency: + group: "vercel-production-${{ github.ref }}" + cancel-in-progress: false # waits for the previous one to finish + jobs: test: uses: ./.github/workflows/tests.yml From 9f3c336242d75598eb03c9389ce1525d2e8cc511 Mon Sep 17 00:00:00 2001 From: piyush-jaiswal Date: Sat, 2 Aug 2025 14:47:20 +0530 Subject: [PATCH 4/6] Pin vercel version --- .github/workflows/deploy_preview.yml | 2 +- .github/workflows/deploy_production.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy_preview.yml b/.github/workflows/deploy_preview.yml index 4d80313..301899a 100644 --- a/.github/workflows/deploy_preview.yml +++ b/.github/workflows/deploy_preview.yml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v4 - name: Install Vercel CLI - run: npm install --global vercel@canary + run: npm install --global vercel@44.6.6 - name: Pull Vercel Environment Information run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} diff --git a/.github/workflows/deploy_production.yml b/.github/workflows/deploy_production.yml index 5689451..0d710ee 100644 --- a/.github/workflows/deploy_production.yml +++ b/.github/workflows/deploy_production.yml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v4 - name: Install Vercel CLI - run: npm install --global vercel@canary + run: npm install --global vercel@44.6.6 - name: Pull Vercel Environment Information run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} From 1a533b6d96e6398d431b0675f482cdcb2549d25a Mon Sep 17 00:00:00 2001 From: piyush-jaiswal Date: Sat, 2 Aug 2025 14:48:07 +0530 Subject: [PATCH 5/6] Don't deploy for PR from forked repos --- .github/workflows/deploy_preview.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy_preview.yml b/.github/workflows/deploy_preview.yml index 301899a..596b844 100644 --- a/.github/workflows/deploy_preview.yml +++ b/.github/workflows/deploy_preview.yml @@ -20,6 +20,8 @@ jobs: deploy-preview: needs: [test] runs-on: ubuntu-latest + # Do not run for PR from forks + if: github.event.pull_request.head.repo.full_name == github.repository steps: - name: Checkout code From 3ba7cdc9f58e0c0ee8a821f5aba7cf72b7a2bcc3 Mon Sep 17 00:00:00 2001 From: piyush-jaiswal Date: Sat, 2 Aug 2025 14:48:44 +0530 Subject: [PATCH 6/6] Stop all automated vercel deployments --- vercel.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vercel.json b/vercel.json index 58b4f91..b8ddeaa 100644 --- a/vercel.json +++ b/vercel.json @@ -4,5 +4,9 @@ "src": "/(.*)", "dest": "/api/vercel_function" } - ] + ], + + "git": { + "deploymentEnabled": false + } }