Running Commands with Contexts

Powerful Command-Line Applications in Go — by Ricardo Gerardi (66 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Handling Output from External Pr ograms | TOC | Integration Tests with a Local G it Server 👉

The final step your Go CI has to perform is pushing code changes to the remote Git repository. For this step, you’ll use some concepts from the Git Version Control System, such as, commits, local and remote repositories, branches, and pushing commits to remote repositories. If you need more information about these concepts, take a look at Git’s official documentation.[34] If you want to try this tool locally, you’ll also need Git installed on your machine.

To push code you’ll add another step to your pipeline to execute the command git with the appropriate options. For now, let’s simplify it and assume that we’re pushing code to the remote repo identified by origin using the branch master. The complete command is git push origin master.

You could implement this feature by adding another step using the existing step type with the necessary options. But in this case, this command will try to push the code to a remote repository over the network — and potentially over the Internet. If there’s a network issue, it could cause the command to hang which would cause the goci tool to hang. If you’re executing the goci tool manually it’s not too bad as you can cancel its execution after a while, but if you’re running it as part of an automation process or script, this is an…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.