As part of our transition from Azure DevOps (ADO) to GitHub, we’re focusing on automating the remaining parts of our workflow. One key area is the automatic creation of GitHub releases using GitHub Actions and the Semantic Release package.
Semantic Release is a highly flexible tool that follow semantic versioning, but it’s primarily geared towards frontend projects, often requiring a package.json file. Additionally, it lacks preconfigured GitHub tasks from official sources, though third-party options are available and describes in various online guides. To minimize dependencies on third-party tools, I’ve developed a few techniques to avoid committing frontend-specific files directly to the repository.
In this article, I’ll walk you through an example pipeline for building and publishing GitHub release for a .NET project using these techniques.
Here’s a refactored version of the provided steps:
- Build and Publish (.NET Project):
- Use the
dotnet build
anddotnet publish
commands. - Set the output directory for the build artifact using the
--output package
option.
- Use the
- Optional: Upload Build Artifact:
- This step involves uploading the generated build artifact to the current workflow action or build.
- Setup Node.js:
- Since Semantic-Release is a Node.js package, ensure that the latest Node.js version is installed in this step.
- Configure Authentication Tokens:
- For private repositories, use a PAT (Personal Access Token) set as the
GH_TOKEN
. - For public repositories, use the
GITHUB_TOKEN
. - Refer to the official Semantic-Release CI Configuration for details.
- These tokens are sensitive and should be added as secrets in your repository.
- Ensure the PAT token has read/write access to the repository to avoid pipeline errors.
- For private repositories, use a PAT (Personal Access Token) set as the
- **Install semantic release on workflow run **:
- First, install the
semantic-release
package withnpm install --save-dev semantic-release
. - Compress the additional build artifact (from the .NET project) that you want to upload to the release.
- First, install the
- Create
.releaserc.json
Configuration:- Use an
echo
command to generate the.releaserc.json
file with all necessary plugins and configurations. - In particular, check the assets section in the
@semantic-release/github
plugin, where the build artifact pathpackage/package.zip
is specified for release upload.
- Use an
- Run Semantic-Release:
- Finally, use
npx semantic-release
to create the actual release, which includes both the source code and the additional build artifact package.
- Finally, use