You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DEVELOPMENT.md
+57-17Lines changed: 57 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff 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
+
1
10
## Development
2
11
3
12
If you want to develop the CLI, clone the repository and build/install it with `go install`
@@ -7,6 +16,44 @@ cd src-cli/
7
16
go install ./cmd/src
8
17
```
9
18
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
+
10
57
## Releasing
11
58
12
59
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
39
86
40
87
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.
41
88
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
43
97
44
98
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/).
45
99
46
100
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.
47
101
48
102
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.
49
103
50
-
### Testing
104
+
####Testing the Docker image
51
105
52
106
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:
53
107
@@ -63,7 +117,7 @@ docker run --rm local-src-cli
63
117
64
118
and get the normal help output from `src`.
65
119
66
-
## Dependent Docker images
120
+
###Dependent Docker images
67
121
68
122
`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).
69
123
@@ -78,17 +132,3 @@ To remove it and then force the upstream image on Docker Hub to be used again:
## 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.
0 commit comments