I have 2 secrets in a JSON file which i do not want to push to my GitHub Repo but i need it to build my apk using GitHub actions.
FileName : app_config.json
FilePath from Root : config / app_config.json
{
"secret1":"abc",
"secret2" : "def",
}
So this is what i came up with :
- Step 1 : Add it to .gitignore
- Step 2 : Add the base 64 version of the JSON file to GitHub secrets
- Step 3 : Add the folder as well as the file [config/app_config.json] at runtime in GitHub actions.
I am performing this in 2 steps:
- Step 1 : This is a Github action which converts base 64 to a file (APP_CONFIG is the GitHub secret with base 64 version of the json file).
- uses: actions/checkout@v1
- name: base64-to-file
id: write_file
uses: timheuer/base64-to-file@v1.0.3
with:
# Name of the file when written to temp location
fileName: 'app_config.json'
# The base64 encoded string
encodedString: ${{ secrets.APP_CONFIG }}
Step 2 : This is the code i am using to
(a) Create a folder named "config"
(b) Move the file from that location (where it was decoded) to the "config" folder
- name: Inject env variables
run: |
mkdir -p ${{ github.workspace }}/config
mv ${{ steps.write_file.outputs.filePath }} ${{ github.workspace }}/config/
When i build this workflow , I do not get any error in this part, but later on while i run "Flutter Test" where the tests of the app are run, This folder is not recognized.
Error:
Error: unable to find directory entry in pubspec.yaml: /home/runner/work/<my_repo_name>/<my_repo_name>/config/
But didn't i just create the Config Folder ? why isn't it recognizing it?
Complete dart.yml File
name: App PlayStore Release
on:
push:
branches: [ master ]
jobs:
version:
name: Create version number
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: base64-to-file
id: write_file
uses: timheuer/base64-to-file@v1.0.3
with:
# Name of the file when written to temp location
fileName: 'app_config.json'
# The base64 encoded string
encodedString: ${{ secrets.APP_CONFIG }}
- name: Inject env variables
run: |
mkdir -p ${{ github.workspace }}/config
mv ${{ steps.write_file.outputs.filePath }} ${{ github.workspace }}/config/
- name: Fetch all history for all tags and branches
run: |
git config remote.origin.url https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }}
git fetch --prune --depth=10000
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.3
with:
versionSpec: '5.2.x'
- name: Use GitVersion
id: gitversion
uses: gittools/actions/gitversion/execute@v0.9.3
- name: Create version.txt with nuGetVersion
run: echo ${{ steps.gitversion.outputs.nuGetVersion }} > version.txt
- name: Upload version.txt
uses: actions/upload-artifact@v2
with:
name: gitversion
path: version.txt
build:
name: Build APK and Create release
needs: [ version ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Get version.txt
uses: actions/download-artifact@v2
with:
name: gitversion
- name: Create new file without newline char from version.txt
run: tr -d '\n' < version.txt > version1.txt
- name: Read version
id: version
uses: juliangruber/read-file-action@v1
with:
path: version1.txt
- name: Update version in YAML
run: sed -i 's/99.99.99+99/${{ steps.version.outputs.content }}+${{ github.run_number }}/g' pubspec.yaml
- name: Update KeyStore password in gradle properties
run: sed -i 's/#{KEYSTORE_PASS}#/${{ secrets.KEYSTORE_PASS }}/g' android/key.properties
- name: Update KeyStore key password in gradle properties
run: sed -i 's/#{KEYSTORE_KEY_PASS}#/${{ secrets.KEYSTORE_KEY_PASS }}/g' android/key.properties
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '1.17.0'
- run: flutter pub get
- run: flutter test
- run: flutter build apk --release --split-per-abi
- run: flutter build appbundle
- name: Create a Release in GitHub
uses: ncipollo/release-action@v1
with:
artifacts: "build/app/outputs/apk/release/*.apk,build/app/outputs/bundle/release/app-release.aab"
token: ${{ secrets.GH_TOKEN }}
tag: ${{ steps.version.outputs.content }}
commit: ${{ github.sha }}
- name: Upload app bundle
uses: actions/upload-artifact@v2
with:
name: appbundle
path: build/app/outputs/bundle/release/app-release.aab
release:
name: Release app to internal track
needs: [ build ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Get appbundle from artifacts
uses: actions/download-artifact@v2
with:
name: appbundle
- name: Release app to internal track
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.PLAYSTORE_ACCOUNT_KEY }}
packageName: com.notes.ounotes
releaseFile: app-release.aab
track: internal
whatsNewDirectory: distribution/whatsnew
Complete Pubspec.yaml file
name: FSOUNotes
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
# //publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 99.99.99+99
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
shared_preferences: ^0.5.7+3
google_sign_in: ^4.5.1
fluttertoast: ^4.0.1
flutter_mailer: ^0.5.1
open_appstore: ^1.0.2
share: ^0.6.4+3
intl: ^0.16.1
font_awesome_flutter: ^8.8.1
flutter_full_pdf_viewer: ^1.0.6
path_provider: ^1.6.11
cuid: ^0.1.2
shimmer: ^1.1.1
file_picker: ^1.12.0
url_launcher: ^5.4.11
expansion_tile_card: ^1.0.3
flutter_typeahead: ^1.8.1
mime: ^0.9.6+3
awesome_dialog: ^1.1.3
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
stacked: ^1.6.0
stacked_hooks: 0.1.1+3
stacked_services: ^0.4.4+1
logger: ^0.6.0
# http request
http: ^0.12.0+2
# async package to add additional Cancellable operations
async: ^2.0.8
firebase_auth: ^0.16.1
cloud_firestore: ^0.13.7
firebase_storage: ^3.1.6
image_picker: ^0.6.7+2
cached_network_image: ^2.2.0+1
firebase_messaging: ^6.0.16
flutter_auth_buttons: ^0.6.0
auto_route: ^0.5.0
modal_progress_hud: ^0.1.3
permission_handler: ^5.0.1+1
get_it:
injectable:
flutter_hooks:
observable_ish:
dev_dependencies:
flutter_launcher_icons: "^0.7.3"
flutter_test:
sdk: flutter
build_runner:
auto_route_generator:
injectable_generator:
mockito:
flutter_icons:
image_path: "assets/images/apnaicon.png"
android: true
ios: true
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/pdf.png
- assets/images/pdf1.png
- assets/images/link.png
- assets/images/Applogo.jpg
- assets/images/apnaicon.png
- assets/images/1.png
- assets/images/2.png
- assets/images/3.png
- assets/images/4.png
- assets/images/5.png
- assets/images/6.png
- assets/images/7.png
- assets/images/github-logo.png
- assets/images/OU_Logo.jpg
- config/
fonts:
- family: OpenSans
fonts:
- asset: assets/fonts/OpenSans-Regular.ttf
- asset: assets/fonts/OpenSans-Bold.ttf
weight: 700
- family: Quicksand
fonts:
- asset: assets/fonts/Quicksand-Regular.ttf
- asset: assets/fonts/Quicksand-Bold.ttf
weight: 700
- family: Custom
fonts:
- asset: assets/fonts/Custom.ttf
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages