Skip to content

updated main.yml

updated main.yml #8

Workflow file for this run

name: CI/CD
on:
- push
jobs:
# FIRST JOB => check if code is valid
code-checks:
name: Code Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # IMPORTANT TO NOTE! this action allows the job to access/check out the repository under $GITHUB_WORKSPACE (https://github.com/marketplace/actions/checkout)
- uses: actions/setup-node@v4
with:
node-version: 18
- run: mv .env.example .env
- run: npm install
- run: npm run test
- run: npm run lint
- run: npm run format:check
- run: npm run types:check
# SECOND JOB => run e2e tests
# it will build the app, start it and run all e2e tests
e2e:
name: E2E Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: mv .env.example .env
- uses: cypress-io/github-action@v6 # this action installs dependencies and caches them for future use, then run cypress e2e tests on election browser and gives us test summary after completion (https://github.com/marketplace/actions/cypress-io)
with:
build: npm run build
start: npm run start
# THIRD JOB => deploy to vercel
deploy:
name: Deploy To Vercel
runs-on: ubuntu-latest
needs: [code-checks, e2e] # this means that deploy job depends on the 2 previous jobs
if: github.repository_owner == 'nina1012'
permissions:
contents: read
deployments: write
steps:
- name: start deployment
uses: bobheadxi/deployments@v1 # before and after deployment to update the deployment status in github
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ fromJSON('["Production", "Preview"]')[github.ref != 'refs/heads/main'] }}
- uses: actions/checkout@v3
- run: mv .env.example .env
- uses: amondnet/vercel-action@v25 # This action makes a deployment with github actions instead of Vercel builder
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-args: ${{ fromJSON('["--prod", ""]')[github.ref != 'refs/heads/main'] }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID}}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID}}
scope: ${{ secrets.VERCEL_ORG_ID}}
working-directory: ./
- name: update deployment status
uses: bobheadxi/deployments@v1 # after the deployment
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env: ${{ steps.deployment.outputs.env }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}