Skip to content

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

  1. Open the .github/workflows/ directory in your repository where GitHub Actions workflows are stored.
  2. Create a new file for your workflow, e.g., build.yml.
  3. Start typing the structure of a GitHub Actions workflow. For example, you might start with:
    name: Build and Test
    on:
    
  4. As you type, GitHub Copilot will start suggesting completions. For example, after typing on:, it might suggest triggers for your workflow like push: or pull_request:.
  5. 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?
    
  6. Review the suggestions from Copilot and copy the code to your build.yml file.
  7. 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

  1. Open the build.yml file in your repository.
  2. In the jobs: section of the workflow, add a new job for running tests. For example:
    test:
    
  3. 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
    
  4. 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.