Skip to content

Commit bfcca49

Browse files
authored
Merge pull request #149 from weaponsforge/dev
v4.1.0
2 parents cc0a781 + 2582134 commit bfcca49

File tree

6 files changed

+151
-17
lines changed

6 files changed

+151
-17
lines changed

.github/workflows/deploy-dev.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
branches:
88
- dev
99

10+
env:
11+
FIREBASE_TARGET: 'dev'
12+
1013
jobs:
1114
lint-export-client:
1215
name: Lint and Export client
@@ -17,11 +20,14 @@ jobs:
1720
NEXT_PUBLIC_FIREBASE_WEB_AUTHDOMAIN: ${{ secrets.FIREBASE_WEB_AUTHDOMAIN_DEV }}
1821
NEXT_PUBLIC_FIREBASE_WEB_PROJECT_ID: ${{ secrets.FIREBASE_WEB_PROJECT_ID_DEV }}
1922
NEXT_PUBLIC_FIREBASE_WEB_STORAGE_BUCKET: ${{ secrets.FIREBASE_WEB_STORAGE_BUCKET_DEV }}
23+
FIREBASE_HOSTING_DEV: ${{ secrets.FIREBASE_HOSTING_DEV }}
2024
steps:
2125
- name: Checkout the repository
2226
uses: actions/checkout@v3
2327
with:
24-
ref: 'dev'
28+
ref: ${{ env.FIREBASE_TARGET }}
29+
- name: Build Firebase Settings
30+
run: chmod u+x scripts/build.sh && ./scripts/build.sh
2531
- name: Use NodeJS v16.14.2
2632
uses: actions/setup-node@v3
2733
with:
@@ -47,9 +53,13 @@ jobs:
4753
client/out
4854
client/firebase.json
4955
client/.firebaserc
56+
client/firestore.rules
57+
client/firestore.indexes.json
58+
client/storage.rules
5059
retention-days: 3
5160

52-
deploy-client:
61+
# Deploy Firebase: Hosting, Firestore/Storage Rules and Indexes
62+
deploy-firebase:
5363
name: Deploy Client to Firebase Hosting
5464
needs: lint-export-client
5565
runs-on: ubuntu-latest
@@ -61,6 +71,8 @@ jobs:
6171
- name: Deploy to Firebase
6272
uses: w9jds/firebase-action@master
6373
with:
64-
args: use dev && firebase deploy --only hosting:dev
74+
args: >
75+
use $FIREBASE_TARGET &&
76+
firebase deploy --only firestore:rules,firestore:indexes,storage,hosting:$FIREBASE_TARGET
6577
env:
6678
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

.github/workflows/release.yml

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
name: Deploy to GitHub Pages
1+
name: Prduction - Deploy to GitHub Pages
22

33
# This workflow will trigger on any tag/release created on *any* branch
44
# Make sure to create tags/releases only from the "master" branch for consistency
55
on:
66
release:
77
types: [published]
88

9+
env:
10+
FIREBASE_TARGET: 'prod'
11+
912
jobs:
1013
lint-export-client:
1114
name: Lint and Export client
15+
if: github.event.release.target_commitish == 'master'
1216
runs-on: ubuntu-latest
1317
env:
1418
NEXT_PUBLIC_BASE_PATH: ${{ secrets.NEXT_PUBLIC_BASE_PATH }}
@@ -21,6 +25,8 @@ jobs:
2125
uses: actions/checkout@v3
2226
with:
2327
ref: ${{ github.event.release.tag_name }}
28+
- name: Build Firebase Settings
29+
run: chmod u+x scripts/build.sh && ./scripts/build.sh
2430
- name: Use NodeJS v16.14.2
2531
uses: actions/setup-node@v3
2632
with:
@@ -45,11 +51,38 @@ jobs:
4551
with:
4652
name: main-out
4753
include-hidden-files: true
48-
path: client/out
54+
path: |
55+
client/out
56+
client/firebase.json
57+
client/.firebaserc
58+
client/firestore.rules
59+
client/firestore.indexes.json
60+
client/storage.rules
4961
retention-days: 3
5062

63+
# Deploy Firebase: Firestore/Storage Rules and Indexes
64+
deploy-firebase:
65+
name: Deploy Firebase Settings
66+
if: github.event.release.target_commitish == 'master'
67+
needs: lint-export-client
68+
runs-on: ubuntu-latest
69+
steps:
70+
- name: Download Artifact
71+
uses: actions/download-artifact@v4
72+
with:
73+
name: main-out
74+
- name: Deploy to Firebase
75+
uses: w9jds/firebase-action@master
76+
with:
77+
args: >
78+
use $FIREBASE_TARGET &&
79+
firebase deploy --only firestore:rules,firestore:indexes,storage
80+
env:
81+
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
82+
5183
deploy-client:
52-
name: Deploy client to Github Pages
84+
name: Deploy Client to Github Pages
85+
if: github.event.release.target_commitish == 'master'
5386
needs: lint-export-client
5487
runs-on: ubuntu-latest
5588
steps:
@@ -63,5 +96,5 @@ jobs:
6396
uses: peaceiris/actions-gh-pages@v3
6497
with:
6598
github_token: ${{ secrets.GITHUB_TOKEN }}
66-
publish_dir: ./
99+
publish_dir: ./out
67100
publish_branch: gh-pages

README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ It also features a lightweight Content Management System (CMS) for creating and
1010
https://weaponsforge.github.io/gsites-components/
1111

1212
#### Development (Playground) App
13-
https://gsites-components.web.app/
13+
https://climate-profile-dev.web.app/
1414

1515
```
1616
EXAMPLE USER (Development App Only)
@@ -115,5 +115,66 @@ docker compose -f docker-compose.prod.yml up
115115
docker compose -f docker-compose.prod.yml down
116116
```
117117

118+
## Deploy With GitHub Actions
119+
120+
### Requirements
121+
122+
1. Two (2) Firebase Projects (to use for development/production environments), pre-activated with:
123+
- Firestore Database
124+
- Firebase Storage
125+
- Firebase Hosting
126+
- Authentication (Email/Address)
127+
128+
> [!TIP]
129+
> Refer to the server README for additional setup information
130+
131+
2. Firebase configuration settings for each of the two (2) Firebase projects.
132+
133+
3. Service account JSON file for each of the two (2) Firebase projects.
134+
135+
## Steps
136+
137+
Follow the steps to self-host the project in your own repository and Firebase projects.
138+
139+
### 1. GitHub Secrets
140+
141+
Create the following GitHub Secrets, using values from the Firebase (web) configuration and settings from the requirements.
142+
143+
| GitHub Secret | Description |
144+
| --- | --- |
145+
| NEXT_PUBLIC_BASE_PATH | Root directory path name that NextJS uses for assets, media and client-side routing for the app.<br><br>Set its value to blank `''` when working on development mode in localhost.<br><br>Set its value to the sub-directory name where the exported NextJS app is to be deployed, i.e. `/<YOUR_REPOSITORY_NAME>` when<br> deploying on a repository (sub-directory) of a root GitHub Pages site, i.e, on `https://<YOUR_GITHUB_USERNAME>.github.io/<YOUR_REPOSITORY_NAME>` |
146+
| FIREBASE_WEB_API_KEY_DEV | Firebase web API key from the Firebase Project Settings configuration file for the (development) environment. |
147+
| FIREBASE_WEB_AUTHDOMAIN_DEV | Firebase web auth domain key from the Firebase Project Settings configuration for the (development) environment. |
148+
| FIREBASE_WEB_PROJECT_ID_DEV | Firebase web project ID from the Firebase Project Settings configuration file for the (development) environment. |
149+
| FIREBASE_WEB_STORAGE_BUCKET_DEV | Firebase web storage bucket key from the Firebase Project Settings configuration file for the (development) environment. |
150+
| FIREBASE_WEB_API_KEY_PROD | Firebase web API key from the Firebase Project Settings configuration file for the (production) environment. |
151+
| FIREBASE_WEB_AUTHDOMAIN_PROD | Firebase web auth domain key from the Firebase Project Settings configuration for the (production) environment. |
152+
| FIREBASE_WEB_PROJECT_ID_PROD | Firebase web project ID from the Firebase Project Settings configuration file for the (production) environment. |
153+
| FIREBASE_WEB_STORAGE_BUCKET_PROD | Firebase web storage bucket key from the Firebase Project Settings configuration file for the (production) environment. |
154+
| FIREBASE_TOKEN | Firebase CLI deploy token, retrieved with `"firebase login:ci"` |
155+
| FIREBASE_HOSTING_DEV | Firebase Hosting name under the `FIREBASE_WEB_PROJECT_ID_DEV` |
156+
157+
### 2. Firebase Hosting
158+
159+
Initialize a Firebase Hosting website in the _**development**_ Firebase project.
160+
161+
### 3. GitHub Pages
162+
163+
Initialize an empty branch in the repository to use for deployment to GitHub Pages.
164+
165+
```bash
166+
# While inside the project code repository root
167+
git checkout --orphan gh-pages
168+
git reset
169+
git commit --allow-empty -m "Initial commit"
170+
git push --set-upstream origin gh-pages
171+
```
172+
173+
### 4. Ship and Deploy
174+
175+
- Deploy to the **development** environment (Firebase Hosting) by pushing or merging updates to the `dev` branch.
176+
- Deploy to the **production** environment (GitHub Pages) by creating a Release/Tag from the `master` branch.
177+
178+
118179
@weaponsforge<br>
119180
20230326

client/.firebaserc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
22
"projects": {
3-
"dev": "climate-profile-app",
4-
"prod": "gsites-embed"
3+
"dev": "FIREBASE_PROJECT_DEV",
4+
"prod": "FIREBASE_PROJECT_PROD"
55
},
66
"targets": {
7-
"climate-profile-app": {
7+
"FIREBASE_PROJECT_DEV": {
88
"hosting": {
99
"dev": [
10-
"climate-profile-dev"
10+
"FIREBASE_HOSTING_DEV"
1111
]
1212
},
1313
"storage": {
1414
"dev": [
15-
"climate-profile-app.appspot.com"
15+
"FIREBASE_PROJECT_DEV.appspot.com"
1616
]
1717
}
1818
},
19-
"gsites-embed": {
19+
"FIREBASE_PROJECT_PROD": {
2020
"storage": {
2121
"dev": [
22-
"gsites-embed.appspot.com"
22+
"FIREBASE_PROJECT_PROD.appspot.com"
2323
]
2424
}
2525
}

client/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## gsites-components
1+
## /gsites-components/client
22

33
Testing display of all related content based on a URL query string.
44

@@ -18,7 +18,7 @@ Testing display of all related content based on a URL query string.
1818
https://weaponsforge.github.io/gsites-components/
1919

2020
#### Development App
21-
https://gsites-components.web.app/
21+
https://climate-profile-dev.web.app/
2222

2323
```
2424
EXAMPLE USER (Development App Only)
@@ -42,6 +42,19 @@ password: useruser
4242
| NEXT_PUBLIC_FIREBASE_WEB_STORAGE_BUCKET | Firebase web storage bucket key from the Firebase Project Settings configuration file. |
4343
| WATCHPACK_POLLING | Enables hot reload on NextJS apps (tested on NextJS v13.2.1) running inside Docker containers on a Windows host. Set it to `true` if running Docker Desktop with WSL2 on a Windows OS. |
4444

45+
3. Update the `.firebaserc` file.
46+
- Replace all instances of the `FIREBASE_PROJECT_DEV` text with the **development** Firebase project ID.
47+
- Replace all instances of the `FIREBASE_PROJECT_PROD` text with eth **production** Firebase project ID.
48+
- Replace the `FIREBASE_HOSTING_DEV` text with the **development** Firebase Hosting website name (minus the `".web.app"`)
49+
50+
> [!WARNING]
51+
> Do not commit the updates in the `.firebaserc` file, if you plan on deploying updates using GitHub Actions.<br>
52+
> Do the following to avoid commiting local updates in the `.firebaserc` file:
53+
> - Ignore local changes to the file.<br>
54+
> `git update-index --assume-unchanged .firebaserc`
55+
> - Revert/start tracking later if needed.<br>
56+
> `git update-index --no-assume-unchanged .firebaserc`
57+
4558
3. Switch to the **dev** Firebase target.<br>
4659
`firebase use dev`
4760

scripts/build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
echo "Setting the .firebaserc values..."
4+
5+
if [ "$FIREBASE_TARGET" == "dev" ]; then
6+
# Replace placeholders with development Firebase settings
7+
sed -i -e "s/FIREBASE_PROJECT_DEV/${NEXT_PUBLIC_FIREBASE_WEB_PROJECT_ID}/g" client/.firebaserc
8+
sed -i -e "s/FIREBASE_HOSTING_DEV/${FIREBASE_HOSTING_DEV}/g" client/.firebaserc
9+
elif [ "$FIREBASE_TARGET" == "prod" ]; then
10+
# Replace placeholders with production Firebase settings
11+
sed -i -e "s/FIREBASE_PROJECT_PROD/${NEXT_PUBLIC_FIREBASE_WEB_PROJECT_ID}/g" client/.firebaserc
12+
else
13+
echo "Error: FIREBASE_TARGET must be 'dev' or 'prod', value: $FIREBASE_TARGET"
14+
exit 1
15+
fi

0 commit comments

Comments
 (0)