Skip to content

Instantly share code, notes, and snippets.

@apgapg
Last active October 7, 2023 16:23
Show Gist options
  • Save apgapg/76e5c251daa7ce53291164479f43e61c to your computer and use it in GitHub Desktop.
Save apgapg/76e5c251daa7ce53291164479f43e61c to your computer and use it in GitHub Desktop.
Github Workflow for Building, Releasing Flutter web app to Github Pages and Firebase Hosting
# This is a basic workflow to help you get started with Actions
name: Build, Release app to Github Pages and Firebase Hosting
# name: Test, Build and Release apk
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- master
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
channel: 'dev'
- name: 'Run flutter pub get'
run: flutter pub get
# - name: 'Run Test(s)'
# run: flutter test
- name: Enable flutter web
run: flutter config --enable-web
- name: 'Build Web App'
run: flutter build web
- name: deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.TOKEN }}
publish_dir: ./build/web
- name: Deploy to Firebase Hosting
uses: w9jds/firebase-action@master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
@apgapg
Copy link
Author

apgapg commented Jun 17, 2020

Remember for Firebase hosting you need to run
firebase login
firebase init

and change firebase.json to following

{
  "hosting": {
    "public": "build/web",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

Also need to add secrets in settings of repo namely TOKEN, FIREBASE_TOKEN

For TOKEN

Your git profile>settings>Developer settings> Personal Access Token> Generate new token> select only 'repo' scope and give a good name and thats it

For FIREBASE TOKEN

Run following in your terminal
firebase login:ci

After getting above tokens, go to repository>settings and add these as secrets with respective names

@UpmindAI
Copy link

UpmindAI commented Oct 26, 2022

I keep getting this error:
Deploy


Deploy
firebase.json file not found. If your firebase.json file is not in the root of your repo, edit the entryPoint option of this GitHub action.

This is my full code:


name: Build and deploy to Firebase Hosting

on:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: subosito/flutter-action@v2
        with:
          channel: 'stable'
      - name: 'Run flutter pub get'
        run: flutter pub get
      - name: 'Run Build'
        run: flutter packages pub run build_runner build --delete-conflicting-outputs
      #    - name: 'Run Test(s)'
      #      run: flutter test
      - name: Enable flutter web
        run: flutter config --enable-web
      - name: 'Build Web App'
        run: flutter build web
      - name: Archive Production Artifact
        uses: actions/upload-artifact@master
        with:
         name: web-build
         path: build/web
  deploy:
    name: Deploy
    needs: build
    runs-on: ubuntu-latest
    steps:      
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PAPERWIZ1 }}'
          channelId: live
          projectId: paperwiz1

I have created the firebase.json file and added it into the root of my main repo.

@apgapg
Copy link
Author

apgapg commented Oct 26, 2022

did you include this file in git vcs? You sure its not in gitignore or untracked?

@UpmindAI
Copy link

Yes, I created the file trough VSC using firebase init hosting:github .
I uploaded it manually into the main branche and it is not in gitignore and it is being tracked.
These are the contents of my firebase.json , same as yours.

{
  "hosting": {
    "public": "build/web",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

@UpmindAI
Copy link

I was able to fix the issue by adding this deployment script instead of the other one:

  deploy:
    name: Deploy
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@master
      - name: Download Artifact
        uses: actions/download-artifact@master
        with:
          name: web-build
          path: build/web
      - name: Deploy to Firebase
        uses: w9jds/firebase-action@master
        with:
          args: deploy --only hosting
        env:
          GCP_SA_KEY: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_PAPERWIZ1 }}

I actually believe this made the difference:

        uses: actions/download-artifact@master
        with:
          name: web-build
          path: build/web

It was uploading the artifacts but not downloading them for deployment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment