Skip to content

Commit

Permalink
Feature/epmgcip 152/configure staging (#19)
Browse files Browse the repository at this point in the history
* feature/EPMGCIP-152/configure-staging

* feature/EPMGCIP-152/update-readme

* feature/EPMGCIP-152/tests-added

---------

Co-authored-by: Siarhei Balonikau <[email protected]>
  • Loading branch information
gordoney and Siarhei Balonikau authored Jul 23, 2024
1 parent e7450d1 commit 3be77b9
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 18 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- main
env:
VITE_CONTENTFUL_SPACE_ID: ${{secrets.VITE_CONTENTFUL_SPACE_ID}}
VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN}}
VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN}}
VITE_CONTENTFUL_SPACE_ID: ${{secrets.VITE_CONTENTFUL_STAGING_SPACE_ID}}
VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_STAGING_CONTENT_DELIVERY_ACCESS_TOKEN}}
VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_STAGING_CONTENT_PREVIEW_ACCESS_TOKEN}}
VITE_CONTENTFUL_ENVIRONMENT: ${{secrets.VITE_CONTENTFUL_ENVIRONMENT}}
VITE_CONTENTFUL_GTAG_ID: ${{secrets.VITE_CONTENTFUL_GTAG_ID}}
VITE_CONTENTFUL_GTAG_ID: ${{secrets.VITE_CONTENTFUL_STAGING_GTAG_ID}}
jobs:
build_and_deploy:
runs-on: ubuntu-latest
Expand All @@ -24,3 +21,4 @@ jobs:
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SAVITSKY_MUSEUM }}'
channelId: live
projectId: savitsky-museum
target: staging-savitsky-museum
28 changes: 19 additions & 9 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on PR
'on': pull_request
permissions:
checks: write
contents: read
pull-requests: write
env:
VITE_CONTENTFUL_SPACE_ID: ${{secrets.VITE_CONTENTFUL_SPACE_ID}}
VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN}}
VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN}}
VITE_CONTENTFUL_SPACE_ID: ${{secrets.VITE_CONTENTFUL_STAGING_SPACE_ID}}
VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_STAGING_CONTENT_DELIVERY_ACCESS_TOKEN}}
VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_STAGING_CONTENT_PREVIEW_ACCESS_TOKEN}}
VITE_CONTENTFUL_ENVIRONMENT: ${{secrets.VITE_CONTENTFUL_ENVIRONMENT}}
VITE_CONTENTFUL_GTAG_ID: ${{secrets.VITE_CONTENTFUL_GTAG_ID}}
VITE_CONTENTFUL_GTAG_ID: ${{secrets.VITE_CONTENTFUL_STAGING_GTAG_ID}}
jobs:
build_and_preview:
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Run Jest tests
run: npm run test
- name: Build
run: npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SAVITSKY_MUSEUM }}'
projectId: savitsky-museum
projectId: savitsky-museum
23 changes: 23 additions & 0 deletions .github/workflows/firebase-hosting-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Deploy to Firebase Hosting on release
'on':
release:
types: [released]
env:
VITE_CONTENTFUL_SPACE_ID: ${{secrets.VITE_CONTENTFUL_SPACE_ID}}
VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_DELIVERY_ACCESS_TOKEN}}
VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN: ${{secrets.VITE_CONTENTFUL_CONTENT_PREVIEW_ACCESS_TOKEN}}
VITE_CONTENTFUL_ENVIRONMENT: ${{secrets.VITE_CONTENTFUL_ENVIRONMENT}}
VITE_CONTENTFUL_GTAG_ID: ${{secrets.VITE_CONTENTFUL_GTAG_ID}}
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SAVITSKY_MUSEUM }}'
channelId: live
projectId: savitsky-museum
target: savitsky-museum
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,41 @@ Instruction for setting up firebase hosting.
h) "What script should be run before every deploy" - choose default - "npm ci && npm run build"<br>
i) "Set up autpmatic deployment to your site's live channel when a PR is a merged" - y<br>
j) "What is the name of the GitHub branch associated with your site's live channel" - choose default - "main"<br>

For handling multiple environments:
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)
2. Add a website id, e.g. "staging-website"
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.
```json
{
"hosting": [{
"site": "production",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}, {
"site": "staging-website",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}]
}
```
19 changes: 17 additions & 2 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"hosting": {
"hosting": [{
"site": "savitsky-museum",
"public": "public",
"ignore": [
"firebase.json",
Expand All @@ -12,5 +13,19 @@
"destination": "/index.html"
}
]
}
}, {
"site": "staging-savitsky-museum",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}]
}

0 comments on commit 3be77b9

Please sign in to comment.