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.

YAML
name: 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

  1. Install the Go SCIP indexer:
SHELL
go install github.com/sourcegraph/scip-go/cmd/scip-go@latest
  1. Install the Sourcegraph CLI:
SHELL
curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src chmod +x /usr/local/bin/src
  • macOS: Replace linux with darwin in the URL and choose the appropriate architecture: M1/M2 chips - arm64, Intel chips - amd64.
  • Windows: Visit the CLI repo for further instructions.

Indexing

  1. cd into your Go project's root (where the go.mod file lives, if you have one) and run:
SHELL
scip-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.

  1. Upload the data to a Sourcegraph instance with:
SHELL
export 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.