# Automate Versioning and CHANGELOG Generation

# Overview

Assume we have a service/app repository. We want to automate the versioning and CHANGELOG generation. How to achieve this? In this article, I will explain how to automate versioning and CHANGELOG generation using `commit-and-tag-version`.

# Prerequisites

* commit-and-tag-version
    
* Git Repository
    

# How to

## Installing `commit-and-tag-version`

```bash
npm i -g commit-and-tag-version
```

## Preparing Configuration files

assume you already have git repository

1. Create configuration file `.versionrc`
    
2. Create `version.json` file.
    
3. Run first release
    
4. Test create commit
    
5. Run release
    

example file `.versionrc` and `version.json`

```json
// .versionrc
{
  "packageFiles": [
    {
      "filename": "version.json",
      "type": "json"
    }
  ],
  "bumpFiles": [
    {
      "filename": "version.json",
      "type": "json"
    }
  ]
}
```

```json
// version.json
{
    "version": "1.0.0"
}
```

## Run First Release

```bash
commit-and-tag-version --first-release
```

## Test Create Commit

You can add a new file and then commit or create an empty commit. To create empty commit, you can follow this example command

```bash
git commit --allow-empty -m "feat: add feature A"
```

## Run Release

```bash
commit-and-tag-version
```

After you run first release, you can see `CHANGELOG.md` file is created and `version.json` file is update.

If you want to read more about `commit-and-tag-version`, you can check the [github repository](https://github.com/absolute-version/commit-and-tag-version).
