Automated versioning and package publishing using GitHub Actions
December 02, 2022 by Anuraj
Docker NuGet Github DevOps DotNet
This post is about implementing versioning and publishing docker images and nuget packages using GitHub Actions. I am not explaining about semantic versioning. There is already a lot of content explaining about these things.
First I am exploring how to implement versioning in Docker Containers. For this purpose I am using the .NET 7.0 dotnet CLI publish as container feature. For my docker images I am using a date based versions or Calendar Versioning. If I am not wrong Ubuntu is using similar versioning strategy. To implement this I am using a ubuntu based GitHub action and here is the code.
In this code I am setting a environment variable BUILD_VERSION
using the date
command in the set release date
step. And in the CSProj file I am using it like this.
The ContainerImageName
tag sets only if it is running on GitHub actions. And when building it locally - the BUILD_VERSION
environment variable is not set or empty, I am using the latest
tag. Here is the GitHub Action execution.
This code is used in one of my GitHub project.
Next we will look into implementing simple semantic versioning. I am using this for publishing nuget package. Here is the Powershell script.
The Setting up build version
task helps us to BUILD_VERSION
environment variable. This version value is updated using the predefined environment variable - GITHUB_RUN_NUMBER
and similar to the earlier implementation, we need to modify the CSProj file with the Version
element.
If the BUILD_VERSION
environment variable is not set or empty, it will use the version 1.0.0
. And once the code committed and when github action runs - the GITHUB_RUN_NUMBER
number will be increased with 1. This value will be replaced in the version
powershell variable and set to the environment - which will be used in the project.
This way we can enable versioning nuget packages and docker images using GitHub actions. We can use different GitHub Action tasks as well for implementing versioning. But in this example, I am using any other github action steps.
Happy Programming.
Copyright © 2024 Anuraj. 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. Powered by Jekyll. Hosted with ❤ by GitHub