-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
42 lines (30 loc) · 984 Bytes
/
deploy.sh
File metadata and controls
42 lines (30 loc) · 984 Bytes
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
#!/bin/bash
# Get the current script's filename (i.e., 'deploy.sh')
SCRIPT_FILENAME=$(basename "$0")
# Run the Vite build command
npm run build
# Check if there are uncommitted changes in the 'main' branch
if [[ $(git diff --exit-code) ]]; then
# Stash the changes in 'main'
git stash
fi
# Create or checkout a production branch
git checkout -B prod
# Remove all files and folders from the root except the dist folder, .gitignore, node_modules, and the script file
shopt -s extglob
rm -rf !(.gitignore|dist|node_modules|"${SCRIPT_FILENAME}")
# Copy the contents of the dist folder to the root
cp -r dist/* .
# Add all changes
git add .
# Commit the changes
git commit -m "Deploy to GitHub Pages"
# Force push to the production branch on GitHub
git push --force origin prod
# Switch back to the main branch
git checkout main
# Delete the local 'prod' branch
git branch -D prod
if [[ $(git stash list) ]]; then
git stash pop
fi