-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (67 loc) · 2.62 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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 }}