Tutorial: Adding precise indexing to many repositories
- You have a private Sourcegraph instance (i.e., you're not usingSourcegraph.com), and the repositories you wish to explore have been added tothat instance.
- You have admin access on your Sourcegraph instance.
- You have installed
src-clito your local machine.
- You have the ability to create org-level secrets in your GitHub organization.
- Your Sourcegraph instance is accessible from your GitHub instance. If you areusing GitHub.com, this means your Sourcegraph instance is accessible on thepublic Internet.
Watch the video or follow the written directions below:
Generate an access token for your Sourcegraph instance. The access token doesNOT need
sudoprivileges, but should have permission to read everyrepository for which precise indexing should be enabled.
Create the following secrets in each GitHub organization represented in theset of repositories. Follow the GitHubdocumentation for doing this.
srcEndpoint: the URL of the Sourcegraph instance, from the perspectiveof the GitHub instance. If using GitHub.com, this is just the URL you useto access Sourcegraph.
srcAccessToken: the Sourcegraph access token you just created.
lsif-go.campaign.yamlto your local machine.
Verify the list of repositories for which you wish to enable precise indexing:
# Use the values you set in your GitHub secrets for SRC_ENDPOINT and SRC_ACCESS_TOKEN SRC_ENDPOINT= SRC_ACCESS_TOKEN= src batch repositories -f lsif-go.campaign.yaml
If the set of repositories displayed is not the set of repositories for which you want to enable precise indexing, modify the
lsif-go.campaign.yamlto specify the Sourcegraph search query that selects the desired repository set.
Execute the batch spec to generate a list of all pull requests that will be created:
# Use the values you set in your GitHub secrets for SRC_ENDPOINT and SRC_ACCESS_TOKEN. SRC_ENDPOINT= SRC_ACCESS_TOKEN= src batch preview -f lsif-go.campaign.yaml
This will create a batch change preview in Sourcegraph. Navigate to the URL printed in theterminal to preview all the pull requests that will be created.
Once you've verified the preview looks correct, change
lsif-go.campaign.yamland run the following:
# Use the values you set in your GitHub secrets for SRC_ENDPOINT and SRC_ACCESS_TOKEN. SRC_ENDPOINT= SRC_ACCESS_TOKEN= src batch apply -f lsif-go.campaign.yaml
Now, go back to the batch change page and verify the pull requests have beencreated.
If there are errors creating any pull request, check to make sure the GitHub token in theSourcegraph code host configuration (Site admin > Manage code hosts) has thenecessary scopes (
Verify that the GitHub action has run successfully in the repositories on GitHub.
Verify that the index has been successfully uploaded to Sourcegraph bynavigating to any repository page on Sourcegraph > Settings > Codeintelligence: Uploads. You should also be able to explore the code at thatrevision with precise code navigation.
Merge the pull requests created by the batch change and close the batchchange. The GitHub action should now run on each push, generating an index for thepushed revision and uploading it to your Sourcegraph instance.