Steps to publish my GO package on Github
Hi, I wish to start publishing my own GO packages on Github, but with some hoops I have to jump through:
- The code is first versioned on a local network gitea server, which is not totally, totally 100% compatible with github
- Once the gitea repo established, I need to create a new github endpoint : `git remote add publicRepo github.com/$MYUSER/$MYREPO.git`
So this means that I cannot use the UI to pull/push the code to/from gitea and github. It's a requirement we can accept here. It is done the old fashioned way : git push && git push publicRepo
Now, it worked fine for a whole software, but I try now to publish shared packages that everyone could download, and wonder about the actual steps to create the whole thing and get it published + usable from anywhere, anytime.
This, I've tried, so far, and failed at, would you mind helping me with the wrong/missing steps ?
The package is named, for now customErrorsExtender
1. created my gitea repo on https://gitea.mynetwork.com:myport/publicGoCode/customErrorsExtender
2. created an empty github.com repo : https://github.com/myuser/customErrorsExtender/
3. created a new GOLAND project called customErrorsExtender in /repos/publicGoCode/
4. in /repos/publicGoCode/customErrorsExtender : mkdir customErrorsExtender, where my package source code will reside, with, obviously having all files starting with “package customErrorsExtender”
5. from /repos/publicGoCode/customErrorsExtender: rm -f go.mod; go mod init github.com/myuser/customErrorsExtender
From there the steps are not that clear (that is, not to me):
Once the code uploaded (pushed) both on gitea and github, I need to publish it as a release as well ? If true, I've no github actions or CICD pipeline (yet) dealing with github, and it means manual ops all around for the time being. I understand that it'd make sense so every potential user uses the latest and greatest version, of course, but a minor drag for me right now.
So, if any steps are missing or wrong, would you mind letting me know ?
Also, related:
My package rootdir is /repos/publicGoCode/customErrorsExtender. The package is named customErrorsExtender, as you know; do I need to create a subdir CustomErrorsExtender and put the code there, or should everything be in the rootdir ?
Please sign in to leave a comment.
Hi,
At step 3, it's better to clone your project in GoLand using Get from VCS button on Welcome Screen.
After that, you can transfer all your repository files from Gitea to a newly created repository, commit and push changes to a remote repository on GitHub.
The last step is to publish your repository as a package using Git tags, the easiest way is to use GoReleaser tool: https://goreleaser.com/
GoReleaser has good documentation for Quick Start: https://goreleaser.com/quick-start/
Then you can create simple GitHub Actions to use GoReleaser on scheduled triggers/events.
Answer to the last question: nested directory structure isn't necessary. You can store all your package files in the project root, see the following examples for reference:
- https://github.com/sirupsen/logrus
- https://github.com/uber-go/zap
I hope it helps.
Thanks, Danill, for all of the answers, above. I'll have a look at goreleaser, looks nice.
My github actions are already set, but I'll still around, because of a minor issue with mine, so far.