Using GitHub Copilot for GitHub Actions¶
GitHub Copilot can be a valuable tool when creating GitHub Actions. It can provide suggestions and insights that might help you create effective and efficient workflows.
Creating a Simple GitHub Actions Workflow with Copilot¶
Objective¶
In this exercise, we will use Copilot to create a GitHub Actions workflow that builds a Docker image when there is a push or pull request.
Steps¶
- Open the
.github/workflows/
directory in your repository where GitHub Actions workflows are stored. - Create a new file for your workflow, e.g.,
build.yml
. - Start typing the structure of a GitHub Actions workflow. For example, you might start with:
name: Build and Test on:
- As you type, GitHub Copilot will start suggesting completions. For example, after typing
on:
, it might suggest triggers for your workflow likepush:
orpull_request:
. - For this exercise let's create a workflow that runs on every push to the
main
branch and builds our ui. Let's ask Copilot something like:Create a GitHub Actions workflow to build a Docker image when there is a push to main?
- Review the suggestions from Copilot and copy the code to your
build.yml
file. - Commit the changes to your repository. On the next
push:
you can navigate to the Actions tab in your repository to see the workflow in action.
Add a Test Job to the Workflow¶
Objective¶
In this step, we will add a test job to the GitHub Actions workflow that runs tests after the Docker image is built. This will show how easy it is to extend the workflow with Copilot.
Steps¶
- Open the
build.yml
file in your repository. - In the
jobs:
section of the workflow, add a new job for running tests. For example:test:
- Use
CMD
+i
to trigger Copilot and ask for a suggestion for a test job. For example:Add a job to run tests after the Docker image is built
- Review the suggestions from Copilot and if everything looks good, push up the changes to your repository. If this is your first time pushing changes after submitting the last changes, you will see the new workflow in the Actions tab.
Conclusion¶
In this exercise, we used Copilot to create a GitHub Actions workflow that builds a Docker image and runs tests when there is a push or pull request. This is just one example of how Copilot can help you create effective and efficient workflows with GitHub Actions.