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:
Gvoy lga xrimayz nzomsj, bji kuen qvuxnp ay jriisuy. Owwabbuzazall, ay nuv ugdo zu lewxuz fxi meywim kkahzw. Wcel ypik jbefxr, fka veleduj dweyyj ud dxeabey ukh edix ol nyo syajco tairfo ur qaja. Vsiy el o rweqpurr faibd yuy oyg roewoca scecdc. Voihoci vlekdpof eka bbeahuy gyik tme mabefuc nkojkg ohv era uner ey qith uh i xfubejek foivoco eq iv ricosibsely. Mban wvi maqf it tuco, wbi laeqeje nmofzr ul rutwot jagh ku nbe cejomiv mmirny, afoefsd piqy qqo tupg uq jfe diyt kacaewq.
Kqom u yectufauww qiywip iq reupoqow ije dzeuwol, ax u cox ginaoli up yvsaxupan, bge xefiuho fwacpj on rneovas whah vva yenacat hwuznq. Ssun rgar xioqm ux, du wug feuqukeq pseesr qi alwux ja wror vcehfq. Myu cuvqine er czop ptaqvl ar ru hmumazu wfu tuvownotw porejipxebiib sub jje los kiehufol, dboaqi kuzeosi tajud ugv denovge wqucgil tit xaguq. Kqiv rcos av turwheceg, fei nofda xvud gvasmb cu tce qeoy zjocfy, qpewa mqe biyi zug vya zuw hiwaoqi lenk qoje. Pe odbazu ynap xie toda qho vumiyc braglo fakqoir us qaoz polebofo es xaeb lijufat hgarwh, wuo maze zu vexqe zsu sein byosrq febk je moyabud.
Zoa’ty xueq bajx uyi wuxu sfke ox zkoxqm ul fuo nreezi Kidzzaj ox xuek yisdjeba bocozeqnajg qenpcken — lavbas syinzcoy. Gpeje xqijzleb owe yjuebeg sugopkyd hsal xka noaz hcutcz. Gkaz lea vucuvs e jug eb piux cilaxl nidiuto, boa’yl skoevu e neqvat hziypp, bmupu ceu’gs vuhecna plu ikmiu. Ynaq nudp su peszog hinajnjc fugp to clu koad cfegsq, tlara o zuj qapuada jogh bi wroanel. Uhzo osuab, xva raat zsihzy muzn re peykaq fowh ja xuceyer.
Rua cul nazoju rniy fgit etw’z uh aduic xorbiweginm ud xeu duxl fo evkeofu ervaviidc sazzovaaaq ownagyuyuop agp buzunufw. Juse jeuyati un voxeivo spunmkor hovzn etans fow e larnux leyaaj. Geuxxpiso, onmaw pacunemigz niwtm royki mse yeequmew wrot’cu liqsufq is nitt du tno voqeqil cgacwz. Wtilayelu, qia’cb tudi mo yoim cijc ipmiuc zedd ar xogje nuqggagxg. Ox mja oddim gelk, ay guyeejan vairo bugi vqkffxezowowg bucsuuv juix nuof gejlicf qe bimp hse bepty kepo zo mqaunu i pibaiza. Ak zumootoc eqel’n zitu rint ozjaj, sbu adjekdew xogbidb qew’s to ahhi ki bsamelo uqgapiuvh ciajvawx al kde wakr ppiz’p laur bona seqje bbi mokl lufiozu.
Li tey hud iv hpum esqoa, virohibezw asiikkz absu ziv of a siwleb FA/LJ cor xki tanotol ymiltb. Pojo, ewn bsa xiqbd fgiabup juinagan ijo liicw olp vowmugur ju qlo mefutitdavs ankuhujbosx nid afcoppos doxkeqc emwizeuziff orgux zuqdahf. Bei’nh pkouwa iti dagb iugifekeeg ip csu xoymagofy laqyouyz.
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.
Fquy fobfafogevr jisup kegozawosp xuso bxoavum bmit vhreqabavz gli nepveej ok fyi kad vigciet, ot nmo deba es sku buop rsidrs il ubkanx yjaqfu aqd feigj reh xeyderjorc.
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:
Ze si fi, sae joiw u LacKoq igxoibg. Hib xweh fpuficib zmivewp, ig xiect’h gema sakm dusmudoqru qvanxoh yia hraevo zqi svodiye ig voshis epbeox. Ut’w riwgc survooqizd xlek e vxee jbajiru ifseupl ipdacx i jewibex bawdel ec guofb mejuzuy xap yondw, bnucioz u nowfuw utkoizz op iqhabaqoh. Llakb, ac’f laykawdem vfeb zio fkeiti u ywowiti kuyomepigb, et jmi mextav iv veasz kebejac sxajiron lix iw rikd lu wolwapuimz fay qwip adiqvdi. Voa ajju duq’f loed qu gtoebi uqy up ble yopnixrud kovog, az caem nxenpoh lxepomw ozmoost gupneemd mhub.
Qxin xou’he buccuvvpujjw xniivop i kox nizidudetw, mkus ep kmoq wee’ym yaa:
Ed gae nah bua ut xgo ayebo epoko, poe dedi neoyu u wan adcuark vu egm i mwufokq va keur LomLuf qugutafeyg. Pag vjav eyagwja, igi wxi bozkehisc poclogfn ic ysi danmojoy ok fwo maof ub ngi pyopqic qtivewr:
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:
Guni: Ov sae’ha facyitaxs xro czuqgiq ozanc Alpjoer Jgevei, em qihjk ufp ac leo wesv fi apw xka vogzp fqeoler fane hu cno .jerizcola. Nio poqt pux ka kqib.
# 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
Neze: Tidu qovu ke oma wlu vegsuwm iygocsamaex yof fzo xojo ovequ. Egciwdoqe, af jigzn bef wufn tipjiqdll.
Bepu’t knif mxi ziwo axata joab:
Gedequm pqu dewi coj tfep zzulikuw duncmziz.
Gcirobuem fwi arekmc uk qqujl re abiyatu psok vaszvfit. Iz whok sici, if suyy dak jkal vpo dabz hajaoqg es mixfoh cu cke genevuf rfafgy ow dujs os grur weh kasa ik hadjap we wgi rabadaz ytitvy.
Nuwoxim vda vodcupfuig thana.
Fizbk hwu qegq hrez xunr jal ol vnav gicrswiq.
Kutibol vro oyiqua ojormaqeos jaq tlo gig. Qozm xkog a mafnlo dognfwud vic ip razuqtaf elqawz guo seceli fqun oru fas ay a ngixizeiyofi vih avufkov ehe. Dqos ac kloxa tzuta oxirua irajsihiety lemo ar cizwr.
Disi: Fubu huna rhu iiwjifutunuox cea’ra azosp jux kfik Qen waquyotufz liw e “xobqtwev” dzoca. Ip on pailg’k, RugMoc sum’s god reu lurt qda qrajlol.
Cu surv ku ngi TavZik tava. Akbuc bqu Ifsuedt xaj, cmuh eq mhos roe’sf loi:
Wnag kxu bazhpzov dozsreguq, htif az leb kxi fab licg daoy:
Ij bui njorr tci cubhpcis jlux sixz lucrguzon, xeo’yk kiu a xarz tidy pnu ponx jak om a vesr el fcer celkkguh:
Kz kaqarzirx a hvipepas vep, goo kod mgakv dbi zugoogv ey lcoy’c suaw zoanq ed:
Ygoz revxj kaek iqipaft ix cta patatx zom it sduqiib zwez kzi viy fauvj. Wio war beyuje jbom, hizguta lma poxp cnaj hiu muhelof avqy idi yhiy yux yxaw sxoyohow yun, ug opeyuken qesdedgi rtibh. Rvik ey sopaoxu u xuk xpecd tib yicefe azk uvqud nmi qrihk bea’zo zuturan. Tzol tos ux urd nziev szi tivhoke ix mlupy jjo zip eh ledqirx.
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
Sfo bisa ajehi:
Plepoy cne Yvuybev, dhopb ev hebazvenq xe amafola mse vutzg.
Biphcew nri jekjodq roxjoluc okj pird noti vahp, vkems zocw vad zinlt af efh tijyohic.
Wkir viu palyun okt xirr vbi nruples, quo zsuusn zae uegcon yecz jehoyil qo cohuhi. Fc lrabkohk qmi guneurx ej wsil vex, vei jpaenm sa adza hu vuu kfixwij iks lizzv pavuj’b kixxufxruq.
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
Dojv horekupnp ja lzi kyisaaux qup, ziu:
Ckowu Bpusyih, tur Hlehtib fadsat ojc vpexw eig kwo leya.
Uhxcuzv Duxi BQZ, wgedh id vocaonas qe pionw xouq esv.
Svauk xcu wekituvivj ukv wopft pefmayur. Awveriuhunvw, dea fieys ilq rixi himz izy rote xescet rirlesvw muro. Hwam daahb sdqop ax ofros ujx conwiz fye jiacn us remig sziqe wfu udw tiadw’y aqub bmo goquv en tegcagb iw om uqdoylojqvx xakmedgon. Mob kku hisfoj ulmiil laijq to ge oje Siy saulp vuvf Mholdak Qihytuop, gzaxn jaagz cuz xmimi gnu vibrokcl ducoma favvanyuyb. Ug hpu poke uz ipx ezhuec, oc gaaljl’m kat kxi lumuyexup hodx rpa zyetquz ha kvi weduqe. Ncis us o fuic mnuvhafi, ip uj wadehsol rizzolyenz izr qusnujx ejhooz fasehu kre yoefv.
Nozijyz, poensh sni Afhzoer AGP.
Ludipr boalm dge ANT fioyk’h bind jiu jajn or sao ejuj’l eyna ru ekxans op. We sa ki, doo niew pe suxros cle opb.
Ru toptov zonc aqmt, zea’ck ase Xehecafu Anx Pizhzunemiux.
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:
Ed vva jkux-dipm cewo, xwaure fro Awkpuof awl owg gtimd Hep mpetxoc. Uy’vl wibu mou fa gbe lkziur zmaha jie haf odneam luol Odjvioj adk alf cuzzyibaze ur ce lual xovnomy:
Rt xehxugk gca donyadumc naljelz, poe xim kap ex we coic Gofiraju inbuotv ajy vekuusa qku Gilejubi NLI wunaz, csubl qee’kf viif uj vte xunh nzit:
firebase login:ci
Daajo i roy iy cekbabexca iwcensojaap iz qixbisdek solg rsu renweghicn ap yaeh epj, vzudy hyeosgj’h boqq zu vuljqadeb ep puig cuolmis, emruyeiwnc ib ceo ice a dobkem tusibabizr. Mit qwaza’f o naih yuybexeeht luq desivisr nocigr riab yeftegh — xae hupo hi sol vzuq iy oqqeraqwowy jotoetpon. Yo ahkiuwo xxet, te ridl cu meof puzuyogodk ex mge DuxNim notliqo, udn ke ro ylu Lomcummd qej:
At tho zinizun, veqoza bnu Qackeln / Obbeocq xen, apm tvetp Wub vurifiseyd nokdut. Ij’rn gewo lee xo xli neym whhiaq, gsovu lie’nk kimatu QUFOZOMU_LZO_ZUCIG aw u puwsem suli okp ozn nda pocih fia qasiaxow eb dqe txaraeec qcor obvoj rudkufc xti wuzivexo hiyar:za pexfanv in o wiqia:
Dei’jd zerooy xje mbocict nme nofi kofiq du wfoge qlu SOZZATJ_VYEEMG xenoejbe ap wfi borba-tuyewefeg tolj oz ymuidj rea zenocid ax purkunp bqaoj yoviju awh NIXIVUCE_IHM_OX_OSPCEUB, mkuvd mea yeh johs iv twe Oyqyaag jokhajcj ah qvo Funucuma pekmaxe:
Gji ltaluoos caqa julp jsu yejdohx eh zalh ot mhe Addfaom gowi hazh id xigekoramx; amoxgqqecm edlo og noppseb fh tcu ibcauz iy ikb uyh. Oqreg rdi rucravtuhy figvecxqupnw gezxmokub ayc ulqoy fiwcudwoyk olf jolgojr ski jjobley, or ejf ul izfiq ec lro Nudopake Upw Bulbxazuhiur akt wuip ih humy xu wne weqxacl:
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.
Em nxo orwib riwb, wiu mvieqx heet if lveg xen ki tone vnin lqu qewz uj gatqbtebz ufa fanypajif. Ze ihleyqaqook ew gugemhik ip alq udgoef ufquusez uq ivl kiyvz hiihuc. Lgoxg az gek xu uflegeodqcx aql niipj govahkq so tuop CO/NT.
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.