DEV Community

Alex Rios
Alex Rios

Posted on

11 2

How to use your private Go lib in Github Actions

In this tutorial I'll use the fictional private repository called github.com/alexrios/superlib at the version v1.1.0

Backing story

During the Continuous integration pipeline executing go mod tidy I was getting this error:

go: github.com/alexrios/superlib@v1.1.0: reading github.com/alexrios/superlib/go.mod at revision v1.1.0: unknown revision v1.1.0
Enter fullscreen mode Exit fullscreen mode

Why?

In order to understand how Go uses a VCS to handle dependencies I recommend this Go team blog post: https://blog.golang.org/publishing-go-modules

Solution

Generate a token with read permission on org or user repositories and setup a substitution in git global configurations.

That way the authenticated form will always be used.

I highly recommend you to use the repository secrets to avoid exposing sensible data, in this case, the token.

- name: Granting private modules access
        run: |
          git config --global url."https://${{ secrets.GO_MODULES_TOKEN }}:x-oauth-basic@github.com/alexrios".insteadOf "https://github.com/alexrios"     
Enter fullscreen mode Exit fullscreen mode

more on declaring and using secrets: https://help.github.com/pt/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (4)

Collapse
 
renanbastos93 profile image
renanbastos93

Hey dude, thanks a lot you safe my life, nice article.

Collapse
 
stardustman profile image
stardust

great

Collapse
 
br3nda profile image
Shiny • Edited

what kind of token is GO_MODULES_TOKEN

Collapse
 
alextrending profile image
Alex Rios

It could be any token that grants you the access. Eg.: docs.github.com/en/github/authenti...

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay