Publish a GO package to github

I have this package that I wrote, let’s call it mypkg. It is available on github.com/myuser/mypkg/

Once the package was completed, I did this:

  • git tag -a ‘1.00.00’ -m ‘version 1.00.00’
  • go mod init github.com/myuser/mypackage
  • git add . && git commit -m ‘my commit message’
  • git push --follow-tags origin ← push the tag to the repo

And I’m done, package-wise (… I think ?)

Now on the software that might wish to use mypkg, I do this, in the tool’s rootdir (where its go.mod file resides):

  • go get github.com/myuser/__mypkg
  • Then, in every source file that needs the package I add this in the import statement:
    github.com/myuser/__mypkg

The problem is with go get : it seems to download a version v0.00.00-with_some_hash, instead of __1.00.00

Why ?

Hello there, did you update your go.mod file? You also need to check what version is marked as release on GitHub.

go mod init && go mod tidy.

On github’s side, I only tagged the code, did not release it. I thought that tagging was sufficient ? This must be my issue, then

What version of the package appears in your “go.mod” file?

it does not show :-/

The package to be published is tagged this way: git tag -a '1.0.0' -m 'First version' and git push --follow-tags origin … On github, I’ve published a release from that 1.0.0 tag.

Now, in the tool that should use the tool, I do: go get github.com/MYUSER/MYPACKAGE

The output shows this:
go: added github.com/MYUSER/MYPACKAGE v0.0.0-20240401010128-eac52ef19ef8

The require section of go.mod shows the same

It’s as if GO ignores the actual tag/release. If I check in my GOROOT ($HOME/go/pkg/mod/github.com/MYUSER/), MYPKG is obviously downloaded there, with the same bogus version number

it could be because tag should be v*.*.*, try to change your tag and change version in mod file explicitly.

tags have to be prepended with v ? ho, I missed that one.

I am using Jetbrains’ GoLand, I thought the IDE might have been messing things up.

Will try later today and will let you know.

Ok, I tested, and it works fine, I’ve managed to import my package and use it in some other tool.

It was just a matter of tagging my package with a v prefix: v1.0.0 …

Thanks, @lemarkar !

1 Like

Same problem, different package I’m trying to publish:

You see, the release IS THERE.

I add the following line to go.mod:
github.com/jeanfrancoisgratton/helperFunctions v1.0.0

Then run go mod tidy, and it then complains this way:

 github.com/stretchr/testify/assert: github.com/jeanfrancoisgratton/helperFunctions@v1.0.0: verifying go.mod: github.com/jeanfrancoisgratton/helperFunctions@v1.0.0/go.mod: reading https://sum.golang.org/lookup/github.com/jeanfrancoisgratton/helper!functions@v1.0.0: 404 Not Found
        server response: not found: github.com/jeanfrancoisgratton/helperFunctions@v1.0.0: invalid version: unknown revision v1.0.0

What gives ?

OK… So I’ve pushed multiple updates to the code (documentation, some extra functions, etc).

  • git add .
  • git commit -m ‘Extra functions, bla bla bla’
  • git tag -a ‘v1.1.0’, -m ‘my message’
  • git push --follow-tags origin

And then, go mod tidy, edited go.mod with a new version, go mod tidy again (yeah I know redundant steps here), and… MAGIC, it worked.

Something tells me me that the whole link between github.com, GOLANG, and most likely, Jetbrains’ GOLAND is fragile.

I mean… I’m a seasoned DevOps guy, maybe not-so in GO, but still… scratching my head until you can see the scratch marks is not an usual way for me.