|
| 1 | +# semantic-release |
| 2 | + |
| 3 | +## What |
| 4 | + |
| 5 | +[semantic-release](https://github.com/semantic-release/semantic-release) automates the whole package release workflow including determining the next version number, generating the release notes, and publishing the package. |
| 6 | + |
| 7 | +semantic-release uses the commit messages to determine the consumer impact of changes in the codebase. Following formalized conventions for commit messages, `semantic-release` automatically determines the next semantic version number, generates a changelog and publishes the release. |
| 8 | + |
| 9 | +## Why |
| 10 | + |
| 11 | +Follow a well-established [commit message convention](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#commit) that encourages your team to have structured commits and provides the controls via commits to automatically version your codebase & publish a release. |
| 12 | + |
| 13 | + |
| 14 | +## How |
| 15 | + |
| 16 | +### Commit message convention |
| 17 | + |
| 18 | +The formalized convention is as follows for commit messages: |
| 19 | + |
| 20 | +``` |
| 21 | +<type>(<scope>): <short summary> |
| 22 | + │ │ │ |
| 23 | + │ │ └─⫸ Summary in present tense. Not capitalized. No period at the end. |
| 24 | + │ │ |
| 25 | + │ └─⫸ Commit Scope: A scope MUST consist of a noun describing a section of the codebase surrounded by parenthesis |
| 26 | + │ |
| 27 | + └─⫸ Commit Type: build|ci|docs|feat|fix|perf|refactor|test |
| 28 | +``` |
| 29 | + |
| 30 | +### Example |
| 31 | + |
| 32 | + |
| 33 | +| Commit message | Release type | |
| 34 | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------- | |
| 35 | +| `fix(pencil): stop graphite breaking when too much pressure applied` | Fix Release | |
| 36 | +| `feat(pencil): add 'graphiteWidth' option` | Feature Release | |
| 37 | +| `perf(pencil): remove graphiteWidth option`<br><br>`BREAKING CHANGE: The graphiteWidth option has been removed.`<br>`The default graphite width of 10mm is always used for performance reasons.` | Breaking Release <br /> (Note that the `BREAKING CHANGE: ` token must be in the footer of the commit) | |
| 38 | + |
| 39 | + |
| 40 | +For a base version of `0.1.0`, the following will apply: |
| 41 | + |
| 42 | +| Type | Release type example | Notes | |
| 43 | +|---------------------------|---------------------------|----------------------------------------------------------------| |
| 44 | +| `fix` | increments to `0.1.1` | | |
| 45 | +| `feat` | increments to `0.1.0` | Resets any existing patch fixes e.g: `0.1.3` will be `0.2.0` | |
| 46 | +| `BREAKING CHANGE` | Increments to `1.0.0` | Can be added to any type | |
| 47 | +| All others | No version increment | | |
| 48 | + |
| 49 | + |
| 50 | +## CI setup |
| 51 | + |
| 52 | +!!! warning |
| 53 | + |
| 54 | + This section covers important implications of setting up a base tag/release version (or lack of) in your repo before using `semantic-release`. |
| 55 | + |
| 56 | +### Base release version |
| 57 | + |
| 58 | +A semantic-release workflow is configured to run on the `main` branch and technically no further setup is required. However, the semantic-release initial version is set at `v1.0.0` (with pre-release options) instead of the generally accepted version `v0.1.0`. This may not be desirable for your project so a workaround is described below. |
| 59 | + |
| 60 | +!!! info |
| 61 | + |
| 62 | + As per the semantic versioning [spec](https://semver.org/#how-should-i-deal-with-revisions-in-the-0yz-initial-development-phase), the initial development release should be `v0.1.0`. Optionally you can set it to `v0.0.0` if there is only an initial commit in the repo. |
| 63 | + |
| 64 | + |
| 65 | +<u>In the Github repo page:</u> |
| 66 | + |
| 67 | +1. Click on the **Create a new release** link on the right-hand panel |
| 68 | + |
| 69 | +2. Click on **Choose a tag**, type in your base version (e.g: `v0.1.0`) and hit enter |
| 70 | + |
| 71 | +3. Enter desired release title e.g: Pre-release |
| 72 | + |
| 73 | +4. Tick **This is a pre-release** checkbox |
| 74 | + |
| 75 | +5. Click the **Publish** button |
| 76 | + |
| 77 | +If you don't want to create a release and the steps above are one too many, you can create a tag via the command line: |
| 78 | + |
| 79 | +```bash |
| 80 | +# Within the `main` branch in your git repo |
| 81 | +git tag -a v0.1.0 -m "Pre-release" |
| 82 | +git push origin v0.1.0 |
| 83 | +``` |
| 84 | + |
| 85 | +## Local setup |
| 86 | + |
| 87 | +### Commitizen |
| 88 | + |
| 89 | +Use [commitzen](https://commitizen-tools.github.io/commitizen/) to ease following the commit message convention described [above](semantic-release.md#how). |
| 90 | + |
| 91 | +``` |
| 92 | +pip install -U commitizen |
| 93 | +``` |
| 94 | + |
| 95 | +For more installtion options see [here](https://commitizen-tools.github.io/commitizen/#installation). |
| 96 | + |
| 97 | +!!! info |
| 98 | + |
| 99 | + Stage some files in your repo and type `cz commit` and you're ready to go! |
| 100 | + |
| 101 | + |
| 102 | +!!! tip |
| 103 | + |
| 104 | + Decide on the commit convention scope in advance. This will keep it consistent and provide a coherent semantic mapping. |
| 105 | + |
| 106 | + |
| 107 | +## FAQ |
| 108 | + |
| 109 | +1. I have many `feat` type commits to be added to `main` but I don't want to trigger a release |
| 110 | + |
| 111 | + For a Continous Deployment methodology, it is not uncommon to release small features frequently in isolation. This will undoubtedly increment your minor version but it is acceptable as it reflects the rapid changes in your project. |
| 112 | + |
| 113 | + Alternatively, if you wish to batch features to trigger a release here are some options: |
| 114 | + |
| 115 | + - **Release branch (recommended)** |
| 116 | + |
| 117 | + Create a release branch and merge multiple `feat` type commits to it. When the release branch is ready and merged to `main`, it will condense the numerous `feat` type commits to generate a singular increment in the release version/tag. |
| 118 | + |
| 119 | + - **Non-standard commit type** |
| 120 | + |
| 121 | + Use a custom commit type such as: |
| 122 | + |
| 123 | + ```bash |
| 124 | + # Feature no release (featnr) denotes a feature but is not release ready |
| 125 | + featnr(pencil): add 'graphiteWidth' option |
| 126 | + ``` |
0 commit comments