-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (59 loc) · 2.18 KB
/
Copy pathdeploy.yml
File metadata and controls
74 lines (59 loc) · 2.18 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
name: Deploy Docusaurus to EC2
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Execute remote deployment
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd /home/ubuntu/projects/docs
echo "Setting git configuration..."
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
echo "Creating temporary build directory..."
mkdir -p ../docs_temp/build
echo "Fetching latest changes..."
git fetch origin main
echo "Cleaning git working directory..."
git reset --hard origin/main
git clean -fd
echo "Setting permissions..."
sudo chown -R ubuntu:ubuntu .
sudo chmod -R 755 .
echo "Installing dependencies..."
rm -rf node_modules package-lock.json
npm install
echo "Building site..."
# Build directly into the temporary directory
npm run build -- --out-dir ../docs_temp/build
# Verify build succeeded
if [ ! -d "../docs_temp/build" ]; then
echo "Build failed - aborting deployment"
rm -rf ../docs_temp
exit 1
fi
echo "Deploying new version..."
# Move the current build to backup (just in case)
if [ -d "build" ]; then
mv build ../docs_build_backup
fi
# Move new build into place
mv ../docs_temp/build .
# Cleanup
rm -rf ../docs_temp
rm -rf ../docs_build_backup
echo "Deployment complete!"