How to deploy a web app in firebase hosting with gut hub action

by SkillAiNest

If you are doing manually, the deployment of a web app can be repeated. Whenever you put the code on your reservoir, the Gut Hub Action Permanently deploy your app to firebase hosting and automate it.

This guide operates by the establishment of a firebase hosting, the formation of the actions of the gut hub, and the management of the deployment. Finally, you will have a reliable CI/CD pipeline for your fluttering web project.

Table of contents:

  1. Provisions

  2. Step 1: Set up a firebase hosting

  3. Step 2: Create a firebase hosting

  4. Step 3: Add a firebase formation in the flurry

  5. Step 4: Create the actions of the Gut Hub

  6. Step 5: Set up a firebase token

  7. Step 6: Verification and Monitor deployment

  8. Advanced compositions

  9. Tracing defects

Provisions

Before diving, make sure you have these ready:

1.: You can install the sprouts FlutteringThen confirm the installation:

flutter --version

2. Firebase CLI installed: The Fire Base CLI allows you to discuss with the firebase hosting. Install through the NPM like this:

npm install -g firebase-tools

Check with installation:

firebase --version

3. A gut hub repository: Your flurry plan should be pushed towards the gut hub.

4. Firebase project formed: Barley Firebase consoleMake a project, and enable firebase hosting.

Step 1: Set up a firebase hosting

Start the firebase in your project

Open your terminal and go to your project:

cd path/to/your/flutter/project

Start the firebase hosting:

firebase init

During the setup, you will need to provide some information:

  1. Hosting: Select firebase hosting.

  2. Public Directory: Enter build/web (This is the place where the web -emitting webs make it).

  3. Single page app: Select Yes (Write all routes again /index.html,

  4. Automatic construction: You can leave because we will manually form gut hub actions.

Step 2: Create a firebase hosting

A file called firebase.json Will be created. Make sure it seems:

{
  "hosting": {
    "public": "build/web",
    "ignore": (
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    )
  }
}
  1. hosting.public The firebase tells where your bullet app is to find (build/web,

  2. ignore Files should not upload the firebase (hidden files, configured files, node_modules,

You can also see A .firebaserc File for Project Eliasing:

{
  "projects": {
    "default": "your-project-id"
  }
}

It connects your local project to your firebase project ID.

Step 3: Add a firebase formation in the flurry

When you connect the firebase with a flurry (through flutterfire CLI), it produces a file like firebase_options.dart.

In you main.dartStart the Fire Base:

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(MyApp());
}
  1. WidgetsFlutterBinding.ensureInitialized() This ensures that the flock engine is already ready before the start of the firebase.

  2. Firebase.initializeApp() Using auto -made options connect your app to the firebase.

Step 4: Create the actions of the Gut Hub

Now we will create a workflow that automatically manufactures and deploys your fluttering web app.

Create a file in your repo: .github/workflows/firebase-hosting.yml

name: Deploy to Firebase Hosting

on:
  push:
    branches:
      - main  
  pull_request:
    branches:
      - main

jobs:
  build_and_deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout Repository
      uses: actions/checkout@v2

    - name: Set up Flutter
      uses: subosito/flutter-action@v3
      with:
        flutter-version: '3.24.1'

    - name: Install Dependencies
      run: flutter pub get

    - name: Build Flutter Web
      run: flutter build web --release

    - name: Set up Node.js
      uses: actions/setup-node@v3
      with:
        node-version: '18'

    - name: Install Firebase CLI
      run: npm install -g firebase-tools

    - name: Deploy to Firebase Hosting
      run: firebase deploy --only hosting --project 
      env:
        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

What is happening in this code is here:

  1. Check Out Repository: Pulls your code into a runner.

  2. Fluttering: Instals a specific version.

  3. Install dependent: Moves flutter pub get.

  4. Create a web fluttering: Create the release version of your web app.

  5. Node. Set JS: Firebase is required for CLI.

  6. Install Firebase CLI: Firebase deployment device installs.

  7. Deploy in firebase hosting: Deploy built -in files to the fire base.

Step 5: Set up a firebase token

Gut hub needs a token to verify with the firebase.

Drive it locally:

firebase login:ci

Then copy the token shown.

Next, go to yourself Gut hub repository → Settings → Secret and variable → Actions.

Create a new secret whose name is: FIREBASE_TOKEN And paste into the token you copied. It protects your credentials.

Step 6: Verification and Monitor deployment

Thus commit a workflow file:

git add .github/workflows/firebase-hosting.yml
git commit -m "Setup GitHub Actions for Firebase Hosting"
git push origin main

Go to your gut hub repo, select the action tab, and then watch the workflow run. You will see an interface that looks like these images:

The work flows in the work

The work flow was completed

Once it succeeds, go to it:

Advanced compositions

Custom Blood

If you need a specific presentants (eg, HTML instead of canvaskat):

run: flutter build web --release --web-renderer html

Multiple environments (staging and production)

run: firebase deploy --only hosting --project ${{ secrets.FIREBASE_PROJECT }}

Specify FIREBASE_PROJECT As a secret to each environment.

Cache depends (high -speed Bloods)

- name: Cache Flutter Dependencies
  uses: actions/cache@v3
  with:
    path: ~/.pub-cache
    key: ${{ runner.os }}-pub-cache-${{ github.sha }}
    restore-keys: |
      ${{ runner.os }}-pub-cache-

Tracing defects

You may face some common problems. There are some quick fixes to help you deal with:

SkipFix
There is no active projectDrive firebase use --add Check locally and .firebaserc.
node.js version matchingBe sure node-version: '18' In the workflow
Firebase CLI errorsRe -install with npm install -g firebase-tools.
Outdated warnings in the index HTMLUpdate the latest fluttering web template.

Wrap

By connecting a firebase hosting with gut hub action, now you have a CI/CD Pipeline For your fluttering web app.

Every push main Keep your app live with zero manual effort.

To make a deep diver, check:

  1. Flossy web documents

  2. Firebase Hosting Documents

  3. Gut Hub Action Documents

You may also like

Leave a Comment

At Skillainest, we believe the future belongs to those who embrace AI, upgrade their skills, and stay ahead of the curve.

Get latest news

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

@2025 Skillainest.Designed and Developed by Pro