DEV Community

Shashank Mishra
Shashank Mishra

Posted on

2 1 1 1 1

Part 3 : Initialize and configure semantic release with releaserc

In this part, I’ll walk you through initializing and configuring semantic release using .releaserc configuration file. This will help in analyzing your Git commit history and following the Conventional Commits specification, it determines the next semantic version (major, minor, or patch) for your project. It also generates release notes, publishes the package, and creates Git tags automatically.

By the end of this guide, you’ll have a fully functioning semantic release workflow that will also create a variable in your azure pipeline for holding the value next release version based on commit message history.

Step 1: Install semantic-release and required Plugins

1.a Install semantic-release and semantic-release plugins as a dev dependency:
npm install --save-dev semantic-release

npm install --save-dev @semantic-release/changelog @semantic-release/git @semantic-release/release-notes-generator @semantic-release/github semantic-release-ado

1.b Create a .releaserc file in your project’s root directory
Here’s an example configuration:

{
  "branches": [
    {
      "name": "main",
      "prerelease": false
    }
  ],
  "plugins": [
    [
      "@semantic-release/commit-analyzer",
      {
        "preset": "conventionalcommits"
      }
    ],
    [
      "@semantic-release/release-notes-generator",
      {
        "preset": "conventionalcommits"
      }
    ],
    [
      "@semantic-release/changelog",
      {
        "changelogFile": "docs/CHANGELOG.md"
      }
    ],
    [
      "@semantic-release/git",
      {
        "assets": [
          "dist/**/*.{js,css}",
          "docs",
          "package.json"
        ],
        "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
      }
    ],
    "@semantic-release/github",
    "semantic-release-ado"
  ]
}

Enter fullscreen mode Exit fullscreen mode

1.c Add Semantic Release Script
Add a script to your package.json:
"release:semantic-release": "npx semantic-release"

Summary of Plugin Functions

  • @semantic-release/commit-analyzer: Analyzes commit messages to determine the next version (major, minor, patch).
  • @semantic-release/release-notes-generator: Generates release notes based on commits.
  • @semantic-release/changelog: Updates the CHANGELOG.md file.
  • @semantic-release/github: Creates a GitHub release with changelogs and assets.
  • @semantic-release/git: Commits updated files (like CHANGELOG.md and package.json).
  • @semantic-release-ado: Generates version number that will be stored on a variable available to downstream steps on the job. By default this variable is named nextRelease, but the name can be configured in the plugin options. Read more

Conclusion

By following these steps, you’ve successfully configured sementic release in order to determine the next semantic version (major, minor, or patch) for your project. It also generates release notes, publishes the package, and creates Git tags automatically.

Stay tuned for more guides to help you optimize your pipelines and development practices. Happy coding! 🚀

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay