Closed callmephil closed 6 days ago
Here's how I usually handle this:
add all your secrets and/or variables to Github Secrets
inside your env/
directory create an .env.example
file containing just the keys without any values, i.e.
SOME_API_KEY=
inside a Github Action, copy these secrets / variables to your.env
files, i.e.
- name: Create environment files
env:
SOME_API_KEY: ${{ secrets.SOME_API_KEY }}
working-directory: env
run: |
set -e
cp .env.example .env
sed -i "s#SOME_API_KEY=.*#SOME_API_KEY=$SOME_API_KEY#" .env
The example above uses sed to find & replace values in your .env
file as it is the most readily available *nix tool that does the job.
in your Github actions run the code generation to generate env.g.dart
(or any other *.g.dart
file) using
- name: Run the build system for Dart code generation and modular compilation
run: |
flutter pub run build_runner clean
flutter pub run build_runner build --delete-conflicting-outputs
once all the files have been generated THEN build your app
upload your app to the app stores
delete all/any generated files / token files / builds etc in order not to expose any secrets using, i.e.
- name: Clean up
if: ${{ always() }}
run: |
rm -rf env/.env*
if command -v flutter &>/dev/null; then
flutter pub run build_runner clean
flutter clean
fi
rm -rf build
rm -rf debug_info
I hope this helps.
I'm trying to use envied with CI/CD (Bitbucket Pipeline & Codemagic) and I'm unsure how to handle the file generation process.
It says in the doc that:
So if I can't publish the env.g.dart it mean that I need to generate it using a pre-build? This will also be true for the .env file right? Is it the recommended approach?