Skip to content

Commit eda63b6

Browse files
authored
Merge pull request #1 from nonstopio/feature/github-actions-deployment
Add GitHub Actions CI/CD for Netlify deployment
2 parents 2150daf + e99d049 commit eda63b6

File tree

6 files changed

+13836
-201
lines changed

6 files changed

+13836
-201
lines changed

.github/DEPLOYMENT.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Deployment Setup Guide
2+
3+
This repository is configured for automatic deployment to Netlify using GitHub Actions.
4+
5+
## Required GitHub Secrets
6+
7+
To enable automatic deployment, you need to add these secrets in your GitHub repository:
8+
9+
### 1. NETLIFY_AUTH_TOKEN
10+
1. Go to [Netlify](https://app.netlify.com)
11+
2. Navigate to **User Settings****Applications****Personal access tokens**
12+
3. Click **"New access token"**
13+
4. Give it a name (e.g., "JSON Viewer GitHub Actions")
14+
5. Copy the generated token
15+
6. In GitHub: **Settings****Secrets and variables****Actions****New repository secret**
16+
7. Name: `NETLIFY_AUTH_TOKEN`
17+
8. Value: Paste the token
18+
19+
### 2. NETLIFY_SITE_ID
20+
1. In Netlify, go to your site dashboard
21+
2. Navigate to **Site settings****General****Site details**
22+
3. Copy the **Site ID** (format: `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`)
23+
4. In GitHub: **Settings****Secrets and variables****Actions****New repository secret**
24+
5. Name: `NETLIFY_SITE_ID`
25+
6. Value: Paste the Site ID
26+
27+
## How It Works
28+
29+
- **Automatic Deployment**: Every push to `main` branch triggers a build and deployment
30+
- **Pull Request Previews**: PRs create preview deployments for testing
31+
- **Build Caching**: npm dependencies are cached for faster builds
32+
- **Security Headers**: Netlify.toml includes security and performance headers
33+
34+
## Manual Deployment
35+
36+
If you need to deploy manually:
37+
38+
```bash
39+
npm run build
40+
netlify deploy --prod --dir=dist
41+
```
42+
43+
## Troubleshooting
44+
45+
### Build Fails
46+
- Check the GitHub Actions log for detailed error messages
47+
- Ensure all dependencies are listed in package.json
48+
- Verify Node.js version compatibility (using Node 20)
49+
50+
### Deployment Fails
51+
- Verify both secrets are correctly set in GitHub
52+
- Check that NETLIFY_SITE_ID matches your Netlify site
53+
- Ensure NETLIFY_AUTH_TOKEN has proper permissions
54+
55+
### Custom Domain
56+
- Configure custom domain in Netlify dashboard
57+
- Update DNS records to point to Netlify
58+
- SSL certificates are automatically generated
59+
60+
## Support
61+
62+
For issues with deployment, check:
63+
1. GitHub Actions workflow logs
64+
2. Netlify deployment logs
65+
3. Ensure secrets are properly configured

.github/workflows/deploy.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build and Deploy to Netlify
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-and-deploy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout Repository
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '20'
21+
cache: 'npm'
22+
23+
- name: Install Dependencies
24+
run: npm ci
25+
26+
- name: Run Tests (if any)
27+
run: npm run test --if-present
28+
29+
- name: Build Project
30+
run: npm run build
31+
32+
- name: Deploy to Netlify
33+
uses: nwtgck/[email protected]
34+
with:
35+
publish-dir: './dist'
36+
production-branch: main
37+
github-token: ${{ secrets.GITHUB_TOKEN }}
38+
deploy-message: "Deploy from GitHub Actions"
39+
enable-pull-request-comment: false
40+
enable-commit-comment: true
41+
overwrites-pull-request-comment: true
42+
env:
43+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
44+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
45+
timeout-minutes: 1

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,11 @@ ga-key.json
327327
Dockerfile*
328328
docker-compose*
329329

330-
# Kubernetes
330+
# Kubernetes (but not GitHub workflows or config files)
331331
*.yaml
332332
*.yml
333+
!.github/**/*.yml
334+
!.github/**/*.yaml
333335
!package.json
334336
!tsconfig.json
335337
!vite.config.ts

netlify.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[build]
2+
command = "npm run build"
3+
publish = "dist"
4+
5+
[build.environment]
6+
NODE_VERSION = "20"
7+
8+
# Redirect all routes to index.html for SPA
9+
[[redirects]]
10+
from = "/*"
11+
to = "/index.html"
12+
status = 200
13+
14+
# Development server configuration
15+
[dev]
16+
command = "npm run dev"
17+
port = 5173
18+
publish = "dist"
19+
20+
# Headers for security and performance
21+
[[headers]]
22+
for = "/*"
23+
[headers.values]
24+
X-Frame-Options = "DENY"
25+
X-XSS-Protection = "1; mode=block"
26+
X-Content-Type-Options = "nosniff"
27+
Referrer-Policy = "strict-origin-when-cross-origin"
28+
Permissions-Policy = "camera=(), microphone=(), geolocation=()"
29+
30+
# Cache static assets
31+
[[headers]]
32+
for = "/assets/*"
33+
[headers.values]
34+
Cache-Control = "public, max-age=31536000, immutable"

0 commit comments

Comments
 (0)