 Hi everyone, thank you for coming Quick reminder, they will still have JetBrains licenses to give away just open up a request on any Kotlin project And I'm happy to welcome on stage Martin and Michel and they're going to talk about automating our workflows with Kotlin. So please welcome them So my name is Martin My name is Michel and today we're here to talk about automating your workflows with Kotlin and Improving your developer life. So we are both Android developers at Dailymotion So everything we're going to say is going to have some kind of Android angle and mobile app automation But it's also stuff that you can use and we hope you will use for other domains, too Okay, so let's start this presentation with a little review of all the tasks a developer An Android developer in our company has to do but it can easily apply to any kind of developer So basically you have tasks so you are seeing a ticket then you create a branch to start working on this ticket You have to code Then when the work is done you create a pull request You have to move the ticket state to in review Then when all reviews have been done You measure your peer you move the ticket state to done and then I don't know if you have that but You know company we have alpha every day every day we have to increment the version Then the tag push inform the product the designers about what we have done What we have done and then eventually integrate feedbacks And again, you have to back step one on another task So you have a lot of little things to do better. So For an Android developer you have to manage app translations. For example, keep the store up to date notify about the updates manage app rollout and Eventually published to alternative store. I think about Amazon All I want is a little task. You have a lot of search party tools So You have to switch from a web UI to another one From a tool to another tool and this can add a lot of friction for a developer. So what can we do for this? Yeah, so we we very much like better to code rather than go to different website and click some stuff So we thought about automating and I'm first going to tell you why not to automate and Automating takes a lot of time. I like to put this XKCD strip on the right Where initially you're thinking well I'm spending all this time every day doing opening put request and changing ticket states and stuff So I should automate that right and then I have a lot of free time and I can drink more coffee But this is not how it happens because you have this initial investment But you're going to need to maintain that initial investment over time So in the end you might end up in that situation over there on the bottom Where you have no more time at the end of automation But there are still some benefits and the real benefits there are Reliability and reproducibility reproducibility by that I mean Your scripts they do not make any mistakes They never forget anything. So you are guaranteed that if you run your script several days in a row They will always behave the same and behave consistently also a nice addition is that Scripts will become your documentation. I've seen a lot of projects where the read me states How to first compile your project for an example you come in a new team? You have different steps to do to compile a project and this is all in the read me if you automate that it becomes just one single command Same thing for deploying releasing etc So your documentation and your code becomes your documentation and we're developers. So we we like that and Lastly, it's also fun and with Kotlin We hope and we we think we manage to keep the automation time to a minimum and keep some time to stay productive So why Kotlin the answers are We're pretty obvious to us. The main thing is that it's the language we use every day So we don't have to change our brain and change our mode mental models to write our automation scripts I call that the bash syndrome I did write a lot of bash scripts in my life and I never never managed to remember how to work with arrays and lists Or just how to quote parameters and stuff. This is stuff I have to look up every time with Kotlin. I'm using that every day. So I know how to do that Also, every team member knows about Kotlin. We're Android developers So now everyone knows how to use Kotlin and it's very productive at Kotlin Then it's also a very modern language. It has a great idea if you have a great machine It's going to run well usually and it builds on top of 25 years of Java, so if you're looking for something a library or tool anything It's most likely there So in the end we ended up replacing a lot of different languages and framework in in our app In our repo We used to have a lot of bash script custom ad hoc bash scripts that were written over over time For dogs and all of different things. We used to have fast lane also I don't know if you're familiar with fast lane to automate app releases Which was written in Ruby and it was very painful to adapt to our needs We had third-party tools GitHub comes with hub written in go our translation tools it came with a Ruby client and Also, ultimately, we also moved our build system to Kotlin. So now we can do Kotlin every all day We did this migration using two main scripts, which we are going to describe a bit more in details The first one is Kotlin scripts based on casecript and second one is a Kotlin common line app that we called kinta and runs from bash So let's start with casecript So casecript the motivation is to replace small single self-contained bash scripts It works well for short project single file project, and it's very easy to use actually The Kotlin compiler has built-in support for scripting so if you Have a Kotlin compiler on your machine. You can just Start writing your small elo.kts file You can even give it some arguments. It's a list of strings You fit that to the Kotlin compiler and Yeah, it's going to work. You can look at the specification. It's worked really well But I mentioned casecript earlier and casecript brings a lot of nice improvement to that raw Kotlin compiler scripting support and the main one is that it's going to cache Your compilation units so that you don't have to compile your script every time So if you run the same elo.kts file twice The second time is going to be way faster, and this is always nice Also, it comes with an interpreter so you can use shebang and directly run your script and Full support for dependencies. So let's say you want to depend on some HTTP clients that you love You can do that You can also package that as a standalone binary which is going to include all your dependencies into a big fat jar Also has IDE support it can generate a small intelligent project for you. You can read everything on the github link So if we take a look at a sample casecript file I'm not going to go too much over Over the Kotlin code there which is pretty standard This is a script to determine if it's a weekend or not So there is this website called is it a weekend yet? It makes a HTTP request to it and then passes the result and display if it's a weekend or not Two interesting things in this script is the first line here So the shebang By that you mean the you tell the operating system that your script itself can be executable So as long as you set the executable flag on it, you can just sorry You can just run it just like you you would do with a regular binary Yeah, it says it's a weekend because it's Sunday. Thanks a lot for being here Second thing interesting is Dependencies so you have an notation brought to you by casecripts That allows you to pull dependencies so here I pulled oki HTTP Which is a pretty standard HTTP stack on Android Comes with ID support if you run casecript With the dash dash idea. It's going to generate a small IntelliG project for you Then you have autocomplete on all your script variable, which is very nice And it comes with debugger support as well. So if you want to debug your script, you can and Pretty sure it's hard to do with bash or any other scripting language So in the end we use that for a lot of small tasks. So typically generating docs install script One single shot Usages like we moved all our groovy Gradle files to Kotlin and this involves a lot of reg axis been changing some Single quotes to double quotes. It's it's not very hard But when you have a lot of gradle files, it's taking a lot of time. So this you can do easily with a small script Also, I personally use it to categorize my my expenses and I just did it for 2019 but There's something else It does have some limitation I mentioned it's based on the GVM. So your users will have to install a GVM and The script will take a bit of time to start Working with multiple files is possible, but it's not that easy It's not designed really for that purpose and since you don't have a gradle You will not be able to do code generation use gradle plugins or stuff like that. So Let's continue with Kintar. Kintar is over Kotlin cli. It's something a bit more complex with a multiple files For example, so let's put on a clicked clicked is an open source library It's a variation of command line interface for Kotlin Basically, it has all command line functionalities to Kotlin so commands fully customizable message commands You will have the help for example So if you type your command H you will you won't be still you won't be lost you will receive your help For parameters, you have arguments options that are composable Typesf so it's very easy to declare Double or an enum for an argument you have prompt and default Why we base Kintar on clicked it's In fact for Kintas we have some workflows some dedicated the global task we want to achieve so we need entry points for these workflows and What else and comments for that it provides a simple way to? To learn these comments by anyone because more or less all developers knows about command line interface So it's made it makes things simpler for for it for every Developers and every platforms technically we had a Build gradle.kts file It just we apply a plug-in application. It's a generate starting script Then you get a jar and you have to specify the main class entry point of the command line up Here you can see What's the the file looks like? Okay, let's take an example a published play store workflow First we have to wonder what is a workflow a workflow is a list of simple batch of a simple task We want to achieve For the workflow publish play store for example, you have to upload an archive to the play store But then you have to create a release on a specific track Find a local changelug on your machine and then upload it to to the play store With Kintar we would like to to run this kind of common Kintar publish beta with Archive file as an option and so all this task will be done directly specific Work, workflow is very easy. Just you inherit from a clicks comment You specify the name This will be the common name the help of course for arguments You define arguments using the bi argument or bi option With help again, and you can see the double is very easy to declare No, you are just to write the double and it's okay click comment comes with run method And let's look at this method So for this workflow we have an upload draft Okay, it is with a play store integration something we have we have coded into Kintar Load look at changelug and then upload or what's new? Following this method the Kintar has become or Swiss knife. It makes a lot of things for us So there is a lot of domains good tickets, so we We are doing some start work PR things for translations. We are using a Tool named trans effects. We just have to push the source then we pull the translated things. It's okay For the play store metadata, we have seen beta release, but you have we have also the possibility to upload a listing or other stuff like that a quick note on builds We have a CI but we use OCI just for the machine. In fact, we download the work in the binary and then you do it We directly lunch a Specific common for the type of build we want This is very simple because if we want to reconfigure to change your CI one day We don't have to reconfigure all the stuff in your new CI. Just download Kintar and launch the same command The history is in your build pair build type command, so it's much easier to maintain And so let's back to the daily work of a developer So I see a ticket create a branch we start with Kintar start work With a ticket ID for example code. Sorry. You just have to write code Create a pull request move a ticket state. For example, we merge it in Gintap here Then we decided to keep the merge the merge action into the Github interface because of several checks and For the alpha version so increment version in one read up Tag push send a message to everyone only a Kintar lightly command. It's okay. So It's a it makes very life easier and We were very happy with with this tool with this little tool. So we decided to to move a bit forward And the next step was to make a Kintar tool usable outside of our company We had a lot of cleanup to do because there are a lot of things specific to organization And we have to define some some stuff like what is a workflow? What is an integration? so an integration is a Kotlin specific class Particular tools or a Github for example or CI or translation tool It's highly reusable. It should not change that too much Too much. It has atomics method. So you can everybody can use this method a Workflows a workflow use this method use these integrations to achieve all tasks complex tasks so Start work for example and When we decided to make a Kintar usable outside We realize that it's not so easy because Workflows are mostly specific to to an organization even a project sometimes so we have to to To restructure work in time fact. So what? Let's see the final architecture for for now So we have a Kintar key. It's the entry point of Kintar We have some built-in workflows or built-in workflows are very reusable workflows such as a clean Github local Clean Github remote. We have a basic published blaster workflow It allows a developer who just want to use some basic things without coding to use it and To match all processes from different organization. We have a custom workflows So when we need it clean Kintar, we create an environment where developers can write their own workflows This is where all our specific day-in-motion workflows have been coded All these workflows can use the Kintar integrations. So all the integration from some sub-parts tools and And so it makes things simpler technically The Kintar cli loads the service locator of the two artifacts of custom workflows and built-in workflows Merge all commands and then when you launch your Kintar command all these commands are available So we've seen that with kscript you can run single-throught one easy single file as created very easily With Kintar that we've been working on You can manage more complex workflow integrating with sub-party services We're still working on it. We are currently fingering out a way to distribute Kintas executable Maybe using SDK man or some some other delivery mechanism Also, we'd like ultimately to have some kind of web interface which we already have kind of For hosting the versions so all the app releases and also changelogs So there's a bit of work to be done there We are doing the work on this repo over there. So you can go feel free to go and take a look We are looking forward to hear what you think. It's still very early So Please be gentle But if you have some things you want to automate or stuff that you're doing every day And you wish you could do in just a single ice, please reach out and we'll be happy to look into it Think we're done. Thank you very much