I have a flutter web app and for accessing the database I have hardcoded an APIKey in a secrets.dart
file, And this works perfectly fine. I have added this file to .gitignore
in order to prevent it from pushing it to version control. But when it comes to deploying the app using GitHub actions The script fails because it doesn't detect the secrets file.
I did look at the docs on Encrypted secrets from Github which basically allows storing the secrets.But it seems like those secrets are only accessible in the yml file.
I would like to know how can I use this secret in my app so that my script runs successfully and deploys the app. Here is my folder structure
lib/
services/
database.dart /// this file uses the APIkey from secrets.dart
secrets.dart /// contains the APIkey
One way to solve this issue I can think of is to use a .env
file but I am not much familiar with How to add the secret keys in .env file through the CI script. I believe that would also solve my problem.
Heres my CI script
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools
name: Deploy to Firebase Hosting on merge
"on":
push:
branches:
- master
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: "12.x"
- uses: subosito/flutter-action@v1
with:
channel: "master"
- run: flutter pub get
- run: flutter pub run build_runner build --delete-conflicting-outputs
- run: flutter build web --release
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_VOCABHUB_34C7F }}"
channelId: live
projectId: vocabhub-34c7f
env:
FIREBASE_CLI_PREVIEWS: hostingchannels