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

chore(all): simplify mocks generation #1413

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Conversation

qdm12
Copy link
Collaborator

@qdm12 qdm12 commented Dec 27, 2024

Why this should be merged

💁 Sibling PR for coreth so both repositories would look similar in this aspect

  • Localized mockgen commands in the package where they are needed
  • Generate mocks from your IDE directly
  • Platform independent way of generating mocks
  • Check automatically mocks are kept up to date with their matching interfaces
  • Check automatically mocks all have a matching source controlled generation command
  • Remove license headers for generated mocks
  • Generating mocks section added in contributing document

How this works

  • New mocks_generate_test.go file per package where mocks need to be generated, containing only //go:generate commands for mock generation. Each command is relative to the current package directory
  • Use //go:generate go run go.uber.org/mock/mockgen to avoid requiring to pre-install mockgen
  • no shell script, just go command needed with go generate -run "mockgen" ./...
    • Remove now unneeded scripts/mocks.gen.sh and scripts/mocks.mockgen.txt
  • Add step to CI test job to check:
    • mocks are up to date, by re-generating all of them and running a git add --intent-to-add --all and git diff --exit-code
    • mocks each have a source controlled //go:generate generation command, by removing all of them before re-generating them
  • Documentation added to .github/CONTRIBUTING.md

How this was tested

CI passing (Golang unit tests > Mocks are up to date)

Need to be documented?

Yes in .github/CONTRIBUTING.md

Need to update RELEASES.md?

Not really

@qdm12 qdm12 changed the title chore(scripts): simplify mock.gen.sh to use go generate commands chore(scripts): simplify mock.gen.sh to use go generate commands Dec 27, 2024
@qdm12 qdm12 force-pushed the qdm12/mock-gen-script branch from 3edebbc to a37996e Compare December 27, 2024 11:29
@qdm12 qdm12 marked this pull request as ready for review December 27, 2024 11:48
@qdm12 qdm12 requested review from ceyonur, darioush and a team as code owners December 27, 2024 11:48
license_header Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we have any sibling PR for avalanchego? This is a direct copy from avalanchego. I'd prefer to keep workflows in repos (coreth/subnet-evm/avalanchego) as similar as possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in ava-labs/avalanchego#3628

I'm happy to wait for that PR to be discussed first and then merge the coreth and subnet-evm ones after.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ava-labs/avalanchego#3628 merged, and I pushed a few commits here to make it as similar as possible 😉

@qdm12 qdm12 force-pushed the qdm12/mock-gen-script branch 2 times, most recently from 0c66511 to b001446 Compare December 30, 2024 17:09
qdm12 added 4 commits January 6, 2025 09:14
- requires a `tools.go` blank importing golang.org/x/mod/semver in order to have the `golang.org/x/mod` dependency satisfied for mockgen v0.4
- not used anywhere
- different from avalanchego
- does not work on windows' bash
@qdm12 qdm12 force-pushed the qdm12/mock-gen-script branch from f7b7acb to c2c5fb0 Compare January 6, 2025 09:44
@qdm12 qdm12 requested a review from ceyonur January 6, 2025 10:54
@qdm12 qdm12 changed the title chore(scripts): simplify mock.gen.sh to use go generate commands chore(scripts): simplify mocks generation Jan 6, 2025
@qdm12 qdm12 changed the title chore(scripts): simplify mocks generation chore(all): simplify mocks generation Jan 6, 2025
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.

3 participants