|
| 1 | +name: CI/CD Workflow --> Deploy and Run E2E Tests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +jobs: |
| 10 | + deploy: |
| 11 | + name: Deploy to Vercel |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout Code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Install Vercel CLI |
| 19 | + run: npm install --global vercel@latest |
| 20 | + |
| 21 | + - name: Pull Vercel Environment Information |
| 22 | + run: | |
| 23 | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 24 | + vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} |
| 25 | + else |
| 26 | + vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} |
| 27 | + fi |
| 28 | +
|
| 29 | + - name: Build Project Artifacts |
| 30 | + run: | |
| 31 | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 32 | + vercel build --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} |
| 33 | + else |
| 34 | + vercel build --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} |
| 35 | + fi |
| 36 | +
|
| 37 | + - name: Deploy to Vercel |
| 38 | + id: deploy |
| 39 | + run: | |
| 40 | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 41 | + DEPLOY_URL=$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | tail -1) |
| 42 | + else |
| 43 | + DEPLOY_URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | tail -1) |
| 44 | + fi |
| 45 | + echo "DEPLOYMENT_URL=${DEPLOY_URL}" >> $GITHUB_ENV |
| 46 | + echo "Deployed to: $DEPLOY_URL" |
| 47 | +
|
| 48 | + env: |
| 49 | + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} |
| 50 | + |
| 51 | + e2e-tests: |
| 52 | + name: Run E2E Tests |
| 53 | + runs-on: ubuntu-latest |
| 54 | + needs: deploy |
| 55 | + |
| 56 | + steps: |
| 57 | + - name: Checkout repository |
| 58 | + uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Install Node.js |
| 61 | + uses: actions/setup-node@v4 |
| 62 | + with: |
| 63 | + node-version: 20 |
| 64 | + |
| 65 | + - name: Install pnpm |
| 66 | + uses: pnpm/action-setup@v4 |
| 67 | + with: |
| 68 | + version: latest |
| 69 | + run_install: false |
| 70 | + |
| 71 | + - name: Get pnpm store directory |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 75 | +
|
| 76 | + - name: Setup pnpm cache |
| 77 | + uses: actions/cache@v4 |
| 78 | + with: |
| 79 | + path: ${{ env.STORE_PATH }} |
| 80 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 81 | + restore-keys: | |
| 82 | + ${{ runner.os }}-pnpm-store- |
| 83 | +
|
| 84 | + - name: Install packages |
| 85 | + run: pnpm install --frozen-lockfile |
| 86 | + |
| 87 | + - name: Install Playwright dependencies |
| 88 | + run: pnpm exec playwright install-deps |
| 89 | + |
| 90 | + - name: Install Playwright |
| 91 | + run: pnpm exec playwright install |
| 92 | + |
| 93 | + - name: Run Playwright Tests |
| 94 | + run: pnpm test:e2e |
| 95 | + env: |
| 96 | + BASE_URL: ${{ env.DEPLOYMENT_URL }} |
0 commit comments