How to Build a Solution with GitHub Actions

21 augustus 2020 om 14:00 by ParTech Media - Post a comment

Finally, GitHub followed the footsteps of GitLab and introduced GitHub Actions to their repertoire. From code hosting to project management, you have everything served in one platter.

Introducing GitHub Actions

GitHub Actions automates the software development process under the same roof where code and pull requests and issues have collaborated. Developers can write individual tasks referred to as Actions and amalgamate them to create a custom workflow. Further, workflows are narrated as a custom automated process that helps you in setting up a repository to build, package, release, test, and deploy code project on GitHub.

Using GitHub Actions, you can develop an end to end continuous integration (CI) and continuous deployment (CD) capabilities directly in your repository. GitHub workflow can actively run in Linux, Windows, macOS, and on GitHub hosted machines. You can smoothly discover Actions suiting your workflow on GitHub and quickly build Actions to share with trusted GitHub community.

How to Build a Solution with GitHub Actions?

To play with the GitHub Actions, we are going to build a small web application to test the waters first. For building a basic solution using .NET Core deployment, the following steps are required:

  • Create a new GitHub repository
  • Clone it on local files
  • Shift to the new directory
  • Run dotnet new webapp
  • Update the .gitignore file
  • Implement the first draft of codes
  • Enter into the remote on GitHub

Working with GitHub Actions

Today, GitHub Actions is free for public repositories. For private repositories, each account holder receives a fixed amount of free minutes and storage depending on the product used with the account. When logged in GitHub tap over Actions on a repository, and you will be proposed a starter YAML file as per your codes available in the repo. There, your e.g. .NET Core code will be found. There are plenty of Actions already available regardless of your stack. The YAML file created by you is a set of actions, and that’s why called a workflow.

Setting Up .NET Core

You can pick the .NET Core project from the suggested setup if it matches your project deployment. However, there are a series of steps present to set up the Action Runner with the tooling as per your .NET Core project. Once you have created the setup, you have to start a build with the dotnet command.

Once the YAML file is saved to your repository and run is kicked off, it will trigger workflow on: push. Now, you can see the commit ID associated with the push along with the branch and account that pushed the change.

Let’s Run

When you first ran your command and greeted with an error, don’t panic. It is a good sign that you have been clearly stated with what’s wrong and where you have made mistakes. So, you should carefully understand the errors and try to fix it with your coding skills.

Source: https://rajbos.github.io/blog/2019/10/26/Deploy-dotnetcore-webapp-with-GitHub-Actions)

In the first run, you might observe a couple of things about GitHub; it won’t automatically show new runs on pushes. You can’t go back to the list of runs to check previous runs; however, you can click on the Actions tab to start your workflow from the top-level overview. It means you run multiple workflows in the same repository, which is very useful. Plus, the user interface is stunning to work.

Publishing

Once you have created your basic web app using .NET Core, you have to next use an Azure App Service to create a new App Service plan. There’s complete documentation on using GitHub Actions available so you can start by reading it. The instructions are pretty clear to run a docker container on the App Service, JavaScript, Python, or Java; it will also work for .NET Core.

Source: https://rajbos.github.io/blog/2019/10/26/Deploy-dotnetcore-webapp-with-GitHub-Actions

To create your repo, you have to download the App Service, publish profile and store it on a GitHub Secret. You have to create a secret name here, which might take a few minutes because GitHub takes dash or underscore in your name very seriously and keep on showing errors unless you set the right name.

Now, you have to add this step in the YAML file, which might be going to take a few trials. It’s because GitHub Actions technology is moving so fast that new Actions are added every other day. Thus, you have to scroll through a wide range of repositories to find a suitable example of YAML files. After a couple of failed attempts to email messages from GitHub, you are ready to launch your web application.

Complete Syntax

Now, you have to check the complete running syntax that somehow looks like this

name: .NET Core

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: 3.0.100
    
    # dotnet build and publish
    - name: Build with dotnet
      run: dotnet build --configuration Release
    - name: dotnet publish
      run: |
        dotnet publish -c Release -o dotnetcorewebapp 
    - name: 'Run Azure webapp deploy action using publish profile credentials'
      uses: azure/webapps-deploy@v1
      with: 
        app-name: dotnetcorewebapp19 # Replace with your app name
        publish-profile: $ # Define secret variable in repository settings as per action documentation
        package: './dotnetcorewebapp' 

Source: https://rajbos.github.io/blog/2019/10/26/Deploy-dotnetcore-webapp-with-GitHub-Actions

Now, you can browse your website online and check whether it’s running or not.

Parting Thoughts

GitHub Actions is a quite promising platform. The workflows are interesting and easy to understand. Open source actions, easy availability, and swiftly developing platforms are a couple of GitHub Actions traits. This one platform contains all the components to run a successful application. Moreover, the product is still developing with lots of new actions every other day. Once the platform reaches its optimum maturity level, you should expect better documentation, patterns, and a bigger audience. So, GitHub Actions might be the next big thing!

Nieuwste