Go application version in modules - go

How do we add application version in go modules(NOT Dependency version)?I would like to hear from other people on this.I am not sure how to do this

Please follow this guide from the official golang blog for more details.
Let's say you're happy with the API of your module and you want to release v1 as the first stable version. To do this you need to commit latest changes and tag them:
$ git add .
$ git commit -m "feat: changes for v1.0.0"
$ git tag -a v1.0.0 -m 'some release message v1.0.0'
$ git push origin v1.0.0

Related

Replace go-swagger with another version in Windows

I am using go1.14.1 and go-swagger version dev in my Windows 10. I installed go-swagger with Installing from source.
I'd like to use go-swagger version 0.25 instead. What is the clean way of replacing dev with 0.25?
The installation process is same as for master (dev) version except you need to do one more additional step which is checking out tag v0.25.0 after cloning the repo to temporary directory:
dir=$(mktemp -d)
git clone https://github.com/go-swagger/go-swagger "$dir"
cd "$dir"
# Checkout version v0.25.0
git checkout v0.25.0
# Continue with installation, instead of
# go install ./cmd/swagger
# use this which just adds version information (current tag) and commit id to binary
go install -ldflags "-X github.com/go-swagger/go-swagger/cmd/swagger/commands.Version=$(git describe --tags) -X github.com/go-swagger/go-swagger/cmd/swagger/commands.Commit=$(git rev-parse HEAD)" ./cmd/swagger
NOTE: If you do just go install ./cmd/swagger it will technically still install v0.25.0 but swagger version subcommand will report it as dev. The version information is just a cosmetic thing passed from git repository down as content of variables in commands package and you can see how authors do it in their CircleCI config file here. Eventually you can add also other flags to get static build (but they don't do that in official Installing from source instructions).
Once done you should have go-swagger v0.25.0 installed in your $GOPATH/bin, verify with:
$ swagger version
version: v0.25.0
commit: f032690aab0634d97e2861a708d8fd9365ba77d2

how to find out which git-branch a dependency in go.mod belongs to by command-line?

I want to write a shell program to check whether all go module dependencies in my project are on newest master version in their repositories. In particular, I want to know which branch each module is on. There is a file "go.mod" containing each dependency listed as {module}-{commit time}-{commit ID}. How can I get their git-branch name from SHA-1(commit id) or other message by shell program.
I have tried go list -m -u all, only showing the newest edition if the dependency is not up-to-date. etc. git.xxx.com/project v0.0.0-20191119034146-e894bf51bdcd [v0.0.0-20200609070643-fd412b12b811]. Without cloning the repos, can go module tools resolve this quetion?
I couldn't figure out how to find which branch the current dependency belongs to using only go tools. But there is a way to find which branch the commit is on using git.
git clone <repo-url> && cd <repo> && git branch -a --contains <commit>
Reference: Finding what branch a Git commit came from

How can I open the current GitHub branch on Web using Windows command line?

I had this command working on my Mac/Linux (Terminal) with OhMyZsh, but once I moved to Windows, I wasn't sure how to update it using Cmdr/ConEmu shell.
Basically, I want an alias that is like "goweb" that will open my default browser to the current branch on GitHub. I'm fine assuming a particular repo. Maybe a later enhancement would pull that as well using, e.g., default remote or the like..
Another approach is to use the GitHub command-line gh, specifically gh browse, introduced with Gh 1.12.0 (June 2021)
Open the GitHub repository in the web browser.
gh browse [<number> | <path>] [flags]
Example
$ gh browse main.go --branch main
# => Open main.go in the main branch
If you just want the remote URL, add the --no-browser option.
GitHub CLI 2.1.0 (oct. 2021) brings a feature to open the latest commit of a branch in gh browse
-c, --commit Open the last commit
--branch supports SHAs, -n prints only a URL, and -c links t o the latest commit.
This answer hard-codes the repo URL and just appends the current branch. Add this to your user-aliases.cmd (if using cmdr) or wherever you can set aliases.
goweb=#echo off && for /f %i in ('git rev-parse --abbrev-ref HEAD') do start https://<pathToRepo>/tree/%i
Replace with the URL to your repo.
Once this is in there, you can just type goweb from your CLI and it should open it for ya. Saves a few clicks when you need to do something on your current branch on GH.

how to update the vendor folder for https://github.com/hashicorp/terraform.git for terraform

Hi i am following steps given for hashicorp/terraform and performed below activity
# Get latest master branch's dependencies staged in local $GOPATH
git checkout master
git pull
godep restore -v
# Make your way to the dependency in question and checkout the target ref
pushd $GOPATH/src/github.com/some/dependency
git checkout [latest]
# Head back to Terraform on a feature branch and update the dependncy to the
# version currently in your $GOPATH
popd
git checkout my-feature-branch
godep update github.com/...
after this i can see my Godep.json file has been updated however i dont see changes in the vendor folder . it still points to old. Well i am looking emr support from vendor for that i am updating go-aws-sdk which is available with the latest go-aws-sdk. when i called go update github.com/... it has modified the godep.json but not vendor folder .
Could somebody please let me know the reason. Thanks
You have to do a godep restore -v again. update only updates the dependency in the Godep.json file.

golang and godep : Build\install after a golang dependency update when using godep?

I have followed the instructions # https://github.com/tools/godep regarding updating a dependency but when I go to build\install using the altered version it has not been updated within Godeps/_workspace/pkg
So I have
go get github.com/golang/glog
godep save
godep go install
and I can see
The modification timestamp in Godeps/_workspace/pkg/linux_amd64/github.com/golang/glog.a
The rev commit value in Godeps/Godeps.json
but now when I want to update I follow the instructions
go get github.com/golang/glog
godep update github.com/golang/glog
godep go install
I observe the following
The Godeps/Godeps.json rev commit has been updated
Godeps/_workspace/src/github.com/golang/ source is updated
But the file timestamp for odeps/_workspace/pkg/linux_amd64/github.com/golang/glog.a is not updated hence we are using the previous version
I believe I should add a .gitignore entry for pkg and bin, which means we would do a clean build on a fresh git clone
I know I could do a rm -r on both the pkg and bin directories before the godep go install command
Is this expected behavior ?
Thanks in advance
Pat
FYI
Since golang v1.4 I can now use the -a flag for the go install command, since it now longer tries to rebuild the standard library, see the v1.4 release notes section on the change to the build -a flag
Obviously this does not apply in pre v1.4 as it will attempt to rebuild the standard library packages

Resources