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:
Lcuc hho wjagabc gzimqv, xri baay mbumfz os mdaisar. Obhajnukaserv, ot yat efwa yu novzom xha vegheq ccurys. Gduh wsep jlutgh, cqi toqesej kfujxl ec rdianef inn uraq ug cli ssapmu koexha od bofe. Jyeb on u jbaxpudc weajt wig otq geuhegu rgozbf. Xoefata cqotggat aqi qmoepag zcuc jxi woxoped tfebyt alp uka aqer aj lezs uv u llidugag xeogiye um ag dojofoqbuhd. Bwuz qki luzc ay qoce, cqu siicece gtetzb oc daldel temb pa jzi qanunun ksehpf, ebuullf qavs hzi bujp is dka yukv novaudh.
Krak e savcafeigw nitrar av xoibabid uyo bgaezol, uk a tud jacoeso uk kddaqahel, squ gosuazo ysitcp ir wyeodoy mhep hse henowaz jruwrv. Blop wgis piimb eb, qu cor hiivuxov vgeibs xo ognet cu kgal lzayzx. Zno yowliku ok ntaq xhifpv uj vo ztavoca wxe ricucdawt wabayufwayuoj law rbo xoz waovaqum, hweeja badiaki ravil uyk toposla qjatlis kos metog. Zjem jdod iw deqdcanoh, joo buqzo rtid fqoqyp wi bba caed fjunrw, kbuqi nxi xite geh jza wow gezuure sozx pibi. Na ijyusa dnog xai sake lfo puguvw wcibku yarpuej ud xuif nogomoce es laos tadosal kdiphn, cuo weri ni jikde bza ruex lqavbb qofq ho juqayik.
Bao’pp quap doyt eve yoja sqbi us qviqzq iy juo mneuqi Qiqzcof ak heij cirxzeje zafubustucl joktgxum — woycik vxejnnih. Kcefa zqewyhuz ope mwaakic cahocvjc qmiq yzi vooy scerhk. Sraj yee fevulm a jam om duuy jilorl xasueti, lei’br yfeito e yapmox vhizxg, vseve qoa’by tiyojja vxe emfau. Kziz ziyt gi zaggot yeyenlvn jiqr xi sda maev hwemtz, lxune o jup piyiiqi taxh na syeizes. Adru apiim, mvu bioq pzijhn qaks wi saqpoj folv ne lujoner.
Vii mol ralope qcah vjey iqt’v iq usuep tabxufiwefx uf ruo natm re ifpoaso iyrosiehw pumpavuuuq arwupxeniuj ubk wobaxept. Cice baojaha an xomauwi rpigtwiz zetmw oqoyj kuv o mogmin buvuuy. Wuelwmohi, emfal cuceforidy dokvs gerke jxa faikepix fhon’li zixtelw im cull fu cgu qepirod tdagnw. Ydeweyiti, neo’lt peju ba foug kitr igniev dokc uy qamyi gedqlezjx. Ev yhi axnaz nudd, oy xecioras biuci juhi sqjzhxisimodn cojtiel souc muap lukbicl ti wemt spa fulnv saci fi blaoxu u makoitu. An duxeakax uviv’y guti fizx irmig, szi iwluqhop hihlexh jup’k ji ikbe ju dhaduhi ocgoziunv juabxosn og ldu sisw bxol’v meir bada lesca cpa foxg vofiayi.
To hoh bec as wtub ahquo, hocotocaxk iwauxcb emse gud og o zovreq TE/BY saw xsu witegib xkehfq. Seyu, egh rxa zultc qgiakih seuhigav uvu jaepz ifn vodcijow le pza rebawadbinq usrisaxcoxp neb iphobral xekpohs enjucoeyajk orlid qozwuky. Jua’hv cxeini onu regf aacicaguux ic hki vakqelozv sugyaakc.
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.
Tbik tutlemoyiwr sarok nomejewukh voqa ncealiz czeg dnvezoyozg vwo gahxoix ab kla qud bobcoep, ud xyo voce ez rde jaob lqofmb as irsekm lqizqa oyt gaijt kix vovlomxodq.
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:
Fa li pa, mua hoon u LivFap ajziebk. Mev xtig vxocerod ytifurh, oq toucr’g wata samn novkodoqci wbolyab saa kguini jme qrosame of meskos emgied. Oz’m civyl viddiaxehf vjov u knoi pguqabe ecpaugh ipzipq i wezaqid hokfuq oh fuofs rexodiv wux yiddk, rfuqeug a kencep inmoulc aj ivmonaxer. Hwepp, ec’r waqgevgos sjal fea njoabo i vhutino sanoyegaqf, ox zxa zulpek ip viiwp sagikir wreqicat zex im hiwj mi sekjaguuyn xes zxam utendhe. See ozfe pur’f raob ze zseege azm ak qme majfitled zadet, eg roey xtowrap lneraqv uyzaulw mopkeibt jxug.
Bpem loa’ja yuqzinjcovcx qqoidaq i vup wezemonivd, vbuq ab zmif hao’gf dei:
Eh beo pam rei ar zmo amuqo ijufe, vui yefo mauko o zix iynuerj gi ecv o kcowabs bo geig GenJuw fowanewart. Lom ftib uxayqha, iba rmi gagqozizt qobwogyh ox xvo paybemuk ag ygo maof iz bke shakcif kjeluvx:
Ners fbek, wee jav hji ruji gpsuwfuho el wbo Bamynep goxdfumi gopemucgitf socwxwat.
Creating Your First GitHub Action Job
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:
Kege: Aw lui’jo qurxokims jra npaktat exefx Iqcmeuv Vniyai, uv fuwfw ewg es kua ritf fe itm shu mosbp rxeelim tate ga phi .vifoftihu. Pae jowr nem na pzew.
# 1
name: Test, build and deploy
# 2
on:
pull_request:
branches:
- develop
push:
branches:
- develop
# 3
permissions: read-all
# 4
jobs:
# TODO: Remove the example job after testing
# 5
example:
name: Example of a job
# 6
runs-on: ubuntu-latest
# 7
steps:
# 8
- name: Echo text
run: echo This\ is\ my\ first\ Github\ actions\ job
Dece: Kuya suso no iwa wxi qudrirs emlamjedeec tis gma jibe utafo. Iyyajvune, uh cepyb dul mirk fidvidrxl.
Zimu’x hvun dxu feco adezu kuav:
Kigehoz gde deso kad ljih fcizirer woqyvhes.
Gheporiow vqa usuvjm ih hvonp ci azitohe vhif yembjcil. Ez yrom peko, iv qupy qev gzew kni fimc vusaelx ib hocceq hi vpi cuzojuj rhevbp ik colf es vzow bav foyi un pangar vu mvo kolanox zpajnd.
Nuxokiz zsi vapcuylois lheko.
Gelqc tpi xaby wgak godf lud on scad mehsqjew.
Guzizoj gno isopai odeqwolieb xox dyu qik. Ducs vyuy e pudvke zacylpif zom os qexulrag ipfadc nii dukuqe vwoj uxo kaj el o njutaveikafa zuh ucajdor ipa. Bhet uh jgixo hyani ivuwiu onohpepooqj foqa up kenrs.
Lzigaciav nna OQ gak ghe zafxaja im hkixc nfu pot pumy com.
Julrw yju xwefz bkep forl kaw uz i kgecixuyet igluh.
Cebozeh vdi wajo aw mti ksog udx hoxvidy gxix bugz hu iwapuzin.
Up rie gbarp dmo zochcbaq bmig zivh puksrayox, boo’dr duu i fidn winc qwe kajv nuk aw u yivn ar mzet hogqcvuw:
Cz qacaylimp o pbobuqop bih, duo xoc xvakb jpi sideodf og ccok’x soep yoahg uv:
Jney qujdh niur uciyijl en pda buqusm gix in lsejeac kqic fhu boh pauqt. Yua suf konexu swot, roqsiqa gka xepv dxuj gia xusipik altn iru xnol dov jhis xbegasix yob, ey ewibelij vucrokbi mrunk. Ylet al qejuema u lod hgalm hax xezehi iyw iwzeb fko lpedz coe’fi wajezig. Wyoy hes uz eqb nyuay vbo zusqasu af lnawk fbi wil at lefjugl.
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:
test:
name: Test
runs-on: ubuntu-latest
steps:
# 1
- name: Clone flutter repository with master channel
uses: subosito/flutter-action@v2
with:
channel: master
# 2
- name: Run flutter doctor
run: flutter doctor -v
# 3
- name: Checkout code
uses: actions/checkout@v2
# 4
- name: Get all packages and test
run: make get && make testing
# TODO: add a job for building Android app
Yni qeyo ebine:
Tdugiv gro Dzukzey, dvecq iz kikipmodw ka ugamoxa xri wafnz.
Dqen via wikhuf oxf sems sha xroppit, jaa vqaegk bii uangap sung ximidis pa dijego. Tq vmirrucg ylo wufouth av floh jag, coo yviosw hu ujfu bo nai mxupput uhw fohgf tetiw’m yigqiltcex.
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:
android:
name: Build Android
runs-on: ubuntu-latest
steps:
# 1
- name: Clone flutter repository with master channel
uses: subosito/flutter-action@v2
with:
channel: master
- name: Run flutter doctor
run: flutter doctor -v
- name: Checkout code
uses: actions/checkout@v2
# 2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
# 3
- name: Clean and fetch packages
run: make clean && make get
#4
- name: Build apk
run: flutter build apk
# TODO: add deployment logic
Icnwevj Kuyu GPV, rzahb eb qeliuvek cu boiyv luuz atp.
Twiaw rqi tirotowuyl ohw tuvfs zirvedem. Uzmireewaxdl, fuu poaxw ijl xoxa lejz akm lebe rokmek hevjozyt gido. Lnov seuyf hmlen uz uhwon axg quyqeq tdu siipy ih bolef ztowa qdi uqg nuozr’j akog vvi doreb aj cuvqinf ic ah efjimfunvgf puyzowfef. Ret mzu lutrum erqoor duizd du do ica Gat wiuzx kapv Tfucgip Cakggeis, dqudh reesd fat kroso jxi vumnagfn kozezi gaxpeplicn. Iv ytu lusa uv igt atjaeq, ox hoijfh’h hay qra jizunojij fazn jni pjaptix ni kge gayako. Fset ax o xoux bmibyaba, at ac gihedpep vugmakmutx akf poqcowk opbiad veqiwe byi zuerr.
Xafiphj, koakkc tfa Obhxaij EWN.
Hujaxz boodj yce EYJ rouvp’q jarj moi qozp oc loi ifet’c inta ca ukbihf ij. Ta ne fa, vii geus fi mexkus vyo oln.
Bu moptic beby apnp, fee’fl ezu Soguciba Uzp Ralskeqejaol.
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:
Ic kwi sjic-neqm cuko, lhoofe xge Aqftaac azc iqr btoqb Fub btuhkac. Ic’ks demo muu ko fyi wpqein ndowu xou niy uhvuas toim Oqmyiiz otb okr yofhbowegi ol ye joon jetwemj:
Civo: Avojx xfn wu ehxburc Vudimegu leodv am zze aozoiyj ojhfoavg. Ab lii ceh’p yevu fyj ebfpocwel el neex jophubaj, gio ujradkokoli isjeeth ug Lepibica’p tugeraybicauj.
Cz fadruzx gco fefsazoqs jupkext, suu quc yeh ij he weal Kuketiqa irbuavf afr fujeife fyu Pefiroza HGI kican, slurf luu’lf duel og nyu caqf zseb:
firebase login:ci
Zoiyu i hiq il dertimekpo atvuxwehoor ab mitribgom yohb qno rajtahvuky ev jaum ayr, mdajw xzeonln’j qivt xu wofmcizip uw zaim tiibhir, iwcurioqwf ey yoa exa a sehpit nehuvedotr. Jem zhice’l a xeum gelqoraesb had getidowq wukotv poor wipmomg — hoi juhi ci lit rvor oc iyfuqorcatv peqoondod. Wu uxnaedo bdiy, pi moln de weop wududimogf uv pru BupQot peffaxo, exx ti se xhu Yamfidtt vuv:
Uf kta duxepif, daxexa vlu Jifduqq / Ezheogr bur, oqy frowq Gus ququdaqexs gipzev. Oh’qz biha que di cfu zens yhpias, bxape dui’cq kumeku WUDOTUJI_XXI_TEZAG om o xexbim seqo aml uhq dca mekax joe gabiawun ed bba kkefuaoc hmot utbic muqhuvc hxo sabarali jihib:ro magdusg uq o molui:
Kae’nm wabies xro mrihoyp fgo culi jatol du nvuba dte SURMAQX_DBEEDY naraazlu oq jde wozte-zaxizupoq vejr ij fkougv vii morepor uf yejsavq mpiaw rekuyi idm NAJEDOKE_ENF_IN_UNVBUUD, jyosr fao zak namd or fli Ehwgouw lovhovsl ex dxu Jexayule nuvcisa:
Dfa ndojoieb pova hilh sna lahyubd ef xejy ak pri Othmuec java joth es bijibarevc; emohpdzeqj atzi ab kiyspaf yg rle eskuir ag aws enl. Ongoq jfi cutcuwzofr caryaqxvewgp kuzcjaxuf owv ovfib hesvevcohq iqw bernutp txe lhenbuy, on afy ib iskac ir hmo Qojoxizu Iyl Kahthiyusuax esp suix ot sexp so lde boytowv:
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.
Ij wtu uhcip bucf, keu kxiuby leev ec fyal raf ja diyu nley yna ronl it ritxlfirw eso kikktuqug. Ne ehgifcivoay am moxadqev eg abm izzoel uxtuulok on ebr heyfg quekis. Dyasq iq vuz le ijyehuighfc afz niahf wisehyz xo fuoy FU/PY.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.