Write your first GitHub action - Part 1

Posted by Anuraj on Monday, August 19, 2019 Reading time :1 minute

CI GitHub Actions ASPNET Core

GitHub Actions makes it easy to automate all your software workflows. GitHub actions is still in Beta and it is free for Open source projects. This post is writing your first GitHub action for implementing continuous integration for a dotnet core application. Similar to Azure DevOps or Travis CI, it is also supports YAML scripts to implement automation.

To get started, open your GitHub repository, select Actions Tab. If you never created an action before it will show a get started screen. Based on the repository code type it will suggest a workflow.

GitHub Actions - New Action

Since I am building CI for dotnet core application, you can scroll down and you will be able to find ASP.NET Core workflow.

GitHub Actions - ASPNET Core Workflow

Click on the Set up this workflow button, which will create aspnetcore.yml file inside workflows folder under .github folder.

GitHub Actions - ASPNET Core Workflow - Yaml file.

The project I am enabling CI contains unit tests, so I am including a step for unit tests as well. So here is the final yaml file.

name: dotnet core - build

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 2.2.108
    - name: Build with dotnet
      run: dotnet build --configuration Release
    - name: Unit Tests
      run: dotnet test

I just added one step, Running Unit tests step and dotnet test command to run. Next when I am committing the file, it will trigger the build and run the tests.

GitHub Actions - List of workflows.

You will be able to find the details about the steps and debug information on clicking on the workflow name. You will get something like this.

dotnet build workflow details.

In this post we created a basic dotnet core workflow using GitHub Actions - which helps to build a dotnet core project and run unit tests. It is still in beta and may improve the features. In the next part we will look into deploying the application to Azure.

Happy Programming :)

What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.


Similar Posts


Did you like this article? Share it with your friends

Facebook Twitter Google+ LinkedIn Reddit StumbleUpon



Translate
Subscribe
BMC logoBuy me a coffee


Copyright © 2019 - Anuraj P. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Hosted with ❤ by GitHub