-
Notifications
You must be signed in to change notification settings - Fork 73
53 lines (42 loc) · 1.74 KB
/
deploy_carbonmark_api.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
# See: https://vercel.com/guides/how-to-alias-a-preview-deployment-using-the-cli
name: Deploy Carbonmark API
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_CARBONMARK_API }}
on:
pull_request:
branches:
- staging
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Pull Vercel Environment Information
run: vercel env pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} carbonmark-api/.env.local
- name: Run tests
run: |
cd carbonmark-api
npm install
npm run test
deploy_preview:
runs-on: ubuntu-latest
environment: Preview – carbonmark-api
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set short commit hash to environment variable
run: echo "SHORT_COMMIT_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c 1-7)" >> $GITHUB_ENV
- name: Pull Environment Vars
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Build API
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy to Vercel
run: |
url="$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})"
echo "DEPLOYED_URL=$url" >> $GITHUB_ENV
- name: Healthcheck deployment
run: npx newman run carbonmark-api/postman_collection.json --env-var "url=${{ env.DEPLOYED_URL }}"
- name: Alias deployment
run: vercel alias --token=${{ secrets.VERCEL_TOKEN }} --scope=${{ secrets.VERCEL_TEAM_ID }} set "${{ env.DEPLOYED_URL }}" carbonmark-api-${{ env.SHORT_COMMIT_SHA }}-klimadao.vercel.app