-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (61 loc) · 2.05 KB
/
deploy_website.yaml
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
name: Build and Deploy website
on:
# Manually triggered event
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
PROJECT_DIR: "frontend"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'
cache-dependency-path: 'frontend/yarn.lock'
- name: Install dependencies
run: yarn --cwd $PROJECT_DIR install --frozen-lockfile
- name: Build project
run: yarn --cwd $PROJECT_DIR build
env:
CI: false
REACT_APP_BASE_URL: ${{ vars.BASE_API_URL }}
REACT_APP_ANSWERS_KEY: ${{ secrets.CHALLENGE_ANSWERS_KEY }}
- name: Archive Production Artifact
run: |
cd $PROJECT_DIR
# Create a filename with date-time suffix
ZIP_FILENAME=build-$(date +'%Y%m%d-%H%M%S').zip
echo "ZIP_FILENAME=$ZIP_FILENAME" >> $GITHUB_ENV
echo "Creating zip $ZIP_FILENAME"
# Replace 'build/' with the directory of your build artifacts
zip -r $ZIP_FILENAME build/
ls
shell: bash
- name: SCP to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ vars.SERVER_HOST }}
username: ${{ vars.SERVER_USERNAME }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_KEY_PASSPHRASE }}
port: 22
source: "frontend/*.zip"
target: ${{ vars.FILE_DIRECTORY }}
- name: SSH remote commands
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ vars.SERVER_HOST }}
username: ${{ vars.SERVER_USERNAME }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_KEY_PASSPHRASE }}
port: 22
script: |
cd ${{ vars.FILE_DIRECTORY }}/${{ env.PROJECT_DIR}}
rm -rf build
unzip -o ${{ env.ZIP_FILENAME }}
# List zip files, sort by date (oldest first), and delete all but the 3 most recent
ls -tp *.zip | grep -v '/$' | tail -n +3 | xargs -I {} rm -- {}