Post

A day on github action

Today, when I explore my github account, I see many projects I created in the past during my spare time using .NET. There are some projects I’m still hoping I could complete them one day, however due to the complexity of those project setup, it takes much longer to resume the development and publish beta version whenever I have spare time.

Luckily, GitHub offers free CI/CD platform - GitHub Actions that lets me easily automate the build, test and deployment pipeline. In addtion, it offers free package management platform - GitHub Packages that allows me to host and manage my projects’ packages in private. These two platform combined together provides most I need for all my projects, so I decide to take a day tuor among these two platforms and hopefully I could get something working at the end.

Usually when I start something new in a short time, my first thing is to write down a list of puzzles/chanllenges I might be enocuntered and do a quick search on the web to get some clarity

Chanllenges

Github Actions

How and where to start the intial setup?

GitHub actions is pretty simple to start, it has a starter kit template for various of projects. As soon as you have your project hosted on github, you can start by clicking on “Actions” from menu and pick up the workflow template suitable for your project type. I choose .NET from Continous integration section as start.

How much free time do I have before I get charged?

From my understanding,for GitHub free account, you won’t be charged for public repositories. For private repositories, there are certain amount of free minutes for hosted runner (aka build engine consumption) and storage listed below.

About billing for GitHub Actions

Where can I find succinct documents (no more than 2-3)?

I personally find docs below are very helpful for me to get the CI/CD up running and publish the packages to GitHub Packages

Github Packages

How can I upload the packages?

You can find more details from Working with the NuGet registry.

If you ever work with other package management platform in .NET, you probably only need to know the following two commands

Add source server and authenticate to GitHub Packages

1
dotnet nuget add source --username USERNAME --password $ --store-password-in-clear-text --name github "https://nuget.pkg.github.com/NAMESPACE/index.json"

USERNAME is the name of your personal account on GitHub.

GITHUB_TOKEN is a authenticate token GitHub recommends to use for access and publish packages associated with the workflow repository.

NAMESPACE is the name of the personal account or organization to which your packages are scoped.

If you run above command to add GitHub Packages source from your machine, you need to use Personal Access Token as password

Publish package

1
dotnet nuget push "bin/Release/PROJECT_NAME.1.0.0.nupkg"  --api-key YOUR_GITHUB_PAT --source "github"

YOUR_GITHUB_PAT is your personal access token.

If you have already configured authentication in Add source server and authenticate to GitHub Packages, you don’t have to supply --api-key

How can I access the packages?

You can find more details from Installing a package

Where to find the packages from UI?

You can find more details from Viewing a repository’s packages

Are there any limitations in free version?

Yes, GitHub offers 500 MB storage per repository if I understand correctly. The storage used by a repository is the total storage used by GitHub Actions artifacts and GitHub Packages.

About billing for GitHub Actions

Put everything in action

It’s time to put everyhing in action as all above chanllenges have been resolved.

Here is what I would like to experiment with GitHub Actions and Packages

  1. Build the solution when code changes are made in main branch
  2. Create nuget package and upload to GitHub Packages when I create release from GitHub repository and associate package version with release name.

Flowchat

The YAML

Click to expand

The YAML with reusable actions (cleaner)

Click to expand

Outcome

Reference

Happy Coding! 😇

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.

© Vincent. Some rights reserved.