forked from NYUCCL/smile
-
Notifications
You must be signed in to change notification settings - Fork 0
246 lines (224 loc) · 10.2 KB
/
deploy.yml
File metadata and controls
246 lines (224 loc) · 10.2 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# This is a basic workflow to deploy your smile experiment
name: deploy
on:
workflow_run:
workflows: ['test']
types:
- completed
workflow_dispatch:
inputs:
github_sha:
description: 'The GitHub SHA you want to deploy'
required: false
type: string
push:
branches-ignore:
- 'feat-*'
- 'fix-*'
- 'refactor-*'
- 'test-*'
- 'chore-*'
- 'style-*'
- 'docs-*'
- 'ci-*'
paths-ignore: # ignore any changes to the docs for this workflow or unimportant files
- 'docs/**'
- '.github/workflows/docs-deploy.yml'
- '**/*.md'
- 'LICENSE'
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: smile-deploy
cancel-in-progress: false
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
# The type of runner that the job will run on
runs-on: ubuntu-latest
env:
GITHUB_COMMIT_MESSAGE: '${{ github.event.head_commit.message }}'
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
## TODO CHANGE THIS TO CHECK OUT THE BRANCH THAT WAS COMMITTED TO
- name: Checkout code commited to branch
uses: actions/checkout@v4
with:
# This will checkout the SHA if triggered by workflow_dispatch, or the commit's branch if triggered by a push
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.github_sha || github.ref }}
# setup node.js
- name: Setup node.js
uses: actions/setup-node@v4
with:
node-version-file: '.node_version'
# install node packages
- name: Install node dependencies
run: npm install
# accesses some git variables and processes them to be lower case/short/escaped
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v5
with:
short-length: 7
# Configure git-specific .env file
- name: Expose git-specific information to the Vite environment
env:
ENV_FILE: 'env/.env.git.local'
run: |
escape_quotes() {
# Get the input string
input="$1"
# Escape single quotes
input="${input//\'/\'}"
# Escape double quotes
input="${input//\"/\\\"}"
# Return the escaped string
echo "$input"
}
echo "------"
echo "# DO NOT EDIT THIS FILE IT IS AUTOMATICALLY GENERATED" > $ENV_FILE
if test -z "${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}"
then
echo "VITE_PROJECT_NAME = unknown" >> $ENV_FILE
VITE_PROJECT_NAME='unknown'
else
echo "VITE_PROJECT_NAME = ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}" >> $ENV_FILE
VITE_PROJECT_NAME='${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}'
fi
if test -z "${{ env.GITHUB_SHA_SHORT }}"
then
echo "VITE_GIT_HASH = x0x0x0x0" >> $ENV_FILE
VITE_GIT_HASH='x0x0x0x0'
else
echo "VITE_GIT_HASH = ${{ env.GITHUB_SHA_SHORT }}" >> $ENV_FILE
VITE_GIT_HASH='${{ env.GITHUB_SHA_SHORT }}'
fi
if test -z "${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}"
then
echo "VITE_GIT_OWNER = unknown_owner" >> $ENV_FILE
VITE_GIT_OWNER='unknown_owner'
else
echo "VITE_GIT_OWNER = ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}" >> $ENV_FILE
VITE_GIT_OWNER='${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}'
fi
if test -z "${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}"
then
echo "VITE_GIT_REPO_NAME = unknown_repo" >> $ENV_FILE
VITE_GIT_REPO_NAME='unknown_repo'
else
echo "VITE_GIT_REPO_NAME = ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}" >> $ENV_FILE
VITE_GIT_REPO_NAME='${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}'
fi
if test -z "${{ env.GITHUB_REF_SLUG }}"
then
echo "VITE_GIT_BRANCH_NAME = unknown_branch" >> $ENV_FILE
VITE_GIT_BRANCH_NAME='unknown_branch'
else
echo "VITE_GIT_BRANCH_NAME = ${{ env.GITHUB_REF_SLUG }}" >> $ENV_FILE
VITE_GIT_BRANCH_NAME='${{ env.GITHUB_REF_SLUG }}'
fi
if test -z "${{ github.event.head_commit.message }}"
then
echo "VITE_GIT_LAST_MSG = (no commit message)" >> $ENV_FILE
VITE_GIT_LAST_MSG='(no commit message)'
else
echo "VITE_GIT_LAST_MSG = $GITHUB_COMMIT_MESSAGE" >> $ENV_FILE
VITE_GIT_LAST_MSG="$GITHUB_COMMIT_MESSAGE"
fi
echo "VITE_DEPLOY_BASE_PATH = '/${VITE_GIT_OWNER}/${VITE_GIT_REPO_NAME}/${VITE_GIT_BRANCH_NAME}/'" >> $ENV_FILE
CODENAME=$(node scripts/codenamize.cjs "/${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}/${{ env.GITHUB_REF_SLUG }}")
echo "VITE_CODE_NAME = ${CODENAME}" >> $ENV_FILE
cat $ENV_FILE
# put the full path name in VITE_DEPLOY_BASE_PATH
# Configure secure information configuration
- name: Expose secret information to the Vite environment
env:
SECRET_APP_CONFIG: ${{ secrets.SECRET_APP_CONFIG }}
SECRET_ENV_FILE: 'env/.env.local'
run: |
echo "------"
echo $SECRET_APP_CONFIG | base64 --decode > $SECRET_ENV_FILE
# load the environment
- name: Load the github dotenv file
id: dotenv_github
uses: falti/dotenv-action@v1.1
with:
path: 'env/.env.git.local'
- name: Load the general config dotenv file
id: dotenv_config
uses: falti/dotenv-action@v1.1
with:
path: './env/.env.local'
# echo all the environment variables
- name: echo the environment variables
run: |
echo "deploy url: ${{ secrets.EXP_DEPLOY_PATH }}${{ steps.dotenv_github.outputs.VITE_DEPLOY_BASE_PATH }}"
# place the deploy settings into the environment files
# this one needs to be made available to vite.config.js
- name: create deploy file
env:
DEPLOY_ENV_FILE: 'env/.env.deploy.local'
run: |
echo "VITE_DEPLOY_URL = 'https://${{ secrets.EXP_DEPLOY_HOST }}${{ steps.dotenv_github.outputs.VITE_DEPLOY_BASE_PATH }}'" > $DEPLOY_ENV_FILE
echo 'VITE_CODE_NAME_DEPLOY_URL = "https://${{ secrets.EXP_DEPLOY_HOST }}/e/${{ steps.dotenv_github.outputs.VITE_CODE_NAME }}"' >> $DEPLOY_ENV_FILE
cat $DEPLOY_ENV_FILE
# Build the web app
- name: Build web app
run: |
if ${{ github.ref == 'refs/heads/presentation' || secrets.EXP_DEPLOY_MODE == 'presentation' }}; then
npm run build:present
elif ${{ secrets.EXP_DEPLOY_MODE == 'development' }}; then
npm run build:dev
else
npm run build
fi
- name: list files
run: |
ls -la ./dist
ls -la ./dist/assets
# make remote folder if necessar
- name: create the remote folders if they don't exist
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EXP_DEPLOY_HOST }}
username: ${{ secrets.EXP_DEPLOY_USER }}
key: ${{ secrets.EXP_DEPLOY_KEY }}
port: ${{ secrets.EXP_DEPLOY_PORT }}
script: mkdir -p ${{ secrets.EXP_DEPLOY_PATH }}/${{ steps.dotenv_github.outputs.VITE_DEPLOY_BASE_PATH }}; mkdir -p ${{ secrets.EXP_DEPLOY_PATH }}/e; mkdir -p ${{ secrets.EXP_DEPLOY_PATH }}/hashes
# link to code name path
- name: link to the code name path
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EXP_DEPLOY_HOST }}
username: ${{ secrets.EXP_DEPLOY_USER }}
key: ${{ secrets.EXP_DEPLOY_KEY }}
port: ${{ secrets.EXP_DEPLOY_PORT }}
script: rm ${{ secrets.EXP_DEPLOY_PATH }}/e/${{ steps.dotenv_github.outputs.VITE_CODE_NAME }}; ln -sf ${{ secrets.EXP_DEPLOY_PATH }}/${{ steps.dotenv_github.outputs.VITE_DEPLOY_BASE_PATH }} ${{ secrets.EXP_DEPLOY_PATH }}/e/${{ steps.dotenv_github.outputs.VITE_CODE_NAME }}
# Deploy files to web server
- name: rsync to server
uses: burnett01/rsync-deployments@5.2
with:
switches: -avrz --delete
path: dist/
remote_path: ${{ secrets.EXP_DEPLOY_PATH }}/${{ steps.dotenv_github.outputs.VITE_DEPLOY_BASE_PATH }} # this should be configured with branch name and versioning
remote_host: ${{ secrets.EXP_DEPLOY_HOST }}
remote_port: ${{ secrets.EXP_DEPLOY_PORT }}
remote_user: ${{ secrets.EXP_DEPLOY_USER }}
remote_key: ${{ secrets.EXP_DEPLOY_KEY }}
# send a notification at the end
- name: Send notification to lab slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: ${{ env.SLACK_WEBHOOK_URL != '' }} # this should only run if SLACK_WEBHOOK exists
id: slack
uses: slackapi/slack-github-action@v1.25.0
with:
# This data can be any valid JSON from a previous step in the GitHub Action
payload: |
{
"github_username": "${{ github.actor }}",
"deploy_url": "https://${{ secrets.EXP_DEPLOY_HOST }}${{ steps.dotenv_github.outputs.VITE_DEPLOY_BASE_PATH }} although you should tell people https://${{ secrets.EXP_DEPLOY_HOST }}/e/${{ steps.dotenv_github.outputs.VITE_CODE_NAME }} . Your QR Code is to the site is here: https://${{ secrets.EXP_DEPLOY_HOST }}/e/${{ steps.dotenv_github.outputs.VITE_CODE_NAME }}/qr.svg",
"github_hash": "https://github.com/${{ steps.dotenv_github.outputs.VITE_GIT_OWNER }}/${{ steps.dotenv_github.outputs.VITE_GIT_REPO_NAME }}/commit/${{ steps.dotenv_github.outputs.VITE_GIT_HASH }}"
}