Github Actions CI/CD - Everything you need to know to get started

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Hey Python Developers!

I made a video tutorial for Github Actions (CI/CD) and a tutorial on how to set up a linter.

CI/CD Automation is becoming more and more important in the industry, as Python programmers it's important that we implement CI/CD when we can.

This tutorial is designed to take you through the very basics, but there are a lot more things you can do to automate testing, packaging, and deployment of your code!

Let me know what you think, any feedback is appreciated! Thank you!

My code from the video tutorial:

https://github.com/bradmorg/mygitactions

Github Actions official Page to learn more:

https://docs.github.com/en/actions/learn-github-actions/introduction-to-github-actions

👍︎︎ 8 👤︎︎ u/DevOps-Journey 📅︎︎ Mar 12 2021 🗫︎ replies

This is great very simple and intuitive thanks!

I'd love to see how testing works with github actions.

👍︎︎ 1 👤︎︎ u/notParticularlyAnony 📅︎︎ Mar 13 2021 🗫︎ replies

Any similar walkthroughs for gitlab?

👍︎︎ 1 👤︎︎ u/skibizkit 📅︎︎ Mar 13 2021 🗫︎ replies
Captions
in today's fast-paced environment it's absolutely essential that we can automate the testing and delivery of our code that's where github actions comes in it's the built-in ci cd tool for github if you're unfamiliar with what ci cd is it stands for continuous integration and continuous delivery essentially it allows us to automate the testing of our code to make sure it meets certain criteria after all the tests are passed you can enable actions to automate the delivery of your code this can significantly reduce the time it takes for you to deliver updates to your application which allows developers to focus more of their time on the code itself in this video i'm going to go over all the theory you need to know to understand the github action workflow in the lab portion of this video we'll go over how to implement our own github action and implement a linter that will run checks against our code to make sure that it meets specific criteria so to start us off let's go over the terminology you need to know to understand a github actions workflow file so we have a workflow yaml file which specifies events jobs runners steps and actions so an event is a trigger for a workflow a common event that occurs in a repository is when someone pushes new code you can see that in this configuration file we specify the workflow to trigger when someone pushes new code when the event occurs it's going to run all the jobs within the workflow in this workflow we have a single job named superlint that specify multiple steps and actions you can see underneath the steps there's two actions that are being run first it's going to check out our code and then it's going to run the super linter against it up here you can see the runs on parameter and this is where we specify our runner basically this is a container environment that will run our code by default github runs this container for you but you can host your own runner if you'd like to the default containers to choose from are ubuntu linux microsoft windows and mac os so to put it all together on the event that someone pushes new code it's going to run the job super lint that job is going to run on ubuntu container hosted on github.com and then it's going to go through two steps the first step is to check out the code and the next step is to run the linter by the way if you don't know what a linter is it's just something that we use to check to make sure that our code is conforming to certain standards super linter is made up of multiple linters so it doesn't matter which code you use in your repository superlinter is going to understand it and make sure you conform to the standards of that language all right so let's hop into github now and i'll show you everything you need to know to get this working okay so we're on github.com and what we want to do is create a new repository so let's go repositories and then click new and then we can call this whatever we want so i'll call it my get actions and then scroll down and let's add a readme file just we have a file to work with and then create repository so we got this nice clean github repository with the readme file in it the next thing we want to do is create a workflow so to do that just go add file and create new file and then we need to be very specific with our naming here so the proper directory structure for your workflow files needs to be first dot github slash workflows and then you can name your file whatever you want so i'll go superlinter.yaml and then i'm going to copy and paste the code and you can see this is the code that we went over earlier in the video basically it's listening for a push event and when the push event happens it's going to first check out our code and then run the superlinter against it to make sure that it conforms to the linting standards so we can go ahead and commit this now and you can create a new branch or just commit to the main branch i'm going to commit to the main branch here and that's it and again just want to stress that this directory structure needs to be exactly like this if your workflow is not triggering it's probably because the directory structure isn't named correctly so let's hop on back to the main repository here so i'll click code and you should notice that there's this little status icon now and you can see it's yellow basically what this is saying is it's currently running the workflow and checking the code if all the checks pass then this is going to turn green if the checks fail then it's gonna turn red so you can actually click on this or you can click on this actions tab so i'll click on the actions tab and you can see that it's running the workflow now and the workflow that it's running is super linter and if we click here you can see that it is linting the code base let's open this up and you can see the exact process that it's on and just open this up you can see setting up the job basically just doing the github action stuff setting everything up and now it is pulling the code from github superlinter once it's done that it's going to check out our code which is our repository and then it's going to run the superlinter against it so this is pretty cool it's telling you behind the scenes which code repository it pulled from if you actually went to this url you could see the actual code of the super linter job anyways okay so getting lots of updates here so the poll worked it checked out our code fine you can see yeah syncing repository my github actions and now it's running the super linter against it and yep super linter worked and this is the logs it looks like everything passed there wasn't a lot of code in our repository so yeah passing a linting check isn't too big of a deal if we head on back to code here we can see we get a nice little check mark to show that all the workflow checks have passed so this is another really cool thing that you can actually use downstream you could have your servers monitor the github api and just check the status of the repository if the status was a green check mark it could automatically go to that repository and pull down your code and you know implement it into staging or production or whatever you want but before we get too into that let's go ahead and push some code that we know is going to generate some linting errors so i'm going to grab some code here and i'm going to go add file create new file and i'm going to paste this in and let's give this a name so i'll just call it main.pi this is some really simple python code if you're not familiar with python that's okay but there's some syntax problems with this code that is not going to pass the linting check um the first example is there should actually be two lines between each function and uh i think i used a tab here and then i just used like two spaces here so the code style isn't very consistent this is what's considered messy code and the linter is not gonna like it it's gonna fail it and you know if i was the developer pushing it i would know that my code doesn't look good it doesn't pass the linter and i would make the fixes and then re-push it so let's go ahead and save this commit it and watch to see what the linter does so scroll to the bottom and just commit new file and let's refresh here and we can see that it is triggered now if we just click here one in progress check and we can just go details and it brings us here so i'm not going to make you sit through this i will uh speed up the video and we'll check to see the errors okay so our super linter has run and we can see that there is an error in our workflow right here on the run super linter so let's go into it and i'll show you sort of how to troubleshoot these errors it's a little bit difficult when you're first getting started but if you read the errors they sort of make sense go down here you see info info info and then errors found air in black linter and it's just saying the file is main.pi so we know that the file that has issues is main.pi this is very relevant if you're pushing to a repository that you know has hundreds of files in it you want to get the file name here so here here's basically the code and the pluses are the lines that it would add and the minuses are the lines it would remove so it's basically saying add an additional line here take out this line and then replace it with this one that has four spaces and then add an additional line below so let's go ahead and do that i will head on over to the code go to main dot pi and edit this so it said add an additional space here so this is just basic pep 8 formatting and and i can see it's adding white space so let's remove that because the linter won't like that and then let's remove this and then do four spaces just to make everything consistent and then it wanted an additional line here and again for some reason the online github editing tool is adding a bunch of white space uh so this looks good this should pass i hope so let's commit the changes we're gonna go ahead and let this run and i'll pause the recording and resume once our linter comes back with either a pass or fail okay so just refreshed and we can see that everything passed if i hop back in here we can go to the details of the latest job and you can see that the super linter ran and everything looks good so let's just explore the github actions a little bit more we'll go up here to actions and you can see that we have a history of all our workflow jobs so this one was our first run before we added the python file with the bad formatting and this was the second run with the bad file and then after we make the fix over on this side you can see you can sort of filter by specific workflows so you could have a bunch of different workflows in the same github repository you're not limited to just like a single workflow or anything like that if you wanted to filter you just click here and that automatically fills out the filter now if you wanted to go through a guided setup instead of just writing your file from scratch like we did you can go new workflow right here and you can see that there's a lot of templated options so for this one it looks like it just repackages up your code and pushes it to pie pie a bunch of other stuff here and i noticed this page is super laggy maybe it's just my browser but i think it's just the finicky github actions thing but basically what i'm trying to say is there's a marketplace with a lot of canned workflows that you can just grab and then you can just modify the file to meet your needs so that's a really good option if you're just starting out and you're just exploring just have a look at the marketplace grab what you think would be good and then just sort of customize it as you go along so anyways that's all i wanted to do for this github actions introduction i hope you enjoyed the video if you did please go ahead and hit that like button for me to get this information out to other devops engineers that need it and if you're interested in learning more about devops programming or just it in general go ahead and subscribe to my channel thanks so much for watching and i hope to see you all in the next video
Info
Channel: DevOps Journey
Views: 20,803
Rating: 4.9706745 out of 5
Keywords: github actions, github actions example, github actions tutorial, github actions workflow, open source, software development, continuous delivery, ci cd, github ci, github actions ci/cd, open source intelligence
Id: mFFXuXjVgkU
Channel Id: undefined
Length: 12min 21sec (741 seconds)
Published: Fri Mar 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.