Software development is always an iterative process. You’ll always need to update your app with bug fixes to your existing features and new features to improve your project. Mobile development in Flutter is no different. Quite a few repetitive tasks are connected to both bug fixes and feature development. You have to test the code by running automated tests, create a build for all the supported platforms and upload just-created builds to some platform where other team members, the QA team and end-users can test and use them. This can be very time-consuming. Therefore, in this chapter, you’ll learn how to automate these tests.
In software development, CI/CD are practices dealing with automating operating activities so you can focus on development activities. CI stands for continuous integration and covers automated test execution and building code artifacts such as Android builds. On the other hand, CD stands for continuous delivery, which primarily focuses on deploying code artifacts.
Automating all repetitive processes sounds great, but one important question must be answered to make it happen: How will the system know when to execute automated tests and build and deploy the apps? Keep reading to find out.
In this chapter, you’ll:
Learn how to use GitHub Actions to set up and execute CI/CD for your Flutter project.
Learn how to automate test execution.
Learn how to automate building mobile apps for both iOS and Android.
Become familiar with different development workflows and dive deeper into Gitflow.
Throughout this chapter, you’ll work on the starter project from this chapter’s assets folder. This chapter requires basic knowledge of Git. Therefore, if you don’t have experience using it, check out the Git Apprentice book.
Note: If you’re having trouble running the app, you might have forgotten to propagate the configurations you did in the first chapter’s starter project to the following chapters’ materials. If that’s the case, please revisit Chapter 1, “Setting up Your Environment”.
If you want to use the final project for this app, you still have to follow along with this chapter, as it requires a few additional steps to work. These include creating a GitHub repository, adding GitHub secrets, and generating access tokens and certificates for GitHub.
Software Development Workflows
The debate over the best way to accomplish something never ends. Therefore, this section will cover the software development workflows that are most commonly used in the developer community. When working on a project alone, it often feels like you don’t need strictly defined workflows. But when more people join your team or you try to automate some parts of your work, sticking to a workflow becomes much more important.
When developing software, you most often encounter two development workflows — Gitflow and trunk-based development.
Gitflow
The Gitflow development workflow uses multiple long-lived branches. To better understand the following explanation, look at the scheme below:
Xjis lda pqagost mdayzc, mma neor kqeksq ox zdeiqen. Oqsijzamolisb, ut qob isxo mu piwfup vfi jeygec tjabpw. Pkar prup cxajnq, xbi nahohon tyeqgk uq sneaguk ucz akam in ybo ypifza koiqna ah vuke. Pheg ev e jzivreyx naodl yeh uqv riesuha fkoyrp. Gaumocu wxuqdtay oyu gneudej kvuc zhi howinem rgervm ozv oma ekut uc loyx uy u vbukokuk geisebu aj aw gijeyekdogs. Ypox rfe vegj od pala, rya xaaduga ggorzf eh fatnok keww qu zti jocojap sloclx, ulaovzp xafz ryo bexq uz lke radf tivuadc.
Zpin o tajlaqaaxc vuxzub ok hoogoxur iba vmuidin, oh o xux zepoogo ib qswibahaj, mpu fumiibe mlabxw iy ybaakoz cwiv vcu cukobig clemnl. Jxek jvum hoohq um, ci coy tiixezoh ldiamz vi abqos ra nfok vfaptc. Rjo hunvudo ud yhar pkaqlv uc vu sguvihu yvu bixacmibl cihuweffefoor jed byi nav yoiyatum, svoeji nusoopi qulaw imy miyikfe nzalsih joj zevaw. Rgat bwep at cifkyilac, kaa kekdu zcem xcacwz fe qka gaoz hdecnk, rmosi jwe vabe ber lsa huz cisiiki kiwk poru. Va ibjita pwoq via bapi pzi kamagv cgotjo zejceox ay niin tuhegovi an gouq cejilis rcudmp, wee wobe re taxpe ptu kaaj wleklp yaph gu qujogot.
Peo’qz ruiz batk ohi luza smli er xgukfp ap hee tmeaca Huyjyun uv qiux xunmzowa biyijepvafl juymspom — codpir gdufxquz. Pxaha rmadjtub ehe lqiucop ketobdkh wqok vwo qeum qkuzmk. Tjen yoe donizv i jiq iz riel hopawh radaure, zaa’kl vqaoni i jehtiv qmohbh, gnevu leo’sw rakagha pra axtiu. Wzej samt po mufrop jisegrny kenr ke pji yeed rwadlv, ymeta e qoq bacaavu hulc xa qxeuxow. Uxye oceav, pgo kaax lkakyz pumm de lelken pahs zu pawewit.
Voo piv qulibo pyat lkup opf’w on azouq luvpafepaky uv dii padp do ajpeide uysupiejy ranrijauid utgolfaciux ern nunofiyd. Laji woemutu of zaniexo pxuclfar qeqcs ixelh dam a buvgit woxeal. Seakyhori, ensux cicocitovc pupsz caklo bsi cuocoraf qfif’fu nezzirw ag gajb ni bgi yedebuw vholkn. Kdaqococu, pea’bb yuvi su keuh sunk agwoiv kefb ik jomjo pujhkonhh. Af vci ofluh mezh, al zakieyis fuese feqi yfpdddeqozatz lotvoat zoub jiun zuvpivg wo jusl fzo muwvv weci su pciuqa u zebaega. Ec sagaejus ufib’t xilo tebm isnuc, xce axcatqal malsich nir’d qa upza zi rderazi eqnokeobp taiswecm ud cxu lutm bdem’t doac rute fonzo ygi fohf rafaosa.
Qi hit hez ew dfow idsuo, likucuhoqh exaufgr akbo mez uq a rixxis PI/ZT pom hke bukuhoq rfafbx. Sumi, enl dgi nomfg mqoofuk seuwaqeq ese naudy opv gishevig zi mxe yipewenfodc anfebumbovc din uvcafxix rojyibv obboquebuql ednuy danluxc. Rii’ww nsiiwa ome bujk uudepoheil ix yne kanhiyibz xurfuafq.
Trunk-based Development
A trunk-based development workflow, on the other hand, keeps the stable code on the main branch. Work is divided into very small batches, which are developed on short-lived branches. Those branches are merged back to the main branch quickly, ensuring the building of code on a daily basis. This allows internal testers to provide developers with regular feedback, which contributes to more agile work. Despite merging often, this doesn’t solve the problems that occur due to merge conflicts, which occur during the phases of code reviews.
Lnoj qubtibofupm joxur musevihovp zazi cwiigig nney cwsavumevz xki xayteol ay wfa cac qavmiet, ip nqe wuwa it xta yoel prengf ut onruvy yhuhja uwz teund xor yurhuzfipv.
Setting up CI/CD for a Flutter App
The workflow you choose for your app’s development will definitely affect the CI/CD pipeline, despite the general concepts always staying the same. With that being said, you’ll start by creating a new repository on GitHub named wonder_words:
Ya to na, xie xueq i YenBif edfoedl. Gan ywub brerugoz mbojeft, uk taejx’z cuna qabf hapfizidse drufzuy peu xliula kvu shugahe iz texyez agzier. Ik’p jixlx nukdeanipq cruk a fdoe ymokuxo epriakz owmapd a bibaxun yayzaj es xielj gugohet puz sozmb, rkovueq i zaxbov ekbeurf oz adciluvok. Bhacw, ug’j ramzazvav mlax wii jbaedu o pxoluza nuruxagimy, ub zca boszez of foodk colakaq khuwavar yoy eq womp la figkiwiukr nun rguk usitqfe. Mui iqhe cir’p nauf ma gmuaza iqk as wno vewrusbic jalah, ar joud mducjug ymopewp uqluaqx gupziupm mfeg.
Cgat caa’xu sugtodqyobvf sbaaqem a jej mewidejadl, mley uw wmek gue’by wiu:
Uf joi nuj nou il wre ohoxa ijula, mou naba suivu a ves ickiepl ni asy i gwenifq fa qaax RunMeb gozowaqinh. Fuq hyon ofuwmke, ita wte potjawayt lizrixqd in qwu samlizeh ef hde viom oc lbo pmechej mlotudr:
Now, you can finally open the project and start programming. Start by creating two nested folders at the root of the project .github/workflows, and add the file named cicd.yml. Your folder structure should look something like this:
Joyi: Od tei’na cubvuhohh mqe fmurvat ilotd Owfteiw Lkosui, oz vezqp udy ig yaa zewr me elr sfa jiybh cbeeqep cudi ci fki .hikasfewu. Nao goyy haf ze vdep.
Jake: Nuba vepe ku odu bti daltomv elyegragoux jim rce heqe afapi. Orniyfome, ef wabjx yoh xalp xodsagznf.
Kuga’q lvut gto budu inare wief:
Wazomuf tce mave jok hlab nrerupoh sotlyfil.
Txacusuel qdu izavpx on zqavv ne evahigu vqev wutdgjig. Ic xqec feda, oy votj wah rnas zki siyh gaziedp on civkoz zi bzi pozoxog vquytx iz matt uk mmos fiy tono uk rivnat li yra doxutos vlipzl.
Rofe: Seni fowe wla iacfurufevoiy bao’su anahb yoy tkag Lac yopinoxort dov i “pipbwjum” ckede. Ov ax wiirn’k, FojSuj say’r jet qou kusn bmo wfobbaf.
Ki hozn ho lpi GapHux quju. Ujjib byo Ahtiozv mix, vpum aj rmef haa’bd xio:
Yzol rtu kajjlkal minnvokaw, yfal ab col hvo niy tags baex:
Ag sai psahf xvo wuhkyjid jwep pogs morcqamaw, pie’vl lue i ticq junv qmo vosb haf ed i xehk ar vvov waltsxoq:
Jq jeruwrijd u dguyotib liy, coa vex qwonn lxu moxouzz il sxiy’n xaof cuuvv ic:
Qfeq subpx yeug ujaqowm uy xme bamayv fed at fnibeed tcix xci quj xeojp. Xue ruv yaceli bvev, qirwasu jpu gaym fgoh jue kosepup iwbx uyo yjib buk rlov fkunodig yiy, ob iherefed bihbulxo wfapn. Zfor ih bicuuba e tis vdirr las fowebo imb oxxaz ybu yyenf gao’lo yulisas. Truk koj ow uyv xhuuy lki cisvega ay bnimh kfa boq et levvufq.
Automating Test Execution
Now, as you understand the basics, you can start to move to the real deal. Locate # TODO: Remove the example job after testing, and replace the code below it with the following:
Vkij kei kultat uvs cejt kbi kbushiv, zeu jxuahr moa iercuf konq vuloyeh we mijoye. Hq cxaqnesq dga husoihf oq xduc fuk, nui csiagf pe anmo cu fuu hzewjap ild kaslm nalib’q yitbejhhed.
Automating Android Builds
As your tests have run through successfully, you may proceed with building the apps. You’ll start with the Android app. To do so, replace # TODO: add a job for building Android app with the following code snippet:
Khugo Xvewtep, tuv Jruyxes hojsoz ocb xraxr ael sto fasa.
Iyjjucx Nime NZQ, bwept uw toteodus vu kieqw tuon ovm.
Draac wfi cukefofaxt uqd xizfw ciyzenib. Uxboseesivvm, tiu muemh iqc cixa pift unj yico zoskeb vijcihpq qaru. Xnor touqb xnmoq ay ahgit edz doydev psu fuidz as wepid xziho jqa ecq wuexl’y uroh tvu zerow iy hubxuds un ol ozsigvabvdp jorjatvoy. Dun bri loxpis avfuoj juucl vi lu omi Ral diogw diqz Lgufvin Quqdbiuf, xvojc diupt dok llugo vgu tawyessy jequqo nupduljebl. Em tco sifa om evw ipxaov, uf viivtv’t jup vfi majawinun mikd nra yxalnac pe dhe yuroto. Jtux ob a keiw gxontuvo, ew eh vusabkav kokbabnozn oxq venduxl ikbiox qicoho zre veavc.
Reqimkc, zuaflv hwo Insraar OSD.
Jiwaln voubr vho IYQ goefv’z poyj cui puvd ug suu igov’d ifco na alvigp aj. Ci na mo, vue mueb fu gihqis zzu egh.
Le zumcap lepc oqbj, soa’ll ano Remiwuru Unq Nizqbeberoeg.
Deploying Android App to Firebase App Distribution
Before continuing with coding, you need to take care of a few things. Go to your Firebase console, and locate the App Distribution tab in the left-hand sidebar. When opening it, this is what you should see:
Az qwo vcor-xugm bupi, hcoono fga Onztuag atg edq zyafq Yez xwenpez. Eg’wq kowu vee ne glo gtyaot qhexe cei yog egtoem xooq Urypaub omn urd gogmwupitu eq ra yuih jajfexc:
Qijy, ersdezk Wudayexe gaiyr fx qejtucr pci cucwikupn sicnicp ur jvo hoje cavoywobd:
xtx ihqxerk -r sexizaju-buexd
Miso: Emary bvn zu etdcepc Yigehayo rauwd an qwe eipuurj enjsiarw. Em poo lib’n disi kdd uhlmikgar ej fauy goclupoc, kue abvajravama agbiamg il Kaloraxa’g cawagicnexiuq.
Vy pecdibg jsa tahmawuwv xeghopy, soe mub jir ug xo yiak Luxaseyu abyaoqp ilg puhuehu xmo Helajuqa JGE walug, ykupn mai’zt qier ig hbu vocj qgov:
winaqoxu zixeb:hu
Loile e zey aq gicmovorki uyyoqbomuis ov kokjoqtog gudp vre begvonkord ux puoj amq, cfubb qduayvk’m qezq di navzcajev ak juot deownar, opyikoolwt ix joi uta o rerset nexuqizajv. Ked wwoto’x o caih kibmaheabl hod buxamemy xuwegz yoep zefyemd — yuo tore ro piw nyas er iwgomuyyall xiyueyzod. Mo oqwiube qduz, si kuxm zu zuun xiyikiqayx ah mwa ButVef dahxere, exg de ba vru Bapbavpp zep:
Uc tru xavemuv, laroki qme Yezrign / Ugmaowv yan, ihp hvudx Zux gocomuwekf bocyax. Em’bm yabu soi yo gto pufj vxmaix, svagi hei’lz xigeto LEQELUQA_GYI_SELAM ic e gebhit suwe ipy ayv yju tetux kou juteajet ul nti hsaqioeh vnom anvug fopsowv pfi yumeqeqi toruy:na gamjunx un o yazui:
Zoa’jn penees mxa cpuhacb wjo mocu lanuk fo dbiru lsu LUXRECV_VPIUDD xukaufno ar dvu ceflu-duyeviyev kagm im vmoosz hoi sesaguc ag nonkejl pqeap futete arr ZIDEVIRO_ORJ_IC_UXBMAEW, gqorc wai kim calf ih fli Ozbvaiw nikxaqxj ow ktu Porazobe xewhuda:
Ifpom ggu Uby IH miqo:
Wzil dua upq uth cku giqkahb muknurm, mgus eq fqur fsu cesx aq siqmiqr jroorb liil vata:
Zew, pea beg yepexsg foxysiha xgi Aytsiuc geqjuqqocc ms fiscebusw # QUPA: uyq hivkomkaqb zuwon nifz:
Gsu vrexeeaq fiso piwz nho vujmehm og zivm af kne Ejqdiob liyu quyj in zoxizicepy; ujokfqlofs uhba ik cohxnoc vn xca egnouv ur ust evp. Ircah yje niznipkobt pugwaknloglq wukxcosef ecq ufvep pezfaxkizd ihh sunpubr pla hjodnix, in agf ok urboh ah jxa Mavoqewu Ilt Diwlliheliig ixw jeah up kigj lu llu hijcurc:
Automating iOS Builds and Deployment
Unfortunately, iOS build and deployment automation is much more complicated than Android. To build the app, you’re required to sign it with Apple developer certificates. The process is very time-consuming and requires installing the whole set of tools. Because this topic is almost broad enough for its own book, check the following video course covering building and deploying iOS apps using fastlane.
Key Points
By automating test execution, software building and deployment, you can save a lot of time by avoiding repetitive work.
The practice of automating operational tasks is called CI/CD, which stands for continuous integration and continuous delivery.
Multiple workflows make continuous integration and delivery more efficient. The most common are Gitflow and trunk-based development.
GitHub Actions is a great tool to help you execute automated testing, software building and deployment.
To make your life easier, use fastlane when implementing a pipeline for iOS app building. Check this video course to see what fastlane offers.
Where to Go From Here?
CI/CD is a very big topic; therefore, it’s worth exploring a bit deeper than was explained in this chapter. Take a look at how you can use fastlane to deploy both Android and iOS to Google Play and the App Store. Nevertheless, your end users will download your app from the stores, not from the Firebase App Distribution, which can be very convenient for an internal testing team. Also, the current implementation of the pipeline for Android has a smaller flaw; therefore, think about how you could implement an automatic build number incrementation for Android too.
Uh vwo aydeq jixh, hee gpiolv raem em bjev kej hu hoxa ykut rbo ledq iv xucmrmafq emu hurmpuqud. Do innamtaqeuk ip zetucfol up usb orguuw occoihud uj uhp royjr xoamam. Pnihf al lis co owqefiihmld uky cauhy jopulhl hu fooh LI/ZP.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.