Skip to content

Commit

Permalink
feat: generate semantic release from the commit merged into main (#2576)
Browse files Browse the repository at this point in the history
## What's the purpose of this pull request?

Generate semantic release from the commit merged into main (PR title).
We squash the commits before merging into main. The resulting commit
will have by default the PR title. So we have to ensure that the PR
title has this convention.

TODO: Create an action to block merge button if the PR title is not
following the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.

Solutions: `lerna version --conventional-commits --yes`

When run with this flag, lerna version will use the [Conventional
Commits Specification](https://conventionalcommits.org/) to [determine
the version
bump](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-recommended-bump)
and [generate CHANGELOG.md
files](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-cli).

WARNING: I wasn't able to validate the publish command in an easy way,
but I'm guessing that if the versions are correct, publish will just
send it to NPM.

[thread with more
details](https://vtex.slack.com/archives/C03L3CRCDC4/p1732651564186349)

## How it works?

![Captura de Tela 2024-12-02 às 10 41
54](https://github.com/user-attachments/assets/9ec87592-ff83-470d-9fe4-c6d35a56cf70)

## How to test it?

Create a new branch and follow this steps: 

1. Create a commit following Conventional Commits specification
2. Run the command `npx lerna version --conventional-commits --yes
--no-push` . The command `--no-push` is very important to avoid push the
tags.
3. Check the release version and changelog generated. 
4. Now, Revert the changes to avoid side effects in the publish
workflow.
5. Remove the changes: `git reset HEAD~1`
6. Remove the tag generated: `git tag -d [tag_version]`. Ex: `git tag -d
v3.1.0`


## References

Reference:
https://github.com/lerna/lerna/tree/main/libs/commands/version#--conventional-commits
  • Loading branch information
pedromtec authored Dec 9, 2024
1 parent 66e2cf9 commit 9b45140
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@
"message": "[no ci] Release: %v"
}
},
"ignoreChanges": [
"CHANGELOG.md",
"**/__fixtures__/**",
"**/*.snap",
"**/*.test.*",
"**/*.md"
],
"packages": ["packages/*", "apps/*"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "turbo run lint",
"test": "turbo run test",
"size": "turbo run size",
"release": "lerna version patch --yes && lerna publish from-git --yes",
"release": "lerna version --conventional-commits --yes && lerna publish from-git --yes",
"clean": "turbo run clean && rm -rf node_modules",
"format": "prettier --ignore-path .gitignore --write \"**/*.{js,jsx,ts,tsx,md}\""
},
Expand Down

0 comments on commit 9b45140

Please sign in to comment.