What is CI/CD?
The concept of CI (Continuous Integration) or CD (Continuous Delivery) is probably no longer strange to the devs. Literally, it is the process of integrating and using the software’s continuous working and automation tools into the product’s development lifecycle. In a rustic way, this is the process of automatically building, testing, deploying the web (for FE/BE) or building the app, deploying the app to the app market (for Mobile App) with just one button (or trigger on it). Git’s on push action). Nowadays, CI CD becomes a natural thing to have in the software development process.
Purpose and limitations
As mentioned above, CI/CD is applied a lot to the software development automation process. Or we can build our own installation for Android / iOS from open source projects without knowledge of Mobile programming, for example. This is quite good for non-tech brothers because there are many cool open-source mobile projects (Youtube Vanced is an example), after building an apk or ipa file (using AltStore to install on macOS, which If everyone is interested, I will post another post later) install it directly on the device.
The biggest drawback is that using a lot will cost money. For each CI/CD service provider, the fee will be different. If you use CodeMagic, you will get 150 hours per month for free, which is pretty cool. Here is a small tip is to use 150 hours, then create another account to use it for free
The second limitation is that it is quite difficult to configure with too many complex projects (multiple environments, …)
Introduction to CodeMagic
As the title of the article, we will only go into CI/CD on Mobile App (or because I don’t know how to do FE/BE). Currently, there are many providers that support this, such as Github Action, Bitrise, Gilab CLI, … (if people are interested, I will post another post). However, in this article we will use CodeMagic. Surely, many Flutter coders will probably find this name familiar because this is a place to share a lot of detailed blogs/guides about Mobile App, you can refer to it here.
Register and configure Source Code
To use it, for sure, we must register an account here . Please allow me to skip this step
After logging in, we proceed to add the application from the Git repo (Github, Gitlab, Bitbucket…). Here I will demo add Github repo. Select
Add application , then select Github and select
Github integration to grant CodeMagic read github repo permission
Next comes the most important part of the process. Here we will have 2 ways to configure
Configuration using Work Flow Editor
Configuration using .yaml . file
With some projects with more complex configuration, we need to configure it with the yaml file. Similar to the configuration above, using the .yaml file will also have the same items but at a more advantage level.
The following is a workflow with a sample .yaml file to run the build to the Android installation file.
name: Android Workflow
- google_credentials # <-- (Includes GCLOUD_KEY_FILE, GOOGLE_CREDENTIALS)
FIREBASE_PROJECT: "YOUR_FIREBASE_PROJECT_NAME" # <-- Put your Firebase Project Name here
- name: Set up debug.keystore
rm -f ~/.android/debug.keystore
keytool -genkeypair -alias androiddebugkey -keypass android -keystore ~/.android/debug.keystore -storepass android -dname 'CN=Android Debug,O=Android,C=US' -keyalg 'RSA' -keysize 2048 -validity 10000
- name: Set up local.properties
echo "flutter.sdk=$HOME/programs/flutter" > "$CM_BUILD_DIR/android/local.properties"
- name: Get Flutter packages
flutter packages pub get
- name: Build APK with Flutter
flutter build apk --debug
- name: Create debug and test APK
./gradlew app:assembleDebug -Ptarget="$CM_BUILD_DIR/integration_test/app_test.dart"
success: true # To not receive a notification when a build succeeds
failure: false # To not receive a notification when a build fails
As you can see, it is quite cumbersome to configure for those who do not have programming knowledge, so I do not recommend this way very much.
After the build is successful, a notification will be sent. The installation file will be included in the email or build history, you just need to download the file and install it directly (for Android) or through a little other trick (for iOS).
Above, I have just basic guide to create a workflow to build files automatically, in the next article I will guide you on sign keystore, auto deploy to CHPlay every time you build. Click upvote if you find it interesting to support me