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: Check commits in PRs #1122

Closed

Conversation

realeinherjar
Copy link
Contributor

@realeinherjar realeinherjar commented Sep 12, 2023

Closes #1119.

  • Creates commits.yml in .github/workflows/ directory with a new GH Action
    that has 2 jobs:

    1. signed-commits: uses [1Password/check-signed-commits-action(https://github.com/1Password/check-signed-commits-action)
      to check if all commits in the PR are signed.
    2. conventional-commits: uses cocogitto/cocogitto-action
      based on cocogitto
      to check if all commits in the PR follows the conventional commits,
      i.e. they are prefixed with fix, refactor, feat etc.
  • Clarifies the "Commit policy" CONTRIBUTING.md:

    • Rust-based CLI tool suggestion to locally check for the commits: cocogitto/cocogitto.
    • Suggestion of two git hooks, see below.
  • Two Git Hooks
    to the new directory ci/git-hooks

    • signed-commits.sh hook (a pre-push hook)
      will not allow the user to push to remote if the last commit is not signed.
      This is a good sanity test,if the last commit is signed then there is a high chance
      of any other previous are also signed.
    • conventional-commits.sh hook (a commit-msg hook) will not allow the user to commit
      if the commit message does not satisfy the Conventional Commits template.

Notes to the reviewers

Since this is a big enforcement change,
we can for now not make this CI check mandatory for a PR to be merged.
When appropriate we can turn check mandatory.

Also none of these actions have write permissions.

Changelog notice

Added CI checks for signed commits and conventional commits guidelines.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature (in CONTRIBUTING.md)

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

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

Heads up, the conventional commits check is failing.

Also, I like this idea from @evanlinjin: https://discord.com/channels/753336465005608961/999098651383189554/1152079701985210408
Do you think we could just have a few scripts checking if commits are signed and conventional instead, so that the check is easy to reproduce locally?

@realeinherjar
Copy link
Contributor Author

Heads up, the conventional commits check is failing.

Somehow webiny/action-conventional-commits was not published to the github actions marketplace.
I've edited the commits in the PR to use aevea/commitsar instead, which is published.

@realeinherjar realeinherjar changed the title Einherjar/ci commits feat(CI): Check commits in PRs Sep 15, 2023
@notmandatory
Copy link
Member

A few comments:

  1. Is there any reason to use the signed-commits github action instead of just relying on the github setting to require signed commmits? I'd rather not add a new CI job and plugin if github can do it without
  2. If the recommendation is to use commitlint locally shouldn't we use it for the ci job also? https://commitlint.js.org/#/guides-ci-setup?id=github-actions
  3. I think the first commit message that starts with feat(CI) should start with just ci: to be to spec. 🙂

@realeinherjar realeinherjar changed the title feat(CI): Check commits in PRs feat(ci): Check commits in PRs Sep 15, 2023
@notmandatory
Copy link
Member

Another suggestion, the cocogitto tool may be better for a rust project like ours. It also has instructions for integrating with ci.

@realeinherjar realeinherjar force-pushed the einherjar/ci-commits branch 4 times, most recently from b8f6706 to ebff4b5 Compare September 15, 2023 21:31
@realeinherjar
Copy link
Contributor Author

realeinherjar commented Sep 15, 2023

Another suggestion, the cocogitto tool may be better for a rust project like ours. It also has instructions for integrating with ci.

That's an amazing suggestion. Yeah I much prefer this one! I followed the instructions at https://github.com/cocogitto/cocogitto-action.
Done in 5647563.

  1. If the recommendation is to use commitlint locally shouldn't we use it for the ci job also? https://commitlint.js.org/#/guides-ci-setup?id=github-actions

Let's change to cocogitto. Done in ebff4b5.

  1. I think the first commit message that starts with feat(CI) should start with just ci: to be to spec.

Done in ebff4b5.

  1. Is there any reason to use the signed-commits github action instead of just relying on the github setting to require signed commmits? I'd rather not add a new CI job and plugin if github can do it without

Yes, but that feature is not automatically copied over to forks.
BDK's enforcement would work in bitcoindevkit/bdk but not in someone/bdk.
Hence, this would not be enforced automatically when people apart the maintainers who can have branches at bitcoindevkit/bdk when they commit in their forks.
This would only happen when we would try to merge the PR.
Here's a recent example: https://github.com/bitcoindevkit/bdk/pull/967/commits
The commits were not signed, but the user was able to not only make the PR but also all CI checks passed.

@realeinherjar
Copy link
Contributor Author

NOTE to myself: cocogitto might check the WHOLE commit history.
If BDK has not always been conventional commits compliant, we migth get a CI commit check failure.
We need to perform check only since the latest tagged version:

      - name: Conventional commit check
        uses: cocogitto/cocogitto-action@v3
        with:
          check-latest-tag-only: true

@notmandatory
Copy link
Member

I think the only way to do this would be to use check-latest-tag-only: true and then we have to wait until after our next tag (should be 1.0.0-alpha.2) to merge this PR. Then from that tag forward all commits will be to be compliant.

@realeinherjar
Copy link
Contributor Author

We can also merge now and not add conventional commits to the mandatory CI checks for PRs to be merged onto master.
Then, 1.0.0-alpha.2 onwards we can enforce this if we want.

@realeinherjar realeinherjar changed the title feat(ci): Check commits in PRs ci: Check commits in PRs Sep 15, 2023
@danielabrozzoni
Copy link
Member

Is there any reason to use the signed-commits github action instead of just relying on the github setting to require signed commmits? I'd rather not add a new CI job and plugin if github can do it without

The reason behind a CI job would be to make the requirement for signed commits more explicit. What happened to me way to many times is that I would ack a PR and notice only later that the author didn't sign the commits, and usually this means waiting days/weeks before the author sees the comments and does something about it. Instead, if at the time of opening PR the CI fails because of signed commits, the author can quickly fix.

@danielabrozzoni
Copy link
Member

Do you think we could just have a few scripts checking if commits are signed and conventional instead, so that the check is easy to reproduce locally?

Btw, we already use the bitcoin core method for merging PRs, using the github-merge.py script, maybe we should consider to also check the commits validity like Bitcoin Core does? In this way, we would add all the docs to verify the commits.
See:

@notmandatory
Copy link
Member

Yes, but that feature is not automatically copied over to forks.

This is a good reason to enable it. I've had to remind new committers (and sometimes not new) to sign commits, having CI on their forks to automatically notify folks would be useful.

@realeinherjar
Copy link
Contributor Author

@danielabrozzoni, I've added two Git Hooks to the new directory ci/git-hooks.
These are bash scripts that the user can add to the .git/hooks/ directory to automatically enforce conventional and signed commits.
Conventional commits hook (a commit-msg hook) will not allow the user to commit if the commit message does not satisfy the conventional commits template.
Signed commits hook (a pre-push hook) will not allow the user to push to remote if the last commit is not signed.
This is a good sanity test, if the last commit is signed then the chance of the other previous are also signed.

I also added instructions to CONTRIBUTING.md.

Here's an output:

> git commit -m "test hook"
Error: Invalid commit message format. Please use a conventional commit message.
Commit message should match the pattern: ^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([[:alnum:]\-]+\))?:[[:space:]].*.
Please refer to https://www.conventionalcommits.org/en/v1.0.0/ for more details.
> git commit --no-gpg-sign -m "ci: test hook"
[einherjar/ci-commits 205b54c] ci: test hook
 3 files changed, 53 insertions(+), 5 deletions(-)
 create mode 100755 ci/git-hooks/conventional-commits.sh
 create mode 100755 ci/git-hooks/signed-commits.sh
> git push
Error: Last commit (205b54cd7caf6b86d53699177137280e91be7c00) is not signed.
error: failed to push some refs to 'https://github.com/realeinherjar/bdk.git'

@danielabrozzoni
Copy link
Member

@danielabrozzoni, I've added two Git Hooks to the new directory ci/git-hooks.

Thanks!

I see that the conventional commits check is failing on the merge commits (for example 59fc1b3), is there a way to configure it to allow them?

@realeinherjar
Copy link
Contributor Author

I see that the conventional commits check is failing on the merge commits (for example 59fc1b3), is there a way to configure it to allow them?

That is only possible with a cog.toml cocogitto configuration file.
Setting ignore_merge_commits = true will make Merge ... commit messages not fail on CI.

This is documented in the cocogitto docs.
The CI cocogitto action should load the cog.toml configs.

Closes bitcoindevkit#1119.
Creates `commits.yml` in `.github/workflows/` directory with a new GH Action
that has 2 jobs:

1. `signed-commits`: uses [`1Password/check-signed-commits-action`](https://github.com/1Password/check-signed-commits-action)
   to check if all commits in the PR are signed.
1. `conventional-commits`: uses [`cocogitto/cocogitto-action`](https://github.com/cocogitto/cocogitto-action)
   based on [`cocogitto`](https://crates.io/crates/cocogitto)
   to check if all commits in the PR follows the conventional commits](https://www.conventionalcommits.org/en/v1.0.0-beta.2/),
   i.e. they are prefixed with `fix`, `refactor`, `feat` etc.
- `signed-commits.sh` hook (a `pre-push` hook)
  will not allow the user to push to remote if the last commit is not signed.
  This is a good sanity test,if the last commit is signed then there is a high chance
  of any other previous are also signed.
- `conventional-commits.sh` hook (a `commit-msg` hook) will not allow the user to commit
  if the commit message does not satisfy the Conventional Commits template.
`ignore_merge_commits` set to `true` will ignore `Merge ...` like in 59fc1b3.
@notmandatory
Copy link
Member

@realeinherjar Is this PR still needed or will these checks be rolled into #1165?

@realeinherjar
Copy link
Contributor Author

This is superseded by #1165.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

CI: Enforce conventional commits and signed commits
3 participants