Skip to content

Merge pull request #35 from Unity-Lab-AI/develop #23

Merge pull request #35 from Unity-Lab-AI/develop

Merge pull request #35 from Unity-Lab-AI/develop #23

Workflow file for this run

name: Build and Deploy
# Run on push to main/master branch only
on:
push:
branches:
- main
- master
workflow_dispatch: # Allow manual triggering
# Grant necessary permissions
permissions:
contents: write
pages: write
id-token: write
issues: write
pull-requests: write
jobs:
# Job 1: Build with Vite
build:
name: Build with Vite
needs: []
runs-on: ubuntu-latest
outputs:
build_status: ${{ steps.build_check.outputs.status }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: |
echo "📦 Installing dependencies..."
npm ci
- name: Build with Vite
id: build_check
run: |
echo "🏗️ Building with Vite..."
npm run build
# Check if build succeeded
if [ ! -d "dist" ]; then
echo "❌ Build failed - dist directory not created!"
echo "status=failed" >> $GITHUB_OUTPUT
exit 1
fi
# Verify critical files exist
if [ ! -f "dist/index.html" ]; then
echo "❌ Build failed - index.html not found in dist!"
echo "status=failed" >> $GITHUB_OUTPUT
exit 1
fi
echo "✅ Vite build completed successfully"
echo "📦 Build output:"
ls -lh dist/
echo ""
echo "📦 Assets:"
ls -lh dist/assets/ | head -20
echo "status=success" >> $GITHUB_OUTPUT
- name: Copy additional files to dist
run: |
echo "📋 Copying additional files using copy-assets.js..."
# Use the centralized copy-assets.js script for consistency
# This script maintains the list of all files/directories to copy
node copy-assets.js
echo ""
echo "📦 Final dist contents:"
find dist -type f | head -50
echo "..."
echo "Total files: $(find dist -type f | wc -l)"
- name: Upload artifact for deployment
uses: actions/upload-pages-artifact@v3
with:
path: 'dist'
# Job 4a: Report Build Status
report-status:
name: Report Build Status
needs: build
runs-on: ubuntu-latest
if: always()
steps:
- name: Report success
if: needs.build.outputs.build_status == 'success'
run: |
echo "✅ BUILD SUCCESSFUL"
echo "================================"
echo "Built with: Vite"
echo "Status: SUCCESS"
echo "Ready for deployment"
echo "================================"
- name: Report failure
if: needs.build.outputs.build_status == 'failed'
run: |
echo "❌ BUILD FAILED"
echo "================================"
echo "Built with: Vite"
echo "Status: FAILED"
echo "Check build logs for details"
echo "================================"
exit 1
- name: Create status comment (if PR)
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const status = '${{ needs.build.outputs.build_status }}';
const icon = status === 'success' ? '✅' : '❌';
const message = status === 'success' ? 'Build successful!' : 'Build failed!';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${icon} **${message}**\n\n**Built with:** Vite\n**Status:** ${status.toUpperCase()}`
});
# Job 4b: Deploy to GitHub Pages
deploy:
name: Deploy to GitHub Pages
needs: build
runs-on: ubuntu-latest
if: needs.build.outputs.build_status == 'success'
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: github-pages
path: artifact
- name: Extract artifact
run: |
cd artifact
tar -xf artifact.tar
mkdir -p ../dist
mv * ../dist/ 2>/dev/null || true
cd ..
rm -rf artifact
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
keep_files: false
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
commit_message: 'Deploy from main branch'
- name: Purge Cloudflare cache
run: |
echo "🧹 Purging Cloudflare cache..."
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE_ID }}/purge_cache" \
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}' | jq .
echo "✅ Cache purge requested"
- name: Report deployment success
run: |
echo "🚀 DEPLOYMENT SUCCESSFUL"
echo "================================"
echo "Branch: ${{ github.ref_name }}"
echo "URL: https://www.unityailab.com/"
echo "Built with: Vite (optimized)"
echo "Cache: Purged via Cloudflare API"
echo "================================"