This document explains how to deploy the GitHub Copilot Premium Requests Usage Analyzer to GitHub Pages.
This project includes a GitHub Actions workflow that automatically builds and deploys the application to GitHub Pages without requiring the Spark dependencies.
- The workflow
.github/workflows/deploy-to-pages.ymlis triggered on pushes to themainbranch or manually from the Actions tab. - It creates a simplified build configuration that:
- Removes dependencies on the GitHub Spark modules
- Creates shims for necessary functionality
- Sets the correct base path for GitHub Pages
- The built application is deployed to GitHub Pages automatically.
To set up GitHub Pages deployment for this repository:
- Go to your repository on GitHub
- Click on "Settings"
- Navigate to "Pages" in the left sidebar
- Under "Build and deployment" > "Source", select "GitHub Actions"
- The workflow will now be able to deploy to GitHub Pages
You can trigger the deployment workflow manually:
- Go to the "Actions" tab in your repository
- Select the "Deploy to GitHub Pages" workflow
- Click "Run workflow" button (branch: main)
- Wait for the workflow to complete
For manual deployment, follow these steps:
Since the Spark dependencies are not available outside the GitHub environment, we need to create a simplified version of the app for GitHub Pages:
-
Create a new temporary directory:
mkdir -p temp_build cd temp_build -
Copy source files:
cp -r ../src . cp ../index.html . cp ../tailwind.config.js .
-
Create a simplified vite.config.js:
import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import { resolve } from 'path'; export default defineConfig({ plugins: [react()], build: { base: "/your-repo-name/", // Change to your repository name outDir: 'dist' }, resolve: { alias: { '@': resolve(__dirname, 'src') } } });
-
Create a simplified package.json with only the necessary dependencies:
{ "name": "github-copilot-usage-analyzer", "private": true, "version": "1.0.0", "type": "module", "scripts": { "build": "vite build", "preview": "vite preview" }, "dependencies": { "@phosphor-icons/react": "^2.0.15", "clsx": "^2.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", "recharts": "^2.10.3", "sonner": "^1.2.4", "tailwind-merge": "^2.2.0" }, "devDependencies": { "@types/react": "^18.2.46", "@types/react-dom": "^18.2.18", "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "^10.4.16", "postcss": "^8.4.32", "tailwindcss": "^3.4.0", "typescript": "^5.3.3", "vite": "^5.0.10" } } -
Create a shim for Spark hooks:
// src/spark-shims/hooks.js import { useState } from 'react'; // Simple localStorage-based shim for useKV hook export function useKV(key, initialValue) { const storageKey = `kv-${key}`; // Get from localStorage const stored = localStorage.getItem(storageKey); const initial = stored !== null ? JSON.parse(stored) : initialValue; const [value, setValue] = useState(initial); const setValueAndStore = (newValue) => { const valueToStore = newValue instanceof Function ? newValue(value) : newValue; setValue(valueToStore); localStorage.setItem(storageKey, JSON.stringify(valueToStore)); }; const deleteValue = () => { setValue(null); localStorage.removeItem(storageKey); }; return [value, setValueAndStore, deleteValue]; }
-
Update imports in your code:
# Replace imports from @github/spark/hooks with our shim find src -type f -name "*.ts" -o -name "*.tsx" | xargs sed -i 's/import {.*} from "@github\/spark\/hooks"/import { useKV } from "..\/spark-shims\/hooks"/g'
-
Install dependencies and build:
npm install npm run build
-
Create a gh-pages branch (if it doesn't exist):
git checkout --orphan gh-pages
-
Remove existing files:
git rm -rf . -
Copy build files:
cp -r temp_build/dist/* .
-
Create a .nojekyll file (important for proper GitHub Pages rendering):
touch .nojekyll
-
Commit and push:
git add . git commit -m "Deploy to GitHub Pages" git push -u origin gh-pages
-
Return to main branch:
git checkout main
Once deployed, your application will be available at:
https://[your-github-username].github.io/your-repo-name/
Replace your-repo-name with the actual name of your repository.
If you encounter any issues with the deployment:
- Check the GitHub Actions logs for any error messages
- Ensure GitHub Pages is properly configured in your repository settings
- Verify that the base path in the Vite configuration matches your repository name
- Check that the repository has proper permissions set for GitHub Pages deployment
- If using manual deployment, make sure you have a .nojekyll file in the gh-pages branch
- Verify that all paths in the application are relative, not absolute
When deployed to GitHub Pages, be aware that:
- The application is entirely client-side - all data processing happens in the browser
- No data is sent to any server when using the CSV upload feature
- If your CSV files are large, performance will depend on the user's device capabilities
- The localStorage-based KV store implementation means data will be persisted only in the user's browser