Skip to content

Commit 3be77b9

Browse files
gordoneySiarhei Balonikau
andauthored
Feature/epmgcip 152/configure staging (#19)
* feature/EPMGCIP-152/configure-staging * feature/EPMGCIP-152/update-readme * feature/EPMGCIP-152/tests-added --------- Co-authored-by: Siarhei Balonikau <[email protected]>
1 parent e7450d1 commit 3be77b9

File tree

5 files changed

+102
-18
lines changed

5 files changed

+102
-18
lines changed
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
# This file was auto-generated by the Firebase CLI
2-
# https://github.com/firebase/firebase-tools
3-
41
name: Deploy to Firebase Hosting on merge
52
'on':
63
push:
74
branches:
85
- main
96
env:
10-
VITE_CONTENTFUL_SPACE_ID: ${{secrets.VITE_CONTENTFUL_SPACE_ID}}
11-
VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN}}
12-
VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN}}
7+
VITE_CONTENTFUL_SPACE_ID: ${{secrets.VITE_CONTENTFUL_STAGING_SPACE_ID}}
8+
VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_STAGING_CONTENT_DELIVERY_ACCESS_TOKEN}}
9+
VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_STAGING_CONTENT_PREVIEW_ACCESS_TOKEN}}
1310
VITE_CONTENTFUL_ENVIRONMENT: ${{secrets.VITE_CONTENTFUL_ENVIRONMENT}}
14-
VITE_CONTENTFUL_GTAG_ID: ${{secrets.VITE_CONTENTFUL_GTAG_ID}}
11+
VITE_CONTENTFUL_GTAG_ID: ${{secrets.VITE_CONTENTFUL_STAGING_GTAG_ID}}
1512
jobs:
1613
build_and_deploy:
1714
runs-on: ubuntu-latest
@@ -24,3 +21,4 @@ jobs:
2421
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SAVITSKY_MUSEUM }}'
2522
channelId: live
2623
projectId: savitsky-museum
24+
target: staging-savitsky-museum
Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
# This file was auto-generated by the Firebase CLI
2-
# https://github.com/firebase/firebase-tools
3-
41
name: Deploy to Firebase Hosting on PR
52
'on': pull_request
3+
permissions:
4+
checks: write
5+
contents: read
6+
pull-requests: write
67
env:
7-
VITE_CONTENTFUL_SPACE_ID: ${{secrets.VITE_CONTENTFUL_SPACE_ID}}
8-
VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN}}
9-
VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN}}
8+
VITE_CONTENTFUL_SPACE_ID: ${{secrets.VITE_CONTENTFUL_STAGING_SPACE_ID}}
9+
VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_STAGING_CONTENT_DELIVERY_ACCESS_TOKEN}}
10+
VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_STAGING_CONTENT_PREVIEW_ACCESS_TOKEN}}
1011
VITE_CONTENTFUL_ENVIRONMENT: ${{secrets.VITE_CONTENTFUL_ENVIRONMENT}}
11-
VITE_CONTENTFUL_GTAG_ID: ${{secrets.VITE_CONTENTFUL_GTAG_ID}}
12+
VITE_CONTENTFUL_GTAG_ID: ${{secrets.VITE_CONTENTFUL_STAGING_GTAG_ID}}
1213
jobs:
1314
build_and_preview:
1415
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
1516
runs-on: ubuntu-latest
1617
steps:
1718
- uses: actions/checkout@v4
18-
- run: npm ci && npm run build
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20'
23+
- name: Install dependencies
24+
run: npm ci
25+
- name: Run Jest tests
26+
run: npm run test
27+
- name: Build
28+
run: npm run build
1929
- uses: FirebaseExtended/action-hosting-deploy@v0
2030
with:
2131
repoToken: '${{ secrets.GITHUB_TOKEN }}'
2232
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SAVITSKY_MUSEUM }}'
23-
projectId: savitsky-museum
33+
projectId: savitsky-museum
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Deploy to Firebase Hosting on release
2+
'on':
3+
release:
4+
types: [released]
5+
env:
6+
VITE_CONTENTFUL_SPACE_ID: ${{secrets.VITE_CONTENTFUL_SPACE_ID}}
7+
VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN}}
8+
VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN}}
9+
VITE_CONTENTFUL_ENVIRONMENT: ${{secrets.VITE_CONTENTFUL_ENVIRONMENT}}
10+
VITE_CONTENTFUL_GTAG_ID: ${{secrets.VITE_CONTENTFUL_GTAG_ID}}
11+
jobs:
12+
build_and_deploy:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- run: npm ci && npm run build
17+
- uses: FirebaseExtended/action-hosting-deploy@v0
18+
with:
19+
repoToken: '${{ secrets.GITHUB_TOKEN }}'
20+
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SAVITSKY_MUSEUM }}'
21+
channelId: live
22+
projectId: savitsky-museum
23+
target: savitsky-museum

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,41 @@ Instruction for setting up firebase hosting.
1616
h) "What script should be run before every deploy" - choose default - "npm ci && npm run build"<br>
1717
i) "Set up autpmatic deployment to your site's live channel when a PR is a merged" - y<br>
1818
j) "What is the name of the GitHub branch associated with your site's live channel" - choose default - "main"<br>
19+
20+
For handling multiple environments:
21+
1. Go to a Firebase Console (https://console.firebase.google.com/) -> Hosting -> Add another site ![Screenshot 2024-07-23 131226](https://github.com/user-attachments/assets/b966efbe-a70f-4448-ab4e-1d76539bc0e7)
22+
2. Add a website id, e.g. "staging-website"
23+
3. Update firebase json by adding a new site for "staging-website" and corrected main website. "site" should be equal to your site ID in firebase. e.g.
24+
```json
25+
{
26+
"hosting": [{
27+
"site": "production",
28+
"public": "public",
29+
"ignore": [
30+
"firebase.json",
31+
"**/.*",
32+
"**/node_modules/**"
33+
],
34+
"rewrites": [
35+
{
36+
"source": "**",
37+
"destination": "/index.html"
38+
}
39+
]
40+
}, {
41+
"site": "staging-website",
42+
"public": "public",
43+
"ignore": [
44+
"firebase.json",
45+
"**/.*",
46+
"**/node_modules/**"
47+
],
48+
"rewrites": [
49+
{
50+
"source": "**",
51+
"destination": "/index.html"
52+
}
53+
]
54+
}]
55+
}
56+
```

firebase.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"hosting": {
2+
"hosting": [{
3+
"site": "savitsky-museum",
34
"public": "public",
45
"ignore": [
56
"firebase.json",
@@ -12,5 +13,19 @@
1213
"destination": "/index.html"
1314
}
1415
]
15-
}
16+
}, {
17+
"site": "staging-savitsky-museum",
18+
"public": "public",
19+
"ignore": [
20+
"firebase.json",
21+
"**/.*",
22+
"**/node_modules/**"
23+
],
24+
"rewrites": [
25+
{
26+
"source": "**",
27+
"destination": "/index.html"
28+
}
29+
]
30+
}]
1631
}

0 commit comments

Comments
 (0)