Using Private Go Modules with golangci-lint in GitHub Actions
If you’re working with private Go modules and using
golangci-lint in your CI pipeline, you’ve probably hit the
authentication wall. Here’s how to solve it cleanly in GitHub
Actions.
The Problem
When golangci-lint runs in GitHub Actions, it needs to
fetch your private Go modules. By default, go commands
can’t access private repositories without proper authentication.
The Solution
Configure GOPRIVATE and set up Git credentials before
running the linter.
- name: Configure git for private modules
run: |
git config --global url."https://${{ secrets.GH_TOKEN }}@github.com/".insteadOf "https://github.com/"
- name: Set GOPRIVATE
run: echo "GOPRIVATE=github.com/your-org/*" >> $GITHUB_ENV
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
Key Takeaways
- Always set
GOPRIVATEto skip the Go module proxy for your private repos - Use
insteadOfgit config to inject authentication tokens - Place the git configuration step before any Go-related steps
This approach keeps your CI pipeline clean and avoids leaking credentials.
← Back to all posts