Skip to content

Commit 22898ff

Browse files
doc: improve developer docs (#553)
Co-authored-by: Kelli Rockwell <kellirockwell@gmail.com>
1 parent 36604c0 commit 22898ff

2 files changed

Lines changed: 61 additions & 17 deletions

File tree

DEVELOPMENT.md

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
This file covers things that are good to know if you're developing or maintaining `src`. It is likely incomplete, and contributions would be most welcome!
2+
3+
## Contents
4+
5+
* [Developing `src`](#development)
6+
* [Testing `src`](#testing)
7+
* [Releasing `src`](#releasing)
8+
* [How we use Docker](#docker)
9+
110
## Development
211

312
If you want to develop the CLI, clone the repository and build/install it with `go install`
@@ -7,6 +16,44 @@ cd src-cli/
716
go install ./cmd/src
817
```
918

19+
You can also run it directly without installation:
20+
21+
```
22+
go run ./cmd/src
23+
```
24+
25+
### Use `debug` build tag to debug batch changes functionality
26+
27+
Since `src batch apply` and `src batch preview` start up a TUI that gets updated repeatedly it's nearly impossible to do printf-debugging by printing debug information - the TUI would hide those or overwrite them.
28+
29+
To help with that, you can compile your src binary (or run the tests) with the `debug` build flag:
30+
31+
```
32+
go build -tags debug -o ~/src ./cmd/src
33+
```
34+
35+
This will cause the `./internal/batches/debug.go` file to be included in the build. In that file the `log` default package logger is setup to log to `~/.sourcegraph/src-cli.debug.log`.
36+
37+
That allows you to `tail -f ~/.sourcegraph/src-cli.debug.log` and use `log.Println()` in your code to debug.
38+
39+
## Testing
40+
41+
`src` uses normal Go testing patterns, and doesn't require any other dependencies for its test suite to be run.
42+
43+
You can test the entire tool with:
44+
45+
```sh
46+
go test ./...
47+
```
48+
49+
Or just a single package with:
50+
51+
```sh
52+
go test ./internal/batches/workspace
53+
```
54+
55+
We adhere to the [general Sourcegraph principles for testing](https://docs.sourcegraph.com/dev/background-information/testing_principles), as well as [the Go specific directions](https://docs.sourcegraph.com/dev/background-information/languages/testing_go_code), at least to the extent they apply to a standalone tool like `src`.
56+
1057
## Releasing
1158

1259
1. If this is a non-patch release, update the changelog. Add a new section `## $MAJOR.MINOR` to [`CHANGELOG.md`](https://github.com/sourcegraph/src-cli/blob/main/CHANGELOG.md#unreleased) immediately under `## Unreleased changes`. Add new empty `Added`, `Changed`, `Fixed`, and `Removed` sections under `## Unreleased changes`.
@@ -39,15 +86,22 @@ If a new feature is added to a new `3.91.6` release of src-cli and this change r
3986

4087
Note that if instead the recommended src-cli version for Sourcegraph `3.99` was `3.90.4` in the example above, there is no additional step required, and the new patch version of src-cli will be available to both Sourcegraph versions.
4188

42-
## `src-cli` Docker image
89+
## Docker
90+
91+
We use Docker in a couple of different ways:
92+
93+
* `src` is pushed to [`sourcegraph/src-cli`](https://hub.docker.com/r/sourcegraph/src-cli) each [release](#releasing). More information on this [can be found below](#src-cli-docker-image).
94+
* `src` uses [`sourcegraph/src-batch-change-volume-workspace`](https://hub.docker.com/r/sourcegraph/src-batch-change-volume-workspace) when executing batch changes on the `volume` workspace, which is the default on macOS. This image is also updated on [release](#releasing). More information on this [can also be found below](#dependent-docker-images).
95+
96+
### `src-cli` Docker image
4397

4498
Each release of `src` results in a new tag of the [`sourcegraph/src-cli` Docker image](https://hub.docker.com/r/sourcegraph/src-cli) being pushed to Docker Hub. This is handled by [goreleaser's Docker support](https://goreleaser.com/customization/docker/).
4599

46100
The main gotcha here is that the way goreleaser builds the Docker image is fairly difficult to replicate from the desktop: it builds a `src` binary without any runtime libc dependencies that can be installed in a `scratch` image, but unless you work on Alpine, your desktop is _not_ configured to build Go binaries like that.
47101

48102
As a result, there are two Dockerfiles in this project. goreleaser uses `Dockerfile.release`, which is replicated in a multi-stage `Dockerfile` that builds `src` in a builder container to ensure it's built in a way that can be tested.
49103

50-
### Testing
104+
#### Testing the Docker image
51105

52106
If you need to test a change to the Dockerfile (for example, due to a Renovate PR bumping the base image), you should pull that change, then build a local image with something like:
53107

@@ -63,7 +117,7 @@ docker run --rm local-src-cli
63117

64118
and get the normal help output from `src`.
65119

66-
## Dependent Docker images
120+
### Dependent Docker images
67121

68122
`src batch apply` and `src batch preview` use a Docker image published as `sourcegraph/src-batch-change-volume-workspace` for utility purposes when the volume workspace is selected, which is the default on macOS. This [Docker image](./docker/batch-change-volume-workspace/Dockerfile) is built by [a Python script](./docker/batch-change-volume-workspace/push.py) invoked by the GitHub Action workflow described in [`docker.yml`](.github/workflows/docker.yml).
69123

@@ -78,17 +132,3 @@ To remove it and then force the upstream image on Docker Hub to be used again:
78132
```sh
79133
docker rmi sourcegraph/src-batch-change-volume-workspace
80134
```
81-
82-
## Use `debug` build tag to debug batch changes functionality
83-
84-
Since `src batch apply` and `src batch preview` start up a TUI that gets updated repeatedly it's nearly impossible to do printf-debugging by printing debug information - the TUI would hide those or overwrite them.
85-
86-
To help with that you can compile your src binary (or run the tests) with the `debug` build flag:
87-
88-
```
89-
go build -tags debug -o ~/src ./cmd/src
90-
```
91-
92-
This will cause the `./internal/batches/debug.go` file to be included in the build. In that file the `log` default package logger is setup to log to `~/.sourcegraph/src-cli.debug.log`.
93-
94-
That allows you to `tail -f ~/.sourcegraph/src-cli.debug.log` and use `log.Println()` in your code to debug.

README.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,7 @@ mv /usr/local/bin/src /usr/local/bin/src-cli
126126
```
127127

128128
You can then invoke it via `src-cli`.
129+
130+
## Development
131+
132+
Some useful notes on developing `src` can be found in [DEVELOPMENT.md](DEVELOPMENT.md).

0 commit comments

Comments
 (0)