Index a Go repository
This page describes how you can use scip-go and src-cli to enable precise indexing for Go codebases.
GitHub Actions
sourcegraph/scip-go-action can be used to index a Go repository using GitHub Actions.
The action installs the latest versions of src-cli and scip-go and relies on setup of a go environment to build your application, prior to running.
If your Sourcegraph instance enforces GitHub validation (lsifEnforceAuth), add -github-token=<token> to the src code-intel upload command.
Use a GitHub App installation access token when available, or fall back to a GitHub user token (classic PAT or fine-grained token) with public_repo scope and ADMIN, MAINTAIN, or WRITE access to the repository.
YAMLname: scip-go on: push: permissions: contents: read jobs: scip-go: steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v6 - name: Sourcegraph Code Intelligence uses: sourcegraph/scip-go-action@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} scip-go-version: latest sourcegraph-url: https://sourcegraph.com/ sourcegraph-token: ${{ secrets.SRC_ACCESS_TOKEN }} upload: true
CI/CD Integrations and Local Indexing
For integration with other CI/CD systems, or to test precise indexing of an individual repository, the following instructions can be used
to install and run scip-go and src-cli.
For general CI patterns (sub-projects, custom build environments, and upload frequency), see Adding precise code navigation to CI/CD workflows.
Setup
- Install the Go SCIP indexer:
SHELLgo install github.com/sourcegraph/scip-go/cmd/scip-go@latest
- Install the Sourcegraph CLI:
SHELLcurl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src chmod +x /usr/local/bin/src
- macOS: Replace
linuxwithdarwinin the URL and choose the appropriate architecture: M1/M2 chips -arm64, Intel chips -amd64. - Windows: Visit the CLI repo for further instructions.
Indexing
cdinto your Go project's root (where thego.modfile lives, if you have one) and run:
SHELLscip-go # generates a file named index.scip
If you have multiple go modules, run scip-go at the root of each module and adjust
the src code-intel upload command with the appropriate -root flag for each generated index.scip file.
- Upload the data to a Sourcegraph instance with:
SHELLexport SRC_ENDPOINT="YOUR_SOURCEGRAPH_URL" export SRC_ACCESS_TOKEN="YOUR_SOURCEGRAPH_API_TOKEN" cd path/to/index.scip src code-intel upload
The upload command will provide a URL you can visit to see the upload status.