-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (110 loc) · 4.03 KB
/
deploy-action.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: 'Deploy App Workflow'
on:
workflow_call:
inputs:
environment:
required: true
type: string
branch:
required: true
type: string
secrets:
app_env:
required: true
vercel_token:
required: true
org_id:
required: true
project_id:
required: true
jobs:
deploy-app:
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
url: ${{ steps.vercel_deploy.outputs.VERCEL_URL }}
concurrency:
cancel-in-progress: true
group: ${{ inputs.environment }}
env:
VERCEL_ORG_ID: ${{ secrets.org_id }}
VERCEL_PROJECT_ID: ${{ secrets.project_id }}
VERCEL_DOMAIN: t3-stack-app.vercel.app
steps:
- name: Checkout ${{ inputs.branch }} branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- uses: pnpm/action-setup@v2
with:
version: 7.0.1
- uses: actions/setup-node@v4
with:
node-version: 16.15.0
cache: 'pnpm'
- name: Set node environment variables
run: echo ${{ secrets.app_env }} | openssl base64 -d -A -out .env
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Deploy to Vercel
id: vercel_deploy
run: |
environment=""
prod_flag=""
vercel_url=""
# set vercel_url based on environment
if [[ "${{ inputs.environment }}" == "dev" ]]
then
vercel_url="develop-$VERCEL_DOMAIN"
elif [[ "${{ inputs.environment }}" == "staging" ]]
then
vercel_url="staging-$VERCEL_DOMAIN"
elif [[ "${{ inputs.environment }}" == "production" ]]
then
vercel_url="$VERCEL_DOMAIN"
environment="--environment=production"
prod_flag="--prod"
fi
# pull request deploy preview
if [[ "${{ github.event_name }}" == "pull_request" ]] && [[ "${{ github.base_ref }}" == "develop" ]]
then
vercel_url="develop-${{ github.event.pull_request.number }}-$VERCEL_DOMAIN"
environment="--environment=preview"
# set PR deploy preview url
echo "PR_PREVIEW_URL=https://${vercel_url}" >> $GITHUB_OUTPUT
fi
# show derived parameters
echo environment: $environment
echo prod_flag: $prod_flag
echo vercel_url: $vercel_url
# start vercel deployment
pnpm vercel --token=${{ secrets.vercel_token }} pull --yes $environment
# on project setup, override the following
# - build command in vercel with `next build --no-lint` to disable linting or `pnpm build`
# - install command as empty to disable installation in vercel build command
pnpm vercel --token=${{ secrets.vercel_token }} build $prod_flag
pnpm vercel --token=${{ secrets.vercel_token }} deploy --prebuilt $prod_flag > domain.txt
# use --scope=$VERCEL_TEAM_ID if you're using vercel teams
if [[ "${{ inputs.environment }}" != "production" ]]
then
pnpm vercel --token=${{ secrets.vercel_token }} alias set `cat domain.txt` $vercel_url
fi
# set vercel preview url as job output url
if [[ "${{ github.event_name }}" != "pull_request" ]]
then
echo Set Environment URL
echo "VERCEL_URL=https://${vercel_url}" >> $GITHUB_OUTPUT
fi
- name: Comment deploy preview URL
uses: thollander/actions-comment-pull-request@v2
if: |
github.event_name == 'pull_request' &&
github.base_ref == 'develop'
with:
message: |
:white_check_mark: Preview
${{ steps.vercel_deploy.outputs.PR_PREVIEW_URL }}
Built with commit ${{ github.event.pull_request.head.sha }}.
comment_tag: execution
pr_number: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}