Automatic releases with GitHub action and Semantic Releases

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:

  1. Build and Publish (.NET Project):
    • Use the dotnet build and dotnet publish commands.
    • Set the output directory for the build artifact using the --output package option.
  2. Optional: Upload Build Artifact:
    • This step involves uploading the generated build artifact to the current workflow action or build.
  3. Setup Node.js:
    • Since Semantic-Release is a Node.js package, ensure that the latest Node.js version is installed in this step.
  4. 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.
  5. **Install semantic release on workflow run **:
    • First, install the semantic-release package with npm install --save-dev semantic-release.
    • Compress the additional build artifact (from the .NET project) that you want to upload to the release.
  6. 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 path package/package.zip is specified for release upload.
  7. 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.

References

  1. https://github.com/semantic-release/semantic-release