Creating Your Own Build/Test with GitHub Actions

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi my name is Sean Wildermuth we're gonna try to use actions to build to create a common build for our github project we're gonna be using actions to do that making this video for a couple of reasons one I really couldn't find a good walkthrough of a really simple straightforward CI build and the second reason is that I've been lazy for a long time and I haven't been doing proper CI builds so what we're gonna do here is actually create an action in github for creating just a simple build and running some tests and you're gonna see everything if I run into problems I'm gonna stop and create them I'm not going on much of a script here let's just do it and see what happens because likely if I'm running into the issues you'll likely run into those same issues so be nice to see how they're fixed so I'm going to start with a project that I haven't actually added an action yet to called my meta weblog project and this is a pretty simple project that's out there that allows you to add the meta weblog API that WordPress and live writer and markdown monster all used to allow you to post things and you can actually see I have a build passing with app there but I'm gonna move this directly into our own project and so all of this actually starts right here on the website so if you go to actions github actions is gonna try to give you a chance by looking at your repository to figure out what kinds of action you want to do and for us it's guessed correctly that there's a solution in there so we want to actually create a dotnet core and the way actions work is they have a number of recipes so we'll see a couple of them when we get a little closer but if you're doing node or you're doing rust or Python or whatever the case may be they have these recipes as sort of a starting point so let's set up the workflow for our dotnet core and all this really does is just make a copy of that recipe and put in a new llamo file into our project you'll notice it creates it in a dot github workflows directory and then we can go ahead and name it and I'll name it very cleverly the build and now that we have it let's talk about this llamo file by editing here on the website we're actually gonna get intellisense so i try to come down here and just say like uses and it's wrong well actually get errors here and if we want to trigger autocomplete we can also just use the control space and it'll give us a list of options as we type what's most important is its gonna do some error checking as we're doing this and so let's talk about the project top-down and then we'll sort of discuss what's happening first we need a name and this name actually is gonna be one we're gonna use later so I'll just call it our build and test and this is going to be a visible name in the action to see whether they're actually being run in so the the name is just the name and then on is when to actually do this action and anytime we push to the project we're going to do it you could do this on specific build on specific version numbers on things being tagged there's a number of different ways to actually kick off one of these actions and then the jobs says we want to do a build I'm gonna run this on a container on the latest version of abouttwo and that's just the default for this sort of project there are different containers that you can be building on but this just says open up a container and allow me to do some things first in order to do this it's gonna give me a list of steps and each of these dashes represents a collapsible region as you're watching these so you're going to want these to sort of be in a row now the first one we're going to use is actually to go and get a checkout of all our code so we're inside of this container we're gonna check out all of our code and then we want to go ahead and add dotnet now in our case we may be dealing with a newer version of net I know that this meta web blog is actually using the - - version so we can leave it there but if we are dealing with 3-1 this is the version of.net not of the SDK so we could certainly do 301 here but I'm gonna leave it at 2 to 108 because that's when I'm actually using for a meta weblog no reason to upgrade it that way we can still maintain it with older projects that still need it and so this action setting up net core is using this action to set up net and add it and then finally we're saying build with dotnet and we're gonna tell it where to build it ok so let's start this commit for a minute actually I'm gonna do this in a different way I'm gonna open up a new tab with my code because I want to talk about that a little currently our build here is happening here in the root of our project but the thing I really need to build is in this source directory this is where the solution file is so that but my dotnet commands work and so what I'm going to want to add here before I run this and you can see we're getting some intellisense is working directory and this is a relative path in your project so we want to go to this working directory and then we want to go ahead and build and in this case build the release configuration then I'm gonna do the same thing with another named section I'm gonna say run tests what are we gonna do here we're gonna set that working directory again and I'm gonna run and this is just whatever being runs the command line and that is of course net test right that's really all we need to do to do a simple build and test what if you wanted something more and let's talk about that for a minute on one of my other projects in order to run the tests because I had some need for for NPM I actually needed to set up NPM or node really in this project as well and so how would I do that I'll start by just giving it a name here set up note and then inside here I want to actually do the setup of node right and the way we do this is we can actually go ahead and look in this marketplace for the different sorts of operations so you can see close stale issues set up that name for actions etc and I can actually just typing node here and we'll start to look for different recipes right and so let's say I want to install let's do set up node which will probably tell us help us and so there's a recipe for that and if we click on it it's not going to add it for us but they're just gonna show you what that looks like and so in our case we could actually copy this whole piece and we can see that it has a name this is uses the actions for the node so I'm gonna erase this in a minute but I want to use that action and then it has some options here what version by default it's 10 what registry and what scope which is kind of being cut off by Firefox for some reason but we don't need any of those in this case we're just saying execute this so that node by default 10x is installed on our machine that we're going to run because we might have in here another operation like npm install' now notice that a lot of these have name name name and those are fine but you can also just use run as a single line command here as well I'm gonna erase all this node stuff because this project doesn't use node at all but I want you to kind of get a sense of how you would add different kinds of projects a lot of this is copying what you see instead of trying to understand the syntax in some deep important level and and this is for me pretty crucial because I want it to be simple something I set up and I forget in many ways so let's go ahead and start that commit and say adding action and I'll commit it directly to the branch and if we go two actions here now that we have one we could start that new workflow if we want but we have this build and test action but it's not being run at all because we haven't actually started a build if we go back to the code well actually see that we now have because we committed it here in github that we have that build yamo here so how are we gonna actually do this let's go and edit our readme now I've noticed that this has been a bug for a long time that that wasn't actually showing thee this is what the old one looked like this is what the new one looked like right so I just want to make this tiny change well actually come back and change this a minute but more importantly this is going to set up a new commit a new push for us and of course if you have had actual code ready you could make a push from anywhere it certainly doesn't need to be at the website I'm just trying to get all the other tools out of the way and so we commit this change so we actually have a new version and over in actions will see that this build and test is being run let's click it while it's running and we can see it's trying to set up the job and then it does a setup of dotnet core and when it's done it's going to collapse this and show you the next one there's that net configuration that looks like it's doing its job and we got a build failed right so didn't even get to build the test we're actually failing to run the build and let's figure out why the current referenced assemblies were not found to resolve this install the SDK or targeting for the GAC and so the problem I have here is actually that the project itself is set up to run on top of the desktop SDK so let's see what that looks like if I try to fix that let's open up visual studio and open the project and an extra expect to do need to open the project this is a good example of what can go wrong because what essentially went wrong is we're trying to build this on a non Linux container we're trying to build it on a Linux container but we're not actually using that Linux container there's some code in here that's dependent on dotnet 4 6 1 which of course Linux will have so let's open up a project let's just where I keep all the projects and we'll see that same structure here in our code and if we look at the project settings you'll see this is just right but running on dotnet standard so that should be fine so it's probably actually the test project that isn't and here I have the target framework that's 4 6 1 instead of 1 that will run on a Linux framework so I'm actually going to make this change I'm gonna change this framework to net core to that core app 2 - could that be right let's build it here and see what happens if I miss label that it doesn't look like I did it succeeded now I must have mistyped it in some way and now if we go back over and I'll use the the get support individual studio to do this though it doesn't really matter how I do it we're not using DevOps here's those changes I'll go ahead and move test project to net core app to two instead of dotnet four six one I'll commit it I'll synch it successfully sync that because we just pushed this change if we come back over to our actions I should see a new build action has been started automatically and that's sort of the magic here of using actions now could have change this by trying to run on top of another container style let's see what it doesn't like err now there's some older changes with this and these are both with the tests of course so there are issues here let's see the package fall back oh yeah we don't need that anymore that was from an older version of the project of the the that weren't framework to be perfectly honest with you let's go ahead and look at the properties here and sometimes though in the package information they'll tell you if anything else is wrong you know that looks all good so let's make sure this builds locally I'm gonna do a rebuild just to make sure let's make one more check in isn't it nice when you don't remember everything that's supposed to be checked in and don't judge my commit messages because they are not good and let's come back to our actions and see what happens see if it's gotten any better usually when you're running these pretty commonly you'll see that some of these steps like setting up that not corn such ends up being a little faster because they've cache them let's see if this has gotten any better there's all the packages did you hate when you just watch things real-time I might speed this up when I edit it but probably not build worked running the tests starting test execution 8 tests 8 passed woohoo we're all good so anytime I make a change this will actually build new and you might have noticed that earlier I had a let's go back to the project I actually have an app there in here I'm gonna get rid of that app fair because I don't want not going to use that there anymore and I'm gonna add our existing item to my solution and that item of course is going to be github workflows and then there's my build right just in case I needed to edit it here I like to have it in the project but more importantly I'm gonna look at that readme and instead of the build status being this app very linked I'm gonna actually replace this with a new one I'm gonna see if I can remember this exactly but it's basically an image so in markup that's the image stack status and I'm gonna say build status is just the alt tag in case this doesn't show up and then let me see if I can remember how this goes it is github.com my name or my projects container if you want to think about it more than that than just your name and then this is meta web blog and then just like the container we saw here workflows and then unusually the name of the build and that if you remember that was build and test this is the not the name of the file this is the name that we gave it here in the build so it's this build and test that which needs to be the name and if there's spaces in your name you'll have to Earl encode it and that's just build SVG and if I've done it right that should unless I put the wrong name in here it's actually badge oh and it shows its passing because this building test is actually succeeding so go back and adding the github action badge admit it make sure everything saved because I changed that let's go over to sync it's gonna show you how cool and do it all at the command line but it's not as interesting anymore if we come back and refresh our page now that we have the new one will actually see no status and that's because it's currently running and there is usually a tiny lag between this actually running and the status updating but since you're not gonna be building every eight seconds and depending on the badge it should work fine for you I took 52 seconds last time orally in a few seconds let's see where it is it should still build and test because I really haven't changed any code so if we've refreshed that page says it's passing make sense that's how you set up CI using github actions and if you're interested I'll be putting a couple of badges here at the end of the video to go visit my Pluralsight courses or my personal courses I teach a lot of Microsoft technologies asp.net asp.net core gr PC s ado in my own teaching some view and some other courses a lot of them around view or bootstrap for etc feel free to visit my courses if you liked this video and give it a thumbs up if you'd like thanks again [Music]
Info
Channel: swildermuth
Views: 9,065
Rating: undefined out of 5
Keywords: github, actions, cicd, ci/cd, Programming, Webdevelopment, git
Id: nNw5H31nuU0
Channel Id: undefined
Length: 19min 40sec (1180 seconds)
Published: Mon Dec 16 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.