-
-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (120 loc) · 4.83 KB
/
deploy-production.yml
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Deploy site (API) to firebase
on:
push:
branches:
- main
env:
NODE_VERSION: 20
TOKEN_FOR_WORKFLOW: ${{ secrets.TOKEN_FOR_WORKFLOW }}
FIREBASE_PROJECT: "production"
GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/firebase/functions/accounts/production.json
BRANCH: "main"
FIREBASE_PARENT_REPO: "dudko-dev/firebase-template"
FIREBASE_PARENT_BRANCH: "main"
FIREBASE_CHILD_REPO: "dudko-dev/firebase-template-functions"
FIREBASE_CHILD_BRANCH: "main"
SITE_DIR: "website"
FIREBASE_SITE_ALIAS: "website"
jobs:
deploy:
name: Deploy site to firebase
runs-on: ubuntu-latest
env:
ENVKEY: ${{ secrets.ENVKEY }}
timeout-minutes: 10
steps:
- name: Сheckout firebase repo (${{ env.FIREBASE_PARENT_REPO }})
uses: actions/checkout@v4
with:
repository: ${{ env.FIREBASE_PARENT_REPO }}
ref: refs/heads/${{ env.FIREBASE_PARENT_BRANCH }}
token: ${{ env.TOKEN_FOR_WORKFLOW }}
path: "firebase"
- name: Сheckout firebase functions repo (${{ env.FIREBASE_CHILD_REPO }})
uses: actions/checkout@v4
with:
repository: ${{ env.FIREBASE_CHILD_REPO }}
ref: refs/heads/${{ env.FIREBASE_CHILD_BRANCH }}
token: ${{ env.TOKEN_FOR_WORKFLOW }}
path: "firebase/functions"
- name: Make hosting directory
run: |
if [[ ! -d firebase/hosting ]]; then
mkdir firebase/hosting;
fi
- name: Сheckout site repo (${{ github.repository }})
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: ${{ github.ref }}
path: "firebase/hosting/${{ env.SITE_DIR }}"
- name: Change mode directory
run: chmod 0755 -R firebase
working-directory: ${{ github.workspace }}
- name: Install node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.yarn
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install build dependencies
run: sudo npm install firebase-tools yarn -g
working-directory: ${{ github.workspace }}/firebase
- name: Export envkey to file
run: echo "$ENVKEY">./.envkey
working-directory: ${{ github.workspace }}/firebase/functions
- name: Decrypt env and accounts files
run: npm run decrypt
working-directory: ${{ github.workspace }}/firebase/functions
- name: Select firebase project
run: firebase use $FIREBASE_PROJECT
working-directory: ${{ github.workspace }}/firebase/hosting/${{ env.SITE_DIR }}
- name: Install dependencies
run: yarn install --frozen-lockfile
working-directory: ${{ github.workspace }}/firebase/hosting/${{ env.SITE_DIR }}
- name: Remove production config
if: ${{ env.FIREBASE_PROJECT != 'production' }}
run: rm -f ./.env.production
working-directory: ${{ github.workspace }}/firebase/hosting/${{ env.SITE_DIR }}
- name: Copy config to production
if: ${{ env.FIREBASE_PROJECT != 'production' }}
run: cp ./.env.$FIREBASE_PROJECT ./.env.production
working-directory: ${{ github.workspace }}/firebase/hosting/${{ env.SITE_DIR }}
- name: Build app
run: yarn build
working-directory: ${{ github.workspace }}/firebase/hosting/${{ env.SITE_DIR }}
- name: Deploy to firebase
run: firebase deploy -m "Autodeploy from GitHUB ($GITHUB_ACTOR)" --only hosting:$FIREBASE_SITE_ALIAS
working-directory: ${{ github.workspace }}/firebase/hosting/${{ env.SITE_DIR }}
# - name: The job has failed - archive result
# if: ${{ failure() }}
# run: |
# if [[ -d ${{ github.workspace }}/firebase ]]; then
# tar -czf firebase.tar.gz firebase;
# fi
# working-directory: ${{ github.workspace }}
# - name: The job has failed - archive npm logs
# if: ${{ failure() }}
# run: |
# if [[ -d /home/runner/.npm/_logs ]]; then
# tar -czf ${{ github.workspace }}/npm-logs.tar.gz /home/runner/.npm/_logs;
# fi
# working-directory: /
# - name: The job has failed - upload artifacts
# if: ${{ failure() }}
# uses: actions/upload-artifact@v4
# with:
# name: ${{ env.FIREBASE_PROJECT }}-site-${{ env.FIREBASE_SITE_ALIAS }}-debug
# path: |
# ${{ github.workspace }}/firebase.tar.gz
# ${{ github.workspace }}/npm-logs.tar.gz
# retention-days: 1