Fixed deployment issues #128
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: CI/CD Pipeline for Next.js | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
preview-deployment: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [18.x, 20.x] | |
outputs: | |
preview-url: ${{ steps.deploy.outputs.preview-url }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: "npm" | |
- name: Install Dependencies | |
run: npm ci | |
- name: Build Next.js Project | |
run: npm run build | |
- name: Deploy to Vercel Preview | |
id: deploy | |
uses: amondnet/[email protected] | |
with: | |
vercel-token: ${{ secrets.VERCEL_TOKEN }} | |
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} | |
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} | |
env: | |
VERCEL_ENV: preview | |
test: | |
needs: preview-deployment | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: "npm" | |
- name: Install Dependencies | |
run: npm ci | |
- name: Run Jest Tests | |
run: npm test | |
- name: Run Cypress Tests | |
uses: cypress-io/github-action@v6 | |
with: | |
browser: chrome | |
command: npm run cypress:run | |
env: | |
CYPRESS_BASE_URL: ${{ needs.preview-deployment.outputs.preview-url }} | |
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} | |
TEST_STORE_ID: ${{ secrets.TEST_STORE_ID }} | |
TEST_EMAIL: ${{ secrets.TEST_EMAIL }} | |
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }} | |
TEST_PRODUCT_ID: ${{ secrets.TEST_PRODUCT_ID }} | |
TEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }} | |
TEST_USER_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }} | |
TEST_USER_PRODUCT_ID: ${{ secrets.TEST_USER_PRODUCT_ID }} | |
TEST_STORE_ID_MANAGE: ${{ secrets.TEST_STORE_ID_MANAGE }} | |
deploy: | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Deploy to Vercel Production | |
uses: amondnet/[email protected] | |
with: | |
vercel-token: ${{ secrets.VERCEL_TOKEN }} | |
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} | |
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} | |
vercel-args: "--prod" |