# Index a Go repository

<p className="subtitle">
	This page describes how you can use [scip-go](https://github.com/sourcegraph/scip-go) and [src-cli](https://github.com/sourcegraph/src-cli) to enable precise indexing for Go codebases.
</p>

## GitHub Actions

[sourcegraph/scip-go-action](https://github.com/sourcegraph/scip-go-action) can be used to index a Go repository using GitHub Actions.

The action installs the latest versions of [src-cli](https://github.com/sourcegraph/src-cli) and [scip-go](https://github.com/sourcegraph/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`.

<Callout type="info">
	For general CI patterns (sub-projects, custom build environments, and upload frequency), see [Adding precise code navigation to CI/CD workflows](/code-navigation/how-to/adding-scip-to-workflows).
</Callout>

### Setup

1. Install the [Go SCIP indexer](https://github.com/sourcegraph/scip-go):

```shell
go install github.com/sourcegraph/scip-go/cmd/scip-go@latest
```

2. Install the [Sourcegraph CLI](https://github.com/sourcegraph/src-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](https://github.com/sourcegraph/src-cli) 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
```

<Callout type="note">
	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.
</Callout>

2. 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.

