Skip to content
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