Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add Conventional Commit Linter #800

Conversation

arielvalentin
Copy link
Collaborator

@arielvalentin arielvalentin commented Jan 7, 2024

I have made too many mistakes approving and merging PRs that lack conventional commits.

This Action should mitigate those mistakes going forward.

Failure

image

Success

image

docs
refactor
release
test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix, feat and perf are missing (of which the first two should be included by default; but it might be nice to be explicit).
Since include-commits: true, I expect squash should also be included here.

Lastly, I believe a token is needed to validate the commits associated to the PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I did was not certain that it was necessary to make a distinction between perf and fix and I am on the fence about whether refactor and test are useful to make distinctions from CI or fix.

Do we gain any additional insights supporting the additional types?

Since include-commits: true, I expect squash should also be included here.

Fair. I use squash all the time and probably do not need it to fail the linter check; though I do want it to be more strict when merging to main

Lastly, I believe a token is needed to validate the commits associated to the PR

For some reason I thought it used a default token! Thanks for the pointer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we gain any additional insights supporting the additional types?

I'm not sure; but I do think that since these are conventional, that we should support them.
Especially since we encourage people to use them, CI shouldn't fail on those.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially since we encourage people to use them, CI shouldn't fail on those.

Great catch. I'm comfortable limiting the list to just those included in our CONTRIBUTING documentation. However, I could see ci and release being very helpful for maintainers, but not for contributors.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, the Convention Commits specification does not impose any restrictions on the type - it only requires feat and fix as these have a special purpose (in relation to SemVer).

Therefore, CommitMe will not impose any restrictions on the type unless you provide an additional list of types to restrict to.

Typically, projects are using the Angular definition of types;

  • build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
  • ci: Changes to our CI configuration files and scripts (examples: CircleCi, SauceLabs)
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • test: Adding missing tests or correcting existing tests

(taken from: https://github.com/angular/angular/blob/68a6a07/CONTRIBUTING.md#-commit-message-format)

Note

The same principle true for the scopes configuration parameter (no restrictions, unless configured)

@arielvalentin arielvalentin force-pushed the add-conventional-commit-linters branch 3 times, most recently from 4f592bb to df1c0d5 Compare January 10, 2024 02:51
@arielvalentin arielvalentin force-pushed the add-conventional-commit-linters branch from ebab210 to a527941 Compare January 11, 2024 03:50
@arielvalentin
Copy link
Collaborator Author

arielvalentin commented Jan 11, 2024

@kaylareopelle @scbjans Seems like default merge commit messages are not allowed because only Squash Commits are allowed.

It also means revert commits will need to be formatted differently.

That will mean we have to rebase whenever we sync branches. Do you all think that is OK?

https://github.com/open-telemetry/opentelemetry-ruby-contrib/actions/runs/7483619858/job/20369149719
image

@arielvalentin arielvalentin force-pushed the add-conventional-commit-linters branch 2 times, most recently from a4305cb to 096647c Compare January 14, 2024 15:48
@scbjans
Copy link
Contributor

scbjans commented Jan 15, 2024

@kaylareopelle @scbjans Seems like default merge commit messages are not allowed because only Squash Commits are allowed.

It also means revert commits will need to be formatted differently.

That will mean we have to rebase whenever we sync branches. Do you all think that is OK?

@arielvalentin Apparently Merge commits are allowed, but with our current configuration we cannot set include-commits: true (because of the merge commits with a non-conventional commit message).

Would it be possible to update the repository and configure the merge_commit_message (sorry, can't deeplink) to BLANK?

IIUC a rebasing merge strategy would mean (potential) contributors need to reset their local branch upon each branch sync, that does not seem desirable to me.

@arielvalentin
Copy link
Collaborator Author

I believe the docs you're referencing are for the defaults values used when merging a PR to a target branch but I'm not aware of how to set the default merge commit message when syncing a fork or branch.

I feel like we have limited options here. I am a fan of rebasing but also am sympathetic to how tricky it can get when dealing with conflicts.

I want to scan commits because it's what the release tooling uses at the moment but we also squash and merge to main so maybe that's enough?

I'll disable commit scanning and see how this works purely with PR title scans.

@arielvalentin arielvalentin changed the title Add Conventional Commit Linter ci: Add Conventional Commit Linter Jan 22, 2024
@arielvalentin arielvalentin force-pushed the add-conventional-commit-linters branch from 13c3bd2 to 121b9a8 Compare January 22, 2024 13:06
.commit-me.json Outdated
@@ -0,0 +1,4 @@
{
"include-pull-requests": true,
"types": [ "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "release", "squash", "test" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. style and revert are both listed in ci: Add Conventional Commit Lint #821, but aren't present here. Do we want to include them?

  2. Does this get around merge commit validations, or do we need to add those too?

  3. Last thing, test is in this list and it's also in the Conventional Commits Angular documentation, but our CONTRIBUTING.md file currently lists tests, plural.

Looking through our commits, it seems like we've used both forms, but test is more common. I prefer to go with test and update our contributing docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style and revert are both listed in #821, but aren't present here. Do we want to include them?

👍🏼

Does this get around merge commit validations, or do we need to add those too?

Yes! Where it did not support it in my initial tests, it does now. https://github.com/open-telemetry/opentelemetry-ruby-contrib/actions/runs/7614598575/job/20737243103

Last thing, test is in this list and it's also in the Conventional Commits Angular documentation, but our CONTRIBUTING.md file currently lists tests, plural.

👍🏼

Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@scbjans
Copy link
Contributor

scbjans commented Jan 24, 2024

Been thinking about this a little longer. Functionally we only need PR title validation for the release tooling?
If so, maybe we should not include commits at this stage since it might break contributor workflows?
We can enable that setting later on if we want?

@arielvalentin
Copy link
Collaborator Author

Been thinking about this a little longer. Functionally we only need PR title validation for the release tooling? If so, maybe we should not include commits at this stage since it might break contributor workflows? We can enable that setting later on if we want?

I brought this up during the SIG. I do not think folks had a strong opinion either way, however during the SIG @mwear also shared a preference to using client-side git-hooks to validate individual commit messages. This would reduce friction for contributors, who would get an error message earlier in the process and avoid generating non-conventional commits.

It would not enforce commits coming from say the PR UI suggestions but as you stated, perhaps all we need is PR title validation. That would at least mitigate issues with maintainers (mostly me) end up merging bad squashed commits.

@scbjans
Copy link
Contributor

scbjans commented Jan 24, 2024

using client-side git-hooks to validate individual commit messages.

That sounds like a great idea!

Copy link
Contributor

@scbjans scbjans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

In addition to that, I would like to follow up on @mwear suggestion to install client side git-hooks before enabling commit validation in the action.

Let's implement that in a separate PR.

@arielvalentin arielvalentin merged commit 11ae23d into open-telemetry:main Feb 8, 2024
50 checks passed
@arielvalentin arielvalentin deleted the add-conventional-commit-linters branch February 8, 2024 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants