CI CD Integration Flutter + Github Full Explanation
CI/CD in Flutter refers to Continuous Integration and Continuous Delivery, which streamline the development process by automating code testing and deployment. This approach enhances collaboration, reduces integration issues, and allows for quicker iterations, ultimately improving the quality and efficiency of your app development.
What is CI/CD in Flutter?
Benefits of CI/CD in Flutter Development
HOW to IMPLEMENT CI CD IN FLUTTER AND GITHUB REPOSITORY
Setup for windows
· setup your project on the github
· Create .yml files
· Setup profile token & repository secreate key
· Avaoid on the cicd and major focus
SETUP Your project on the Github
In this case you must have to deploy your flutter project as it on the github . You follow the step of flutter project host on the github reference easily available you have got. For CI CD you have to work on the GITHUB Action tab but you don’t need to setup because by default it enble on your project, incase your project is private or someone share you then you must talk to him and enable the tab.
CREATE .YML File
This step is the Major step where you have create file to help your github CICD pipeline
.github > workflows > main.yml in your project directory (main is optional you have change according your choice)
Inside main.yml
on:
pull_request:
branches:
- main
push:
branches:
- main
name: "Build & Release"
jobs:
build:
name: Build & Release
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
architecture: x64
- run: flutter build apk --release
# --split-per-abi
# - run: |
# flutter build ios --no-codesign
# cd build/ios/iphoneos
# mkdir Payload
# cd Payload
# ln -s ../Runner.app
# cd ..
# zip -r app.ipa Payload
- name: Push to Releases
uses: ncipollo/release-action@v1
with:
artifacts: "build/app/outputs/apk/release/*.apk"
tag: v1.0.${{ github.run_number }}
token: ${{ secrets.TOKENN }}
On the top of the file is very sensitive (space / name / alignment/ any minimal change provide error ) and it setup for debug application and windows setup system.
For macos change runs-on: macos-latest and artifacts: "build/app/outputs/apk/release/*,build/ios/iphoneos/app.ipa"
And token: ${{ secrets.TOKEN }} inside TOKEN is exact name of the repository secreate key (describe on the bellow)
We have to comment ios create build app you have to uncomment for the IOS build app
In the java version make sure use as your install java version which required accordingle to flutter project which used.
Summary of the Workflow
Key Points
Prepare for the Play Store release
in this you have to create your jks file and other setup accordingle to flutter release rule. If you use there CICD pipe you must follow the step after setup your release and securely create a release APK/APPbundle on the terminal by type flutter build appbundle.
[Convert]::ToBase64String([System.IO.File]::ReadAllBytes("upload-key.jks")) | Out-File -FilePath "upload-key-base64.txt" -Encoding ASCII
on:
pull_request:
branches:
- main
push:
branches:
- main
name: "Build & Release"
jobs:
Recommended by LinkedIn
build:
name: Build & Release
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
architecture: x64
- name: Get Flutter dependencies
run: flutter pub get
- name: Decode Keystore
env:
ENCODED_KEYSTORE: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
run: |
echo "$ENCODED_KEYSTORE" | base64 --decode --ignore-garbage > android/app/upload-keystore.jks
# You might need to adjust the path if your JKS file is not directly in android/app
- run: flutter build apk --release --split-per-abi
env:
MYAPP_UPLOAD_STORE_FILE: android/app/upload-keystore.jks
MYAPP_UPLOAD_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
MYAPP_UPLOAD_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
MYAPP_UPLOAD_STORE_PASSWORD: ${{ secrets.ANDROID_STORE_PASSWORD }}
# - run: |
# flutter build ios --no-codesign
# cd build/ios/iphoneos
# mkdir Payload
# cd Payload
# ln -s ../Runner.app
# cd ..
# zip -r app.ipa Payload
# - name: Push to Releases
# uses: ncipollo/release-action@v1
# with:
# artifacts: "build/app/outputs/apk/release/*,build/ios/iphoneos/app.ipa"
# tag: v1.0.${{ github.run_number }}
# token: ${{ secrets.ODIACALENDAR }}
- name: Upload APK artifact
uses: actions/upload-artifact@v4
with:
name: app-release-apk
path: build/app/outputs/flutter-apk/*.apk
# push to master, main, develop
# pull request on main master
In this code I have to comment IOS build if you need then you oncomment and notice some of the point is
· env MYAPP_UPLOAD_STORE_FILE: android/app/upload-keystore. , echo "$ENCODED_KEYSTORE" | base64 --decode --ignore-garbage > android/app/upload-keystore.jks here (android/app/upload-keystore.jks file location as it your specific location)
· MYAPP_UPLOAD_KEY_ALIAS same name as it the build.gradle setup
signingConfigs {
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}else{
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
}
Setup profile token & repository secreate key
In this personal acess token you have to to the profile icon > setting > developer setting > personal acess Token > Token Clasic >Generate new token > generate Token Clasic
After going to this you have to give your token name and choose repo option and other don’t need to check then create token.
Now creating for the Repository secreate Go to project Repository > setting > secreate and variables > choose action > mnew Repository Secreate Button
In this give your name of the Repository secreate and the value give the personal accesses token
When you create Base64 Repository key you provide the value of base64 test and accordingle KeyAllias for key.properties keyallias respectively
Avaoid on the cicd and major focus
1. Avoid use personal acess token with or without comment it create github push error
2. For Macos push for CICD follow the complete step as of the Macos we discoss briefly on the used area
3. .yml file is very sensitive make changes very carefully
4. Make sure used of the token inside .yml file is exact match to the repository_secreate