From the course: OpenAI API and MCP Development

Solution: Leveraging GitHub actions with AI models

From the course: OpenAI API and MCP Development

Solution: Leveraging GitHub actions with AI models

All right, so let's look at the solution of how to complete this workflow to make this workflow very interesting and also assisted with AI. And what we would like as a final project, as a final solution, is to be able to generate a document using the capabilities of the language models by calling the GitHub models within the workflow. As soon as this workflow is completed within our GitHub account, we're going to be able to see in our directory that there is a documentation which has been generated, which is very helpful, which has been done in just a few seconds. That could have been the job of a developer, a human developer. But instead, we're going to complete this job using the power and the capabilities of the language models. So let's see how we can do it. But for the purpose of this exercise, I'd like to actually add some jobs, which I think could be helpful in the day-to-day task. So for example, you could add one test job. So I'm gonna collapse them just so you can actually see the different steps. So you have the jobs first, and every new job that you add here will be indented. So it needs to be at the same level. So we're gonna use this exercise to also understand so how to define jobs, actions within your workflow. And this you're going to find in the corresponding exercise files in the corresponding chapter and video number, just so you know. So that's going to be the solution, which is going to be provided. So let's skip this one because this one is already added. We're going to add also this test example. I'm going to copy the final version, but of course I'm going to walk you through every line so we can understand what is the goal and the role of every test, of every job. And this one is to run some tests. So before that, we're going to make sure that we have tests added to our final version. Let me copy it. I'm going back to my example, GitHub actions, because remember that we run this locally first using our personal accounts. So you're going to add this test main.py, all right? Because we want to run some tests during the workflow process. Let's go back to the workflow file. And remember that we have one first job, which is to install all the dependencies. Then let's add a second job. So this is, oh, sorry, my bad. So this is not the right one. So let me go back, because this test main is already available. Let me go back to the actual workflow file. All right. So this part is done. Let's go back to the workflow, which is here that you find within GitHub and then workflow here. I want to copy this from line 33, all the way down to 59. Let's go back to the exercise. I'm going to close this file now, and let's go back to the workflow file and then add it at the right level. Here we go. So now you've got install. Let's close it. And now you've got tests. And the purpose of this job test that we name run Python tests is to run some Python tests, simply. So the recommendations for every project is to run some tests to check if the code is performing and working effectively as expected. So we run some tests before going to the next step, which is to check out or to ask for a review or to then push to production. This is one recommendation and good practice for every development job. So we're gonna run this using first here the same dependencies that we need to install first. We need also to use the secret keys and then to run some tests using this command. All right, so that's gonna be done automatically as soon as the previous job is completed. So this is specifying that it needs to complete the previous install job before running this new job test. All right, next we go to the interesting part, which is to add another job, which is to call an AI model. So again, let's go to our last example for the corresponding files. And we're going to find this one, which is generate docs. So as the name indicates, Generate GitHub Models Markdown, we want to use our file, so our project directory, to ask the GitHub models to generate a proper technical documentation written in Markdown syntax for us. So for the use of other developers, for example. So instead of doing it manually, so with the work and work hours of another developer, we're going to use AI to do it first, in seconds. So if there is any change in our project, it's going to be updated also in this documentation. Okay, very helpful. So we're going to copy this job, line 61, all the way down to 120. So this is a lot of lines, but I'm going to walk you through it again. Let's copy. And let's go back to our projects. All right, again, it needs to be at the same level. You can notice that we have install, test and generate docs. Okay, so let's read through this job now. So it needs to complete the previous job test before running this new job to generate documentations. So the first steps will be to check out to the repository. Then we want to call the GitHub models. We need to also export the secret key, then run here this line, which is to create a new docs. So the directory will be created in our repository. Then we define the actual API requests with the credentials, specifying which models to call. Then we ask the question. So let's read it. So first we provide with the system message, line 84, to tell the language models to act as a technical writer and to output the documentation in Markdown syntax only. Then the user will give instructions to write a README style Markdown document explaining GitHub models, what it is, how to use it with GitHub Actions, et cetera. Then we're gonna echo the response, but also allow to assign, so let me check. Yeah, so that's gonna actually generate this documentation in the docs. All right, using this results because every time that there is an output, it's gonna be available within content. Next, we have another step within this job, which is to update the readme. So that is very interesting because we already have an existing readme in our projects. Let's look at it. So this is one that I have written myself manually. So I had to make sure that everything was complete enough and It's sufficient to give enough instructions to any type of user. But here, with the help of AI, we're going to ask to complete this README by adding this information about GitHub models. So that's going to be completed here as well in this step, which is line 97. Next we also commit. We allow to make another commit actually within the repository. So that's going to be done using our username and e-mail. And finally we're going to push and then we're going to generate the documentation that we're going to be able to then find in our repository and then read it. Let's try that. We're going to add and make another commit after editing this workflow. And I'm going to say edit workflow with two new jobs. And after pushing this new commit, let's keep an eye on the dashboard. So as soon as we push, we're going to see a new job, a new workflow run, which is being executed. So let's go back. I'm going to push. And in the case, you've got that, because I think I had a few changes remotely. So we're just going to push. It doesn't matter if we override. So that's going to be getPushForceWithLists in that case, specific case. But that can be different on your end. That's going to be with lists. All right. So in that case, let me go back. I'm going to pull first because I had some changes remotely and then I'm going to push again. Okay. Here we go. All right, now it works. Let's go back and then I'm going to refresh And we're going to see that now we have a new job, which is up and running. And everything is going to go in sequence because for every step we had, we have made sure that we required the previous step to complete. So it's going to start with installation of the dependencies first. Then this part is complete. Like we can actually check out, I think. Yeah, that's complete now. Let's go back to see the rest. Okay, it's running some Python tests. Now let's go to the last step, which is to ask to call the AI model. It's gonna create a new directory, which is docs. Great. All right, this is updating the README as well. It's going very fast and now it is complete. So if we go back now, you can see the green check marks. So this means that now this workflow is successful. And if you go back to the code, you're gonna notice that now you have this directory. All right, and we can check out the response. First, you have a JSON response. So we want something which is more user-friendly. So let's go back to the Markdown file. And now you can see that you have this nice documentation which has been generated by AI after calling the AI model within the GitHub Actions, which is super interesting and helpful. And on top of that, so it's gonna tell you, explain to you how you can define API calls within your workflow, but also how to write permissions. So everything that you need to know, every step necessary to complete that. I mean, to be successful in that task. And if we go back to the main page, you're going to see that you also have an update for the README because that was part of this last job. There was one step that was allowing to also update the README file. Excellent. And that's going to be all the way at the bottom. Here we go. Step five, integrating GitHub models. And this is not something that I've done myself. it was actually generated by AI.

Contents