|
| 1 | +name: Deploy Demos to GitHub Pages |
| 2 | + |
| 3 | +on: |
| 4 | + # Trigger on push to main branch |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths: |
| 9 | + - 'demos/**' |
| 10 | + - '.github/workflows/deploy-demos.yml' |
| 11 | + |
| 12 | + # Allow manual trigger from Actions tab |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +# Sets permissions for GitHub Pages deployment |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + pages: write |
| 19 | + id-token: write |
| 20 | + |
| 21 | +# Allow only one concurrent deployment |
| 22 | +concurrency: |
| 23 | + group: "pages" |
| 24 | + cancel-in-progress: true |
| 25 | + |
| 26 | +jobs: |
| 27 | + # Build job |
| 28 | + build: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - name: Checkout repository |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Setup Node.js |
| 35 | + uses: actions/setup-node@v4 |
| 36 | + with: |
| 37 | + node-version: '20' |
| 38 | + |
| 39 | + - name: Validate HTML files |
| 40 | + run: | |
| 41 | + echo "Validating HTML structure..." |
| 42 | + # Check if index.html exists |
| 43 | + if [ ! -f "demos/index.html" ]; then |
| 44 | + echo "Error: demos/index.html not found" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + echo "HTML validation passed!" |
| 48 | +
|
| 49 | + - name: Check for broken links (basic) |
| 50 | + run: | |
| 51 | + echo "Checking for basic issues in demos..." |
| 52 | + # Simple check for common issues |
| 53 | + find demos -name "*.html" -type f | while read file; do |
| 54 | + echo "Checking: $file" |
| 55 | + # Check for basic HTML structure |
| 56 | + if ! grep -q "<!DOCTYPE html>" "$file"; then |
| 57 | + echo "Warning: $file missing DOCTYPE declaration" |
| 58 | + fi |
| 59 | + done |
| 60 | +
|
| 61 | + - name: Create build artifact |
| 62 | + run: | |
| 63 | + echo "Preparing demos for deployment..." |
| 64 | + mkdir -p _site |
| 65 | + cp -r demos/* _site/ |
| 66 | +
|
| 67 | + # Create a .nojekyll file to bypass Jekyll processing |
| 68 | + touch _site/.nojekyll |
| 69 | +
|
| 70 | + # Create a custom 404 page |
| 71 | + cat > _site/404.html << 'EOF' |
| 72 | + <!DOCTYPE html> |
| 73 | + <html lang="en"> |
| 74 | + <head> |
| 75 | + <meta charset="UTF-8"> |
| 76 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 77 | + <title>404 - Page Not Found</title> |
| 78 | + <style> |
| 79 | + body { |
| 80 | + margin: 0; |
| 81 | + padding: 0; |
| 82 | + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; |
| 83 | + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
| 84 | + color: white; |
| 85 | + display: flex; |
| 86 | + align-items: center; |
| 87 | + justify-content: center; |
| 88 | + min-height: 100vh; |
| 89 | + text-align: center; |
| 90 | + } |
| 91 | + .container { |
| 92 | + max-width: 600px; |
| 93 | + padding: 2rem; |
| 94 | + } |
| 95 | + h1 { |
| 96 | + font-size: 6rem; |
| 97 | + margin: 0; |
| 98 | + font-weight: 700; |
| 99 | + } |
| 100 | + p { |
| 101 | + font-size: 1.5rem; |
| 102 | + margin: 1rem 0 2rem; |
| 103 | + } |
| 104 | + a { |
| 105 | + display: inline-block; |
| 106 | + padding: 1rem 2rem; |
| 107 | + background: white; |
| 108 | + color: #667eea; |
| 109 | + text-decoration: none; |
| 110 | + border-radius: 8px; |
| 111 | + font-weight: 600; |
| 112 | + transition: transform 0.3s ease; |
| 113 | + } |
| 114 | + a:hover { |
| 115 | + transform: translateY(-2px); |
| 116 | + } |
| 117 | + </style> |
| 118 | + </head> |
| 119 | + <body> |
| 120 | + <div class="container"> |
| 121 | + <h1>404</h1> |
| 122 | + <p>Oops! This demo doesn't exist yet.</p> |
| 123 | + <a href="/">Return to Demo Gallery</a> |
| 124 | + </div> |
| 125 | + </body> |
| 126 | + </html> |
| 127 | + EOF |
| 128 | +
|
| 129 | + echo "Build artifact created successfully!" |
| 130 | +
|
| 131 | + - name: List build contents |
| 132 | + run: | |
| 133 | + echo "Build directory structure:" |
| 134 | + ls -la _site/ |
| 135 | + echo "" |
| 136 | + echo "Demos available:" |
| 137 | + find _site -type d -maxdepth 1 | sort |
| 138 | +
|
| 139 | + - name: Setup Pages |
| 140 | + uses: actions/configure-pages@v4 |
| 141 | + |
| 142 | + - name: Upload artifact |
| 143 | + uses: actions/upload-pages-artifact@v3 |
| 144 | + with: |
| 145 | + path: '_site' |
| 146 | + |
| 147 | + # Deployment job |
| 148 | + deploy: |
| 149 | + environment: |
| 150 | + name: github-pages |
| 151 | + url: ${{ steps.deployment.outputs.page_url }} |
| 152 | + runs-on: ubuntu-latest |
| 153 | + needs: build |
| 154 | + steps: |
| 155 | + - name: Deploy to GitHub Pages |
| 156 | + id: deployment |
| 157 | + uses: actions/deploy-pages@v4 |
| 158 | + |
| 159 | + - name: Display deployment URL |
| 160 | + run: | |
| 161 | + echo "🎉 Demos deployed successfully!" |
| 162 | + echo "📦 URL: ${{ steps.deployment.outputs.page_url }}" |
| 163 | + echo "" |
| 164 | + echo "Available demos:" |
| 165 | + echo "- Main Gallery: ${{ steps.deployment.outputs.page_url }}" |
| 166 | + echo "- ELIZA: ${{ steps.deployment.outputs.page_url }}01-eliza/" |
| 167 | + echo "- Tokenization: ${{ steps.deployment.outputs.page_url }}02-tokenization/" |
| 168 | + echo "- Embeddings: ${{ steps.deployment.outputs.page_url }}03-embeddings/" |
| 169 | + echo "- Attention: ${{ steps.deployment.outputs.page_url }}04-attention/" |
| 170 | + echo "- Transformer: ${{ steps.deployment.outputs.page_url }}05-transformer/" |
| 171 | + echo "- GPT Playground: ${{ steps.deployment.outputs.page_url }}06-gpt-playground/" |
| 172 | +
|
| 173 | + # Optional: Verify deployment |
| 174 | + verify: |
| 175 | + runs-on: ubuntu-latest |
| 176 | + needs: deploy |
| 177 | + steps: |
| 178 | + - name: Verify deployment |
| 179 | + run: | |
| 180 | + echo "Deployment verification complete!" |
| 181 | + echo "Demos should now be live at GitHub Pages." |
| 182 | + echo "" |
| 183 | + echo "To enable GitHub Pages:" |
| 184 | + echo "1. Go to repository Settings" |
| 185 | + echo "2. Navigate to Pages section" |
| 186 | + echo "3. Under 'Build and deployment', select 'GitHub Actions' as the source" |
| 187 | + echo "4. Save changes" |
0 commit comments