Github
Github provides a lot of functionality out of the box for a small fee. It is true that choosing other providers might offer additional functionality, but this mostly comes at a price. As an enterprise the decision really depends on the added value of the functionality. This mostly boils down to reporting, visualization and ease of use. In beginning projects I would advocate to use Github and the functionality it offers to the fullest.
Github Actions
Github actions allow us to automate a lot of things, that would otherwise require more expensive tools. The trade of is, that it is not a point and click interface. The advantage is, that it is widely used and therefor a lot of documentation can be found online. Github actions allow us to build and deploy our application automatically after changes are pushed to a branch.
NuGet Registry
GithubNuGet registryTo automatically create a NuGet package from code, all we need to do is create a file .github/forkflows/release.yaml
from the root of our project.
|
|
Versioning is not done automatically. You need to manually set your version in the project file in your solution. The build will not fail, it will not push the new version when it already exists on the NuGet registry.
Optional: Remove the parameter --skip-duplicate
from the Publish NuGet package
command.
Explaining the code:
- line 5: Script will run when changes are pushed to the
main
branch - line 9: Sets the nuget directory for the build, this will not influence your build.
- line 23: This example depends on
dotnet 7.0.x
, wherex
is a wildcard to get the most recent version. - line 32: Runs the build with the
release
option enabled. - line 99: The option
--skip-duplicate
is used to prevent failure when the version already exists. Remove this if you want the build to fail on duplicate versions.
Before uploading this, make sure to create the secrets in your github account.
- NUGET_STORE_API_KEY: Your api key with access to the NuGet registry
- NUGET_STORE: Url to your NuGet registry
Docker container registry
GithubDocker registryWe can create docker containers and deploy them to the Github container registry easily.
You can easily deploy your containers from Github actions. Personally I prefer Gitops where we just create the container. Another service will pick it up and will deploy it.
|
|
Explaining the code
- line 6 -> 7: sets up release management based on branching
- line 10 -> 14: Environment variables needed for the build
Setting the above variables is enough to build the project. This script was used for deploying a dotnet core application. It uses GitVersion to automatically determine the version numbers upon every build. The method here is only compatible with dotnet core. For more information for other software check out: https://gitversion.net/docs/
Jobs
- Version: determines the version number using GitVersion
- Build: Builds the docker container using the Dockerfile and pushes the image to the container registry
- Release: Creates a release using Semantic Versioning
You will be able to see the result in your repository