-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (76 loc) · 2.68 KB
/
Copy pathfirebase-ci-cd.yml
File metadata and controls
88 lines (76 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# CI: validate on every PR / push to main
# CD: deploy Firebase Hosting on push to main (requires repo secret — see README)
#
# Note: GitHub does not allow `secrets.*` inside step `if:` expressions (parse error).
# We use a tiny job that maps the secret to a boolean job output, then `needs.*` in deploy `if:`.
name: Firebase CI / Hosting deploy
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: read
jobs:
ci:
name: Validate project
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Validate firebase.json
run: python3 -c "import json; json.load(open('firebase.json'))"
- name: Syntax-check desktop app
run: python3 -m py_compile just_do_it.py
- name: Setup Node (functions)
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: functions/package-lock.json
- name: Install & check Cloud Functions
working-directory: functions
run: |
npm ci
node --check index.js
# secrets cannot be used in step `if:` — expose only true/false via job output
gate-firebase-secret:
name: Check Hosting deploy secret
runs-on: ubuntu-latest
outputs:
deploy_ok: ${{ steps.check.outputs.deploy_ok }}
steps:
- id: check
env:
CREDS: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_JSON }}
run: |
if [ -n "$CREDS" ]; then
echo "deploy_ok=true" >> "$GITHUB_OUTPUT"
else
echo "deploy_ok=false" >> "$GITHUB_OUTPUT"
fi
- name: Missing secret notice
if: steps.check.outputs.deploy_ok == 'false'
run: |
echo "::notice::FIREBASE_SERVICE_ACCOUNT_JSON is not set — Hosting deploy job will be skipped."
deploy-hosting:
name: Deploy Firebase Hosting
runs-on: ubuntu-latest
needs: [ci, gate-firebase-secret]
if: >-
needs.gate-firebase-secret.outputs.deploy_ok == 'true' &&
github.repository == 'letsjoyn/just-do-it' &&
(github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && github.ref == 'refs/heads/main'))
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy to Firebase Hosting
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_JSON }}
projectId: just-do-it-1fa38
# Production; omitting uses preview channel deploy (fails: "channelID is currently required")
channelId: live