Skip to content

Commit 36c253a

Browse files
add workflow
1 parent 9916054 commit 36c253a

3 files changed

Lines changed: 44 additions & 17 deletions

File tree

.github/workflows/firebase-hosting.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,30 @@ on:
99
workflow_dispatch:
1010

1111
jobs:
12-
checkout:
12+
deploy:
1313
runs-on: ubuntu-latest
14+
environment: release
1415
steps:
15-
- uses: actions/checkout@v4
16+
- name: Checkout
17+
uses: actions/checkout@v4
1618

17-
add_secret_redirects:
18-
runs-on: ubuntu-latest
19-
steps:
20-
- uses: jsdaniell/create-json@v1.2.3
19+
- name: Use Node.js
20+
uses: actions/setup-node@v4
2121
with:
22-
name: "secret-redirects.json"
23-
json: ${{ secrets.SECRET_REDIRECTS }}
24-
- uses: mpmxyz/merge-json-with-template@latest
25-
with:
26-
source-file: "firebase.json"
27-
target-file: "secret-redirects.json"
22+
node-version: "22.x"
2823

29-
deploy:
30-
runs-on: ubuntu-latest
31-
steps:
32-
- uses: actions/checkout@v4
33-
- uses: FirebaseExtended/action-hosting-deploy@v0
24+
- name: Create secret-redirects.json
25+
run: |
26+
echo "$SECRET_REDIRECTS" > secret-redirects.json
27+
env:
28+
SECRET_REDIRECTS: ${{secrets.SECRET_REDIRECTS}}
29+
30+
- name: Merge secret-redirects.json into firebase.json
31+
run: |
32+
node merge-json.mjs
33+
34+
- name: Deploy to Firebase Hosting
35+
uses: FirebaseExtended/action-hosting-deploy@v0
3436
with:
3537
repoToken: ${{ secrets.GITHUB_TOKEN }}
3638
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_K_DEVCON }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ node_modules/
6464

6565
# dotenv environment variables file
6666
.env
67+
68+
secret-redirects.json

merge-json.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import firebaseConfig from "./firebase.json" with { type: "json" };
2+
import fs from "fs";
3+
4+
const secretRedirectsJsonPath = "secret-redirects.json";
5+
if (fs.existsSync(secretRedirectsJsonPath)) {
6+
try {
7+
const secretRedirectsJson = fs.readFileSync(
8+
secretRedirectsJsonPath,
9+
"utf-8"
10+
);
11+
const secretRedirects = JSON.parse(secretRedirectsJson);
12+
firebaseConfig['hosting']['redirects'].push(...secretRedirects);
13+
14+
const firebaseConfigJson = JSON.stringify(firebaseConfig, null, 2);
15+
fs.writeFileSync(
16+
"firebase.json",
17+
firebaseConfigJson,
18+
"utf-8"
19+
);
20+
} catch (error) {
21+
console.error("merge failed", error);
22+
}
23+
}

0 commit comments

Comments
 (0)