DEV Community

Cover image for GitHub Actions
Emily
Emily

Posted on • Updated on

GitHub Actions

Introduction

What is GitHub Action? According to Github, it is a series of commands that can be executed when a special event (defined by user) occurred. The series of commands is put in the context of workflow and every steps can be seen as a job.
This week, I had a chance to explore GitHub Actions for my Shinny-SSG project and it is a great improvement for my application.

Define Workflows

I created my first workflow by using Github's default workflow template for .Net project. Github created a YAML file in the .github/workflows directory inside my git repository. You can read more about it here.
My dotnet.yml file :

name: .NET

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core 3.1 
      uses: actions/setup-dotnet@v1 
      with: 
       dotnet-version: 3.1.x
    - name: Setup .NET Core 5.0
      uses: actions/setup-dotnet@v1
      with:
       dotnet-version: 5.0.x
    - name: dotnet-format
      run: dotnet tool install -g dotnet-format --version 5.1.225507
    - name: Restore dependencies
      run: dotnet restore shinny-ssg/shinny-ssg.sln
    - name: Build
      run: dotnet build shinny-ssg/shinny-ssg.sln --no-restore 
    - name: Test
      run: dotnet test shinny-ssgTests --no-build --verbosity normal
Enter fullscreen mode Exit fullscreen mode

Testing

Later, I tested my Github Actions by making a pull request to my origin repository. It worked like a charm and it denied merging if my PR did not pass the test.
Image description

I also made a PR for my classmate's project. It also worked as expected.

Discussion (0)