Automate Flutter Build and Release Using Github Actions | Flutter Automation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back to the channel everyone today we are going to learn some very very interesting and very very fun stuff to do with flutter and github actions and trust me no one else is going to teach you this kind of stuff anywhere all right so what are we going to do let us first try to understand the problem that we are facing so now uh we have built this really awesome app but suppose we have some friends and we want to share this the the build file the apk or the iba file for this app with those friends so they can test our app for us well right now the process in itself will be very tedious we have to build this app on our local computer and then we have to share those apks or those iba files with our friends via whatsapp or via google drive and so on how about our releases or our builds were also available with our code in our github repository so anyone can migrate there and can download the apk or the ipa file or the release of this app and install it and play with it test it for us and so on and how about this entire process can take place automatically every time you push your github repository the only thing that would be needed to achieve this is a one-time setup imagine how many hours you you would save by following this process so let's go ahead shall we let's quickly get started all right so the very first thing we need to do here is create a root level directory called dot data now inside this directory i introduced one more directory which is called workflows and within the workflows directory i introduce a file called main dot dmr now the very first element within the cml file will will be a key called on which will signify the events on which this workflow will get triggered so let me just put out some comments suppose i i want this workflow to be triggered when we push code to master or main branch as well as maybe a pull request on main as well as master branch for a push let's also develop all right so i introduce a key here called pull request and within this key i specify the branches on which i would like this workflow to get triggered so for pull request we had the main as well as the master branch okay and next let's repeat quite the same process for a push say push on branches main master as well as develop now let's give this entire workflow a name bill and please let us next specify the jobs that will be releasing as a part of this workflow let's call this one let's give it a simple name such as build actually it's not the name it's just a key to be specified in the yaml file next let's give it a name let's give the same build and release and actually this name can go here without any quotes as well right after the name we have to specify which os we want to run this on let me say mac os latest you could choose ubuntu latest also but since we want to extend it for ios and ios can only be built on mac os we need to specify mac os here in the next line we will specify the steps for this job all right so the next part is really really interesting so the first step that we might want to do when we build our code what would that be suppose we have to um you know our repository is is on github and we want to build our code locally what would we do we would first check out our repository and then go on building it right so similarly um assume that this entire workflow will run on virtual machine so the first step that we need to do here is actually check out the code this can be done by using a predefined action within github which is the checkout action and the version of that action would be version one the next step would involve setting up java for which also we have a predefined action which is actions setup java now having set up java we would need to set up flutter for that we would we would use the action flutter action all right so the code has been checked out java has been set up flutter has been set up what do we naturally do next well we run a simple command which is flat upgrade to get all of our packages great what should we do after that well we should ensure that all our test cases are passing and of course that what should we do well it's simple isn't it we should build our apk files well all of this was pretty awesome wasn't it so till now we have checked out our code setup java set up flutter was that we have got our packages we have tested our code and built our apk now just notice that this apk would right now be lying within a virtual machine we need to actually send it to our code repository so that it can be easily accessed and how exactly are we going to push those bills to release we have a predefined action for that also which is nicola release action version one all right as a part of this action we also need to specify the name of our artifacts right here so our the artifacts that would be created and pushed would be build apk outputs apk debug slash star which means all of the files which are present inside the build app outputs apk debug folder will be pushed as i released to our github repository now if you see the general format of release releases are always stacked with the release number so let us specify a tag here so our releases will will have a version number v1.0 point the the github run number so if you are running it for the first time it will be v 1.0.1 you are running it for the second time it will be version 1.0.2 and so on now all this is fine and it looks amazing but tell me why would github allow anyone external to your repository to write to your code repository they they they might even delete your code or do anything with your code they may modify it in malicious ways introduce bugs or security threats or anything so get so github will allow this action to actually be successful only under authentication and how exactly are we going to introduce the authentication i'm just going to tell you that in the meantime let's introduce an auth token here the key would be token and it would refer to a value called secrets dot token now we have to head on over to github and actually generate this token all right so for the fun part head on over to github settings github.com settings and head on over to developer settings within developer settings you have a section of personal access tokens go here generate a new token note for youtube demo and give it the repository score click on generate token your new token has been generated now please don't try to do any funny stuffs with this token i would anyways be deleting it right in front of your eyes towards the end of this video let's copy this token and let's head on over to our code repository now let's go to settings let's go down to secrets and let's add a repository secret let's create a new repository secret and the secret no name should be token and let's paste the value right here now this name token where is it coming from well it is the same name that we defined here in our workflow main.yaml file now suppose the name was token 123 you would have to define it as token 123 here as well but now since the name is token here we are keeping the name as token here also let's add this secret all right now the only thing left to do is to commit this file add build automation github let's commit this and let's push our code and let's see we actually succeeded in building the automation pipeline if i come back to github and i open the actions tab from here i can see that one workflow has actually started running okay i think so we messed up the spelling but that's okay let's let's go inside and we can see that this is the workflow uh it is has been triggered by a push um and the file name is main.yaml and as you can see the name of our job was billed and released okay let's go inside here and these are all the steps that we have defined in this file itself you can see here we had the checkout we had the setup java we had the flutter action and so on let's let's just wait for all of the actions all of these steps to complete and our releases and our releases should soon be built we should be able to see a new release right here when one of them is created so let's just wait for the actions to complete in the meantime all right there you have it all our steps have completed successfully including the build the push to release and some post action cleanups so let's head on over to code and we should have some files within release oh yes we have one release version 1.0.1 let's click on it and yes we can see very well that there are different apk files which can be downloaded and installed in your devices so wasn't that awesome now let's quickly just extend our solution for ios as well now in the interest of time i am just pasting some code here um it's a it's a simple build process for ios as it is done better so i won't spend too much time in explaining it and in inclusion with the apk files i also need to push the ipa file to our release and that is it that would do the process for ios as well so i hope you learned some really cool and really helpful stuff and i hope that this will really help you and save a lot of time for all of you so i recommend you do try it out on your own and see how it works and if you have any enhancements please do suggest them to me as well if you like the content of the video please do hit the like button if you continue if you like the content of my channel please click subscribe you can hit the bell icon to never miss any new updates and like always thanks a lot for watching i'll see you very soon with a brand new tutorial
Info
Channel: Codetuber
Views: 11,636
Rating: undefined out of 5
Keywords:
Id: 9L7OfshBqX8
Channel Id: undefined
Length: 13min 8sec (788 seconds)
Published: Sun Jul 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.