Skip to content

Commit 496b455

Browse files
committed
Update test.yml
1 parent 3a89f82 commit 496b455

1 file changed

Lines changed: 83 additions & 17 deletions

File tree

.github/workflows/test.yml

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,88 @@
1-
name: test
2-
on: push
1+
name: Deploy Vite React App
2+
3+
on:
4+
push:
5+
branches:
6+
- main # Change to your default branch
7+
38
jobs:
4-
checkoutandsetup:
5-
runs-on: ubuntu-latest
9+
deploy:
10+
runs-on: self-hosted
11+
612
steps:
7-
- name: code clone
8-
uses: actions/checkout@v2
9-
- name: setup node js
10-
uses: actions/setup-node@v6
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
1118
with:
12-
node-version: 20
13-
- name: install dependencies
19+
node-version: '18'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
1423
run: npm ci
15-
build:
16-
needs: checkoutandsetup
17-
runs-on: ubuntu-latest
18-
steps:
19-
- name: test Check
20-
run: npm test
21-
- name: build
24+
25+
- name: Build project
2226
run: npm run build
27+
env:
28+
NODE_ENV: production
29+
30+
- name: Backup existing deployment
31+
run: |
32+
DEPLOY_DIR="/var/www/your-app"
33+
if [ -d "$DEPLOY_DIR" ]; then
34+
BACKUP_DIR="${DEPLOY_DIR}.backup.$(date +%Y%m%d_%H%M%S)"
35+
echo "Creating backup at $BACKUP_DIR"
36+
sudo cp -r "$DEPLOY_DIR" "$BACKUP_DIR"
37+
38+
# Keep only last 5 backups
39+
ls -dt ${DEPLOY_DIR}.backup.* | tail -n +6 | xargs -r sudo rm -rf
40+
fi
41+
42+
- name: Deploy to server
43+
run: |
44+
DEPLOY_DIR="/var/www/your-app"
45+
echo "Deploying to $DEPLOY_DIR"
46+
47+
# Create directory if it doesn't exist
48+
sudo mkdir -p "$DEPLOY_DIR"
49+
50+
# Remove old files
51+
sudo rm -rf "$DEPLOY_DIR"/*
52+
53+
# Copy new build
54+
sudo cp -r ./dist/* "$DEPLOY_DIR"/
55+
56+
# Set proper permissions
57+
sudo chown -R www-data:www-data "$DEPLOY_DIR"
58+
sudo chmod -R 755 "$DEPLOY_DIR"
59+
60+
- name: Restart web server
61+
run: |
62+
echo "Reloading web server..."
63+
sudo systemctl reload nginx
64+
# For Apache use: sudo systemctl reload apache2
65+
66+
- name: Verify deployment
67+
run: |
68+
DEPLOY_DIR="/var/www/your-app"
69+
if [ -f "$DEPLOY_DIR/index.html" ]; then
70+
echo "✅ Deployment successful!"
71+
echo "Files deployed:"
72+
ls -lah "$DEPLOY_DIR"
73+
else
74+
echo "❌ Deployment failed - index.html not found"
75+
exit 1
76+
fi
77+
78+
- name: Deployment summary
79+
if: always()
80+
run: |
81+
echo "=========================================="
82+
echo "Deployment Summary"
83+
echo "=========================================="
84+
echo "Branch: ${{ github.ref_name }}"
85+
echo "Commit: ${{ github.sha }}"
86+
echo "Triggered by: ${{ github.actor }}"
87+
echo "Status: ${{ job.status }}"
88+
echo "=========================================="

0 commit comments

Comments
 (0)