Skip to content

Commit 72124d3

Browse files
committed
Add workflow to deploy built project to master branch
- Creates production build with environment variables - Deploys built files to master branch - Enables GitHub Pages deployment - Triggers on push to next branch
1 parent dcb45cb commit 72124d3

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Deploy Built Project to Master Branch
2+
3+
on:
4+
push:
5+
branches: [ next ]
6+
workflow_dispatch: # Allow manual trigger
7+
8+
jobs:
9+
build-and-deploy-to-master:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # Fetch all history for proper git operations
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '18'
22+
cache: 'npm'
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Create production .env
28+
run: |
29+
echo "GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}" >> .env.production
30+
echo "VITE_ENABLE_CHATBOT=${{ secrets.VITE_ENABLE_CHATBOT || 'true' }}" >> .env.production
31+
echo "VITE_ENABLE_DYNAMIC_CONTENT=${{ secrets.VITE_ENABLE_DYNAMIC_CONTENT || 'true' }}" >> .env.production
32+
echo "VITE_SHOW_DEV_ELEMENTS=false" >> .env.production
33+
echo "VITE_SHOW_VISITOR_CONTROLS=false" >> .env.production
34+
echo "VITE_SHOW_PROFILE_INSIGHTS=false" >> .env.production
35+
echo "VITE_SHOW_TRANSLATION_DEBUG=false" >> .env.production
36+
echo "VITE_SHOW_DEBUG_INFO=false" >> .env.production
37+
echo "NODE_ENV=production" >> .env.production
38+
39+
- name: Test environment variables
40+
run: |
41+
echo "Testing environment variables..."
42+
node -e "
43+
const fs = require('fs');
44+
const envContent = fs.readFileSync('.env.production', 'utf8');
45+
console.log('Production .env content:');
46+
console.log(envContent.replace(/GEMINI_API_KEY=.*/, 'GEMINI_API_KEY=***HIDDEN***'));
47+
"
48+
49+
- name: Build project
50+
run: npm run build:prod
51+
52+
- name: Configure Git
53+
run: |
54+
git config --local user.email "action@github.com"
55+
git config --local user.name "GitHub Action"
56+
57+
- name: Switch to master branch
58+
run: |
59+
git checkout master
60+
git pull origin master
61+
62+
- name: Clean master branch (keep only built files)
63+
run: |
64+
# Remove all files except .git
65+
find . -maxdepth 1 -not -name '.git' -not -name '.' -exec rm -rf {} +
66+
67+
- name: Copy built files to master
68+
run: |
69+
# Copy built files from next branch
70+
git checkout next -- dist/
71+
git checkout next -- .env.production
72+
git checkout next -- .env.example
73+
git checkout next -- README.md
74+
git checkout next -- package.json
75+
76+
- name: Create index.html for GitHub Pages
77+
run: |
78+
# Move dist contents to root for GitHub Pages
79+
cp -r dist/* .
80+
# Keep important files
81+
cp .env.example .
82+
cp README.md .
83+
cp package.json .
84+
85+
- name: Commit and push to master
86+
run: |
87+
git add .
88+
git commit -m "Deploy built project from next branch - $(date)"
89+
git push origin master
90+
91+
- name: Deploy to GitHub Pages
92+
uses: peaceiris/actions-gh-pages@v3
93+
with:
94+
github_token: ${{ secrets.GITHUB_TOKEN }}
95+
publish_dir: ./

0 commit comments

Comments
 (0)