Skip to content

Commit c9b4a1e

Browse files
feat(config): add commitlint and husky setup for controlled deployments
1 parent a96d662 commit c9b4a1e

File tree

4 files changed

+201
-6
lines changed

4 files changed

+201
-6
lines changed

.firebaserc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"projects": {
3-
"default": "your-firebase-project-id"
3+
"default": "angular-admin-blog"
44
},
55
"targets": {
6-
"your-firebase-project-id": {
6+
"angular-admin-blog": {
77
"hosting": {
88
"admin": [
9-
"admin-site-id"
9+
"angular-admin-blog"
1010
],
1111
"samples": [
12-
"samples-site-id"
12+
"angular-admin-blog-samples"
1313
]
1414
}
1515
}
16-
}
17-
}
16+
},
17+
"etags": {}
18+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Deploy Admin App to Firebase
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'projects/admin/**'
9+
- 'firebase.json'
10+
- '.firebaserc'
11+
- 'package*.json'
12+
pull_request:
13+
branches:
14+
- main
15+
paths:
16+
- 'projects/admin/**'
17+
- 'firebase.json'
18+
- '.firebaserc'
19+
- 'package*.json'
20+
21+
jobs:
22+
build-and-deploy:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: '20'
33+
cache: 'npm'
34+
35+
- name: Install dependencies
36+
run: npm ci
37+
38+
- name: Lint admin project
39+
run: npm run lint:admin
40+
41+
- name: Test admin project
42+
run: npm run test -- admin --watch=false --browsers=ChromeHeadless
43+
44+
- name: Build admin project
45+
run: ng build admin --configuration=production
46+
47+
- name: Deploy to Firebase Preview (PR)
48+
if: github.event_name == 'pull_request'
49+
uses: FirebaseExtended/action-hosting-deploy@v0
50+
with:
51+
repoToken: '${{ secrets.GITHUB_TOKEN }}'
52+
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_ANGULAR_ADMIN_BLOG }}'
53+
projectId: angular-admin-blog
54+
channelId: pr-${{ github.event.number }}
55+
target: admin
56+
expires: 7d
57+
env:
58+
FIREBASE_CLI_EXPERIMENTS: webframeworks
59+
60+
- name: Deploy to Firebase Live (Main Branch)
61+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
62+
uses: FirebaseExtended/action-hosting-deploy@v0
63+
with:
64+
repoToken: '${{ secrets.GITHUB_TOKEN }}'
65+
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_ANGULAR_ADMIN_BLOG }}'
66+
projectId: angular-admin-blog
67+
channelId: live
68+
target: admin
69+
env:
70+
FIREBASE_CLI_EXPERIMENTS: webframeworks
71+
72+
- name: Add PR Comment
73+
if: github.event_name == 'pull_request'
74+
uses: actions/github-script@v7
75+
with:
76+
script: |
77+
const { data: comments } = await github.rest.issues.listComments({
78+
owner: context.repo.owner,
79+
repo: context.repo.repo,
80+
issue_number: context.issue.number,
81+
});
82+
83+
const botComment = comments.find(comment =>
84+
comment.user.type === 'Bot' &&
85+
comment.body.includes('🔥 Firebase Admin Preview')
86+
);
87+
88+
const body = `
89+
## 🔥 Firebase Admin Preview Deployed
90+
91+
**Preview URL**: https://angular-admin-blog--pr-${{ github.event.number }}-8t1hsdkv.web.app
92+
93+
Changes in this PR have been deployed to a preview channel.
94+
The preview will be available for 7 days.
95+
96+
### What's included:
97+
- ✅ Admin application build
98+
- ✅ Security headers configured
99+
- ✅ SPA routing enabled
100+
- ✅ Production optimizations
101+
`;
102+
103+
if (botComment) {
104+
await github.rest.issues.updateComment({
105+
owner: context.repo.owner,
106+
repo: context.repo.repo,
107+
comment_id: botComment.id,
108+
body: body
109+
});
110+
} else {
111+
await github.rest.issues.createComment({
112+
owner: context.repo.owner,
113+
repo: context.repo.repo,
114+
issue_number: context.issue.number,
115+
body: body
116+
});
117+
}

FIREBASE_DEPLOYMENT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Firebase Admin Deployment
2+
3+
## Overview
4+
The Angular admin application is deployed to Firebase Hosting with automated CI/CD.
5+
6+
## Live URLs
7+
- **Primary**: https://angular-admin-blog.web.app
8+
- **Custom Domain**: https://app.angular.fun
9+
10+
## Project Configuration
11+
- **Firebase Project ID**: `angular-admin-blog`
12+
- **Hosting Target**: `admin`
13+
- **Build Output**: `dist/admin/browser`
14+
15+
## Features Configured
16+
17+
### ✅ Production Deployment
18+
- Optimized Angular build
19+
- Asset caching with immutable headers
20+
- SPA routing configured
21+
22+
### ✅ Security Headers
23+
- Content Security Policy (CSP)
24+
- X-Frame-Options: DENY
25+
- X-Content-Type-Options: nosniff
26+
- Referrer-Policy: strict-origin-when-cross-origin
27+
- Permissions-Policy for privacy
28+
29+
### ✅ Preview Channels
30+
- Automatic PR previews via GitHub Actions
31+
- 7-day expiration for preview deployments
32+
- Unique URLs per PR: `angular-admin-blog--pr-{number}-*.web.app`
33+
34+
### ✅ CI/CD Automation
35+
- **Triggers**: Changes to `projects/admin/**`, `firebase.json`, etc.
36+
- **PR Flow**: Lint → Test → Build → Deploy to preview channel
37+
- **Main Branch**: Deploy to live site
38+
- **PR Comments**: Automatic preview URL posting
39+
40+
## Manual Commands
41+
42+
```bash
43+
# Deploy to live site
44+
firebase deploy --only hosting:admin
45+
46+
# Deploy to preview channel
47+
firebase hosting:channel:deploy preview --only admin
48+
49+
# Create new preview channel
50+
firebase hosting:channel:create <channel-name> --site angular-admin-blog
51+
```
52+
53+
## GitHub Secrets Required
54+
55+
For CI/CD to work, add this secret to your GitHub repository:
56+
- `FIREBASE_SERVICE_ACCOUNT_ANGULAR_ADMIN_BLOG`
57+
58+
To get the service account key:
59+
1. Go to [Firebase Console](https://console.firebase.google.com/project/angular-admin-blog/settings/serviceaccounts/adminsdk)
60+
2. Generate new private key
61+
3. Copy the JSON content to GitHub secret
62+
63+
## Build Process
64+
1. Install dependencies (`npm ci`)
65+
2. Lint admin project
66+
3. Run tests
67+
4. Build for production
68+
5. Deploy to Firebase Hosting
69+
70+
## Cache Strategy
71+
- **HTML files**: No cache (always fresh)
72+
- **Assets** (JS/CSS/fonts/images): 1 year cache with immutable flag
73+
- **Micro-frontend remoteEntry**: 1 year cache + CORS headers
74+
75+
## Redirects
76+
- `/admin``/` (301 redirect for legacy paths)

test-web.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

0 commit comments

Comments
 (0)