modver - a Go package and command that helps you obey semantic versioning rules in your Go module.

Modver

Go Reference Go Report Card Tests Coverage Status

This is modver, a Go package and command that helps you obey semantic versioning rules in your Go module.

It can read and compare two different versions of the same module, from two different directories, or two different Git commits. It then reports whether the changes require an increase in the major-version number, the minor-version number, or the patchlevel.

Installation and usage

Install the modver command using Go 1.16 or later like this:

go install github.com/bobg/modver/cmd/modver@latest

Assuming the current directory is the root of a cloned Git repository, you can run it like this:

$ modver -git .git HEAD~1 HEAD

to tell what kind of version-number change is needed for the latest commit. The -git .git gives the path to the repository’s info; it can also be something like https://github.com/bobg/modver. The arguments HEAD~1 and HEAD specify two Git revisions to compare; in this case, the latest two commits on the current branch. These could also be tags or commit hashes.

Modver also has a simple API for use from within Go programs.

Semantic versioning

Briefly, a major-version bump is needed for incompatible changes in the public API, such as when a type is removed or renamed, or parameters or results are added to or removed from a function. Old callers cannot expect to use the new version without being updated.

A minor-version bump is needed when new features are added to the public API, like a new entrypoint or new fields in an existing struct. Old callers can continue using the new version without being updated, but callers depending on the new features cannot use the old version.

A patchlevel bump is needed for most other changes.

The result produced by modver is the minimal change required. The actual change required may be greater. For example, if a new method is added to a type, this function will return Minor. However, if something also changed about an existing method that breaks the old contract - it accepts a narrower range of inputs, for example, or returns errors in some new cases - that may well require a major-version bump, and this function can't detect those cases.

You can be assured, however, that if this function returns Major, a minor-version bump won't suffice, and if this function returns Minor, a patchlevel bump won't suffice, etc.

The modver command (in the cmd/modver subdirectory) can be used, among other ways, to test that each commit to a Git repository increments the module’s version number appropriately. This is done for modver itself using GitHub Actions, here.

(Note that the standard actions/checkout@v2 action, for cloning a repository during GitHub Actions, creates a shallow clone with just one commit’s worth of history. For the usage here to work, you’ll need more history: at least two commit’s worth and maybe more to pull in the latest tag for the previous revision. The clone depth can be overridden with the fetch-depth parameter, which modver does here.)

Owner
Comments
  • Suggestion for `modver` output

    Suggestion for `modver` output

    To help with readability:

    Patchlevel: 
    handleRequest: old and new versions of parameters of are not identical:
    
        Details:
        in type github.com/lib/CustomType: 
            in parameters of 
                func(a *CustomType, path string) error: 
                    handleRequest
    
                struct{
                    field1 string
                } 
    
  • False

    False "Major" positive

    Modver claims that there is a major-version change in this diff (of two recent versions of modver itself): https://github.com/bobg/modver/compare/0481b0af47a4cf9c59d6a765fe59aa34ff2e77fb...56512db177a95c010ef2308a844cf2eb5071b2ce

    ...but there is not.

  • Git Native Client Option

    Git Native Client Option

    add option to allow modver to use the native git shell client versus go-git

    This is because go-git does not provide the option to skip fetching a remote even when cloning a repository from the local filesystem. This can cause issue when git fetch is not available via eith https or ssh.

    Tested manually with:

    > ./modver -gitpath /usr/bin/git -git .git $MERGE_BASE HEAD
    > ./modver -git .git $MERGE_BASE HEAD
    ...
    
  • add option to allow modver to use the native git shell client versus …

    add option to allow modver to use the native git shell client versus …

    add option to allow modver to use the native git shell client versus go-git.

    This is because go-git does not provide the option to skip fetching a remote even when cloning a repository from the local filesystem. This can cause issue when git fetch is not available via eith https or ssh.

  • Adding and removing interface methods are both Major changes

    Adding and removing interface methods are both Major changes

    Adding a method to an interface is presently considered a Minor change, on the premise that existing calling code can invoke all the same methods as before, plus some new ones, so the change is backward-compatible. But! Calling code implementing the interface breaks if it doesn't implement the new method, so the change is not backward-compatible.

    A similar argument goes for removing interface methods (which is already considered a Major change).

  • Transitive major-version upgrades

    Transitive major-version upgrades

    Seen in the wild (actual project names concealed to protect proprietary interests):

    Module A exports function F that takes a *github.Client as an argument. Module B calls F.

    Module A upgrades its go-github dependency from v47 to v48. Now F takes a *github.Client (a different type, because it's a different major version). Modver does not require a major-version upgrade in A, and B breaks.

  • Use proposed go/types API

    Use proposed go/types API

    To support generics, modver duplicates some of the logic in go/types that is presently unexported. There are two proposals to export some of that logic:

    • https://github.com/golang/go/issues/50447
    • https://github.com/golang/go/issues/50963

    When and if those proposals become adopted, modver should use those calls.

Related tags
A boilerplate for Go fiber versioning
A boilerplate for Go fiber versioning

Fiber Versioning Boilerplate Prerequisite Make sure you have the following installed outside the current project directory and available in your GOPAT

Nov 18, 2022
Helps exercise your memory by giving you random tokens and poems to memorize.

memory-enhancer Helps exercise your memory by giving you random tokens and poems to memorize. Using Every day when you first open your terminal you wi

Nov 9, 2021
An operator that helps you perform benchmarks

Camunda-Benchmark-Operator ??️‍♀️ An operator that helps you perform benchmarks. Your first benchmark This requires that you know how to run the opera

Mar 2, 2022
Squizit is a simple tool, that aim to help you get the grade you want, not the one you have learnt for.
Squizit is a simple tool, that aim to help you get the grade you want, not the one you have learnt for.

Squizit is a simple tool, that aim to help you get the grade you want, not the one you have learnt for. Screenshots First, input PIN Then enjoy! Hoste

Mar 11, 2022
The package manager for macOS you didn’t know you missed. Simple, functional, and fast.
The package manager for macOS you didn’t know you missed. Simple, functional, and fast.

Stew The package manager for macOS you didn’t know you missed. Built with simplicity, functionality, and most importantly, speed in mind. Installation

Mar 30, 2022
A Golang library to manipulate strings according to the word parsing rules of the UNIX Bourne shell.

shellwords A Golang library to manipulate strings according to the word parsing rules of the UNIX Bourne shell. Installation go get github.com/Wing924

Sep 27, 2022
Go library for generate serial numbers according to rules.

go-sn - Serial Number Generator Go library for generate serial numbers according to rules. This library is also useful for generating serial numbers i

Sep 8, 2022
Package fsm allows you to add finite-state machines to your Go code.

fsm Package fsm allows you to add finite-state machines to your Go code. States and Events are defined as int consts: const ( StateFoo fsm.State =

Dec 9, 2022
A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.
A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.

one-file-pdf - A minimalist PDF generator in <2K lines and 1 file The main idea behind this project was: "How small can I make a PDF generator for it

Dec 11, 2022
Assembly syntax that makes you feel like you're writing code in a high-level language.

shasm Assembly syntax that makes you feel like you're writing code in a high-level language. Shasm is not an Assembler. Shasm simply compiles Shasm sy

Jun 5, 2021
If you accept that 1 day is 24 hours in some situations, you might want to parse it in Go too.

relaxduration If you accept that 1 day is 24 hours in some situations, you might want to parse it in Go too. This package tries to handle situations w

Dec 7, 2022
Host yo' self from your browser, your phone, your toaster.
Host yo' self from your browser, your phone, your toaster.

A hosting service from the browser, because why not. Try it at hostyoself.com. See it in action Here's an example where I use hostyoself.com to host i

Jan 1, 2023
GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way to say thanks to the maintainers of the modules you use and the contributors of Go itself.
GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way  to say thanks to the maintainers of the modules you use and the contributors of Go itself.

Give thanks (in the form of a GitHub ★) to your fellow Go modules maintainers. About GoThanks performs the following operations Sends a star to Go's r

Dec 24, 2022
Go package and associated command line utility to generate random yet human-readable names and identifiers
Go package and associated command line utility to generate random yet human-readable names and identifiers

namegen | What's this? Go package and associated command line utility to generate random yet human-readable names and identifiers. Somewhat inspired b

Oct 19, 2022
A Go package to allow you to read and write from the serial port as a stream of bytes.

Serial A Go package to allow you to read and write from the serial port as a stream of bytes. Details It aims to have the same API on all platforms, i

Jan 6, 2023
You could leverage Alfred and Google Sheets to track your time with ease.
You could leverage Alfred and Google Sheets to track your time with ease.

You could leverage Alfred and Google Sheets to track your time with ease. The goal is to track your time in a way that is easy to understand how much time you spend on.

Dec 25, 2022
This application is a tool that allows you to prepare mail designs specific to your group and make Christmas raffles.

What is this? This application is a tool that allows you to prepare mail designs specific to your group and make Christmas raffles. How is it working?

Dec 15, 2022
Gosfdc module - a collection of packages containing the data structures from the various Salesforce APIs and Tools

Gosfdc module - a collection of packages containing the data structures from the various Salesforce APIs and Tools

Jan 21, 2022
A command-line tool that triggers command when the input (doesn't) comes from STDIN in an interval.

conk A command-line tool that triggers command when the input (doesn't) comes from STDIN in an interval. Usage $ conk -h A command-line tool that trig

Apr 29, 2022