|
| 1 | +# GitHub Pages Deployment Guide |
| 2 | + |
| 3 | +This document outlines the deployment process for CodeStorm Hub using GitHub Pages with automated GitHub Actions workflow. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +CodeStorm Hub is deployed using GitHub Pages with a Next.js static export. The deployment process is fully automated through GitHub Actions, which builds and deploys the site whenever changes are pushed to the main branch. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +- **Framework**: Next.js 15 with static export (`output: 'export'`) |
| 12 | +- **Deployment Platform**: GitHub Pages |
| 13 | +- **Automation**: GitHub Actions workflow |
| 14 | +- **Branch**: `main` (production deployment) |
| 15 | +- **Build Output**: Static HTML/CSS/JS files in `/out` directory |
| 16 | + |
| 17 | +## Deployment Configuration |
| 18 | + |
| 19 | +### 1. Next.js Configuration (`next.config.ts`) |
| 20 | + |
| 21 | +The application is configured for static export with GitHub Pages optimizations: |
| 22 | + |
| 23 | +```typescript |
| 24 | +const nextConfig: NextConfig = { |
| 25 | + output: 'export', |
| 26 | + trailingSlash: true, |
| 27 | + images: { |
| 28 | + unoptimized: true, // Required for GitHub Pages |
| 29 | + remotePatterns: [new URL("https://github.com/CodeStorm-Hub.png")], |
| 30 | + }, |
| 31 | + // GitHub Pages specific paths |
| 32 | + basePath: process.env.NODE_ENV === 'production' ? '/CodeStorm-Hub.github.io' : '', |
| 33 | + assetPrefix: process.env.NODE_ENV === 'production' ? '/CodeStorm-Hub.github.io/' : '', |
| 34 | +}; |
| 35 | +``` |
| 36 | + |
| 37 | +### 2. GitHub Actions Workflow (`.github/workflows/deploy-github-pages.yml`) |
| 38 | + |
| 39 | +Automated deployment workflow that: |
| 40 | +- Triggers on pushes to `main` branch |
| 41 | +- Can be manually triggered via workflow_dispatch |
| 42 | +- Builds the Next.js application as static files |
| 43 | +- Deploys to GitHub Pages |
| 44 | + |
| 45 | +### 3. Additional Files |
| 46 | + |
| 47 | +- `.nojekyll`: Prevents GitHub from processing the site with Jekyll |
| 48 | +- `404.html`: Custom 404 page (automatically generated by Next.js) |
| 49 | + |
| 50 | +## Deployment Process |
| 51 | + |
| 52 | +### Automatic Deployment |
| 53 | + |
| 54 | +1. **Trigger**: Push changes to the `main` branch |
| 55 | +2. **Build**: GitHub Actions runs `npm run build:github-pages` |
| 56 | +3. **Export**: Next.js generates static files in `/out` directory |
| 57 | +4. **Deploy**: Files are deployed to GitHub Pages |
| 58 | +5. **Live**: Site is available at `https://codestorm-hub.github.io/CodeStorm-Hub.github.io/` |
| 59 | + |
| 60 | +### Manual Deployment |
| 61 | + |
| 62 | +You can manually trigger deployment: |
| 63 | +1. Go to the repository's Actions tab |
| 64 | +2. Select "Deploy to GitHub Pages" workflow |
| 65 | +3. Click "Run workflow" on the main branch |
| 66 | + |
| 67 | +## Local Testing |
| 68 | + |
| 69 | +To test the GitHub Pages build locally: |
| 70 | + |
| 71 | +```bash |
| 72 | +# Install dependencies |
| 73 | +npm install |
| 74 | + |
| 75 | +# Build for GitHub Pages |
| 76 | +npm run build:github-pages |
| 77 | + |
| 78 | +# Serve the static files (optional) |
| 79 | +npx serve out |
| 80 | +``` |
| 81 | + |
| 82 | +## Repository Settings |
| 83 | + |
| 84 | +Ensure the following GitHub repository settings are configured: |
| 85 | + |
| 86 | +### Pages Settings |
| 87 | +1. Navigate to **Settings** → **Pages** |
| 88 | +2. **Source**: Deploy from a branch |
| 89 | +3. **Branch**: Select `gh-pages` (created automatically by the workflow) |
| 90 | +4. **Folder**: `/ (root)` |
| 91 | + |
| 92 | +### Actions Permissions |
| 93 | +1. Navigate to **Settings** → **Actions** → **General** |
| 94 | +2. Ensure "Allow all actions and reusable workflows" is selected |
| 95 | +3. Under "Workflow permissions", select "Read and write permissions" |
| 96 | + |
| 97 | +## Troubleshooting |
| 98 | + |
| 99 | +### Common Issues |
| 100 | + |
| 101 | +1. **Build Fails** |
| 102 | + - Check the Actions tab for error logs |
| 103 | + - Ensure all dependencies are properly listed in `package.json` |
| 104 | + - Verify TypeScript compilation passes locally |
| 105 | + |
| 106 | +2. **Assets Not Loading** |
| 107 | + - Confirm `basePath` and `assetPrefix` are correctly configured |
| 108 | + - Check that images use the Next.js `Image` component |
| 109 | + - Verify links use Next.js `Link` component |
| 110 | + |
| 111 | +3. **404 Errors on Page Refresh** |
| 112 | + - This is expected behavior for client-side routing in GitHub Pages |
| 113 | + - The custom 404.html handles fallback routing |
| 114 | + |
| 115 | +4. **Workflow Permissions Error** |
| 116 | + - Ensure repository has proper Actions permissions |
| 117 | + - Check that GITHUB_TOKEN has necessary permissions |
| 118 | + |
| 119 | +### Validation Steps |
| 120 | + |
| 121 | +After deployment, verify: |
| 122 | +- [ ] Site loads at the GitHub Pages URL |
| 123 | +- [ ] Navigation works correctly |
| 124 | +- [ ] Images and assets load properly |
| 125 | +- [ ] All pages are accessible |
| 126 | +- [ ] Responsive design works across devices |
| 127 | +- [ ] Dark/light mode toggle functions |
| 128 | +- [ ] No console errors in browser developer tools |
| 129 | + |
| 130 | +## Performance Optimizations |
| 131 | + |
| 132 | +The GitHub Pages deployment includes several optimizations: |
| 133 | + |
| 134 | +- **Static Generation**: All pages are pre-generated at build time |
| 135 | +- **Asset Optimization**: Images and assets are optimized for web delivery |
| 136 | +- **Bundle Splitting**: JavaScript is split into optimized chunks |
| 137 | +- **CSS Optimization**: Tailwind CSS is purged of unused styles |
| 138 | +- **Caching**: Static assets leverage browser caching |
| 139 | + |
| 140 | +## Monitoring |
| 141 | + |
| 142 | +Monitor deployment status: |
| 143 | +- **Actions Tab**: View build and deployment logs |
| 144 | +- **Pages Settings**: Check deployment status and URL |
| 145 | +- **Repository Insights**: Monitor site traffic and performance |
| 146 | + |
| 147 | +## Maintenance |
| 148 | + |
| 149 | +Regular maintenance tasks: |
| 150 | +- Monitor GitHub Actions workflow runs |
| 151 | +- Update dependencies periodically |
| 152 | +- Review and optimize Core Web Vitals |
| 153 | +- Test deployment after major changes |
| 154 | +- Keep documentation updated |
| 155 | + |
| 156 | +## Custom Domain (Optional) |
| 157 | + |
| 158 | +To use a custom domain: |
| 159 | +1. Add a `CNAME` file to the repository root |
| 160 | +2. Configure DNS records with your domain provider |
| 161 | +3. Update the domain in repository Pages settings |
| 162 | +4. Update `basePath` and `assetPrefix` in `next.config.ts` |
| 163 | + |
| 164 | +## Security Considerations |
| 165 | + |
| 166 | +- All builds run in isolated GitHub Actions environments |
| 167 | +- No sensitive data is exposed in client-side code |
| 168 | +- Dependencies are automatically scanned for vulnerabilities |
| 169 | +- HTTPS is enforced by default on GitHub Pages |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +For questions or issues with deployment, please refer to the [GitHub Pages documentation](https://docs.github.com/en/pages) or open an issue in this repository. |
0 commit comments