From fe5ff0de10ef71a3d5054be685c8fae39350b4e2 Mon Sep 17 00:00:00 2001 From: Anand Suthar Date: Sun, 26 May 2024 12:26:34 +0530 Subject: [PATCH] Refactor workflow to deploy before testing, with rollback on test failure. --- .github/workflows/playwright.yml | 33 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 0cb31571..441e4599 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -7,7 +7,7 @@ on: branches: [main, master] jobs: - test: + deploy-and-test: timeout-minutes: 60 runs-on: ubuntu-latest steps: @@ -17,6 +17,14 @@ jobs: node-version: 18 - name: Install dependencies run: npm ci + - 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 --prod --token=${{ secrets.VERCEL_TOKEN }} + - name: Deploy Project Artifacts to Vercel + run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} - name: Install Playwright Browsers run: npx playwright install --with-deps - name: Run Playwright tests @@ -27,23 +35,6 @@ jobs: name: playwright-report path: playwright-report/ retention-days: 30 - - deploy: - needs: test - if: ${{ success() }} - runs-on: ubuntu-latest - - env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} - - steps: - - 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 --prod --token=${{ secrets.VERCEL_TOKEN }} - - name: Deploy Project Artifacts to Vercel - run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} + - name: Rollback Deployment on Test Failure + if: failure() + run: vercel rollback --prod --token=${{ secrets.VERCEL_TOKEN }}