| 1 |
# genbot |
| 2 |
|
| 3 |
genbot is a binary for generating gapics and creating PRs with the results. |
| 4 |
It is intended to be used as a bot, though it can be run locally too. |
| 5 |
|
| 6 |
## Prerequisites for running locally |
| 7 |
|
| 8 |
Note that only step one, listed below, is required if you plan to run the code |
| 9 |
in docker. |
| 10 |
|
| 11 |
1. Clone this project: `git clone https://github.com/googleapis/google-cloud-go.git` |
| 12 |
1. Install [protoc](https://github.com/protocolbuffers/protobuf/releases) |
| 13 |
1. Install [Go](http://golang.org/dl) |
| 14 |
1. Add `$GOPATH/bin` to `PATH` |
| 15 |
1. Create a [GitHub access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). |
| 16 |
1. Install Go tools: |
| 17 |
|
| 18 |
```bash |
| 19 |
go get \ |
| 20 |
github.com/golang/protobuf/protoc-gen-go \ |
| 21 |
golang.org/x/lint/golint \ |
| 22 |
golang.org/x/tools/cmd/goimports \ |
| 23 |
honnef.co/go/tools/cmd/staticcheck \ |
| 24 |
github.com/googleapis/gapic-generator-go/cmd/protoc-gen-go_gapic |
| 25 |
``` |
| 26 |
|
| 27 |
## Generating code and PRs(bot mode) |
| 28 |
|
| 29 |
### Run genbot locally |
| 30 |
|
| 31 |
Note: this may change your `~/.gitconfig`, `~/.gitcookies`, and use up |
| 32 |
non-trivial amounts of space on your computer. |
| 33 |
|
| 34 |
1. Make sure you are on a non-Windows platform. If you are using windows |
| 35 |
continue on to the docker instructions. |
| 36 |
1. Make sure you have all the tools installed listed in genlocal's README.md |
| 37 |
1. Run: |
| 38 |
|
| 39 |
```shell |
| 40 |
cd /path/to/internal/gapicgen |
| 41 |
go run cloud.google.com/go/internal/gapicgen/cmd/genbot \ |
| 42 |
--githubAccessToken=$GITHUB_ACCESS_TOKEN \ |
| 43 |
--githubUsername=$GITHUB_USERNAME \ |
| 44 |
--githubName="Jean de Klerk" \ |
| 45 |
[email protected] \ |
| 46 |
``` |
| 47 |
|
| 48 |
### Run genbot with docker |
| 49 |
|
| 50 |
Note: this can be quite slow (~10m). |
| 51 |
|
| 52 |
Note: this may leave a lot of docker resources laying around. Use |
| 53 |
`docker system prune` to clean up after runs. |
| 54 |
|
| 55 |
```shell |
| 56 |
cd /path/to/internal/gapicgen/cmd/genbot |
| 57 |
docker build . -t genbot |
| 58 |
docker run -t --rm --privileged \ |
| 59 |
-v `pwd`/../..:/gapicgen \ |
| 60 |
-e GITHUB_ACCESS_TOKEN \ |
| 61 |
-e GITHUB_USERNAME \ |
| 62 |
-e GITHUB_NAME \ |
| 63 |
-e GITHUB_EMAIL \ |
| 64 |
genbot |
| 65 |
``` |
| 66 |
|
| 67 |
## Generating code (local mode) |
| 68 |
|
| 69 |
Sometimes you may want to just generate gapic sources to test out |
| 70 |
new changes, test the generation of a new library, test new generator tweaks, |
| 71 |
run generators against googleapis-private, and various other local tasks. The |
| 72 |
local mode in genbot allows you to do just that. |
| 73 |
|
| 74 |
### Run genbot(local mode) locally |
| 75 |
|
| 76 |
```shell |
| 77 |
cd /path/to/internal/gapicgen |
| 78 |
go run cloud.google.com/go/internal/gapicgen/cmd/genbot \ |
| 79 |
-local \ |
| 80 |
-only-gapics \ |
| 81 |
-gocloud-dir=/path/to/google-cloud-go \ |
| 82 |
-gapic=cloud.google.com/go/foo/apiv1 |
| 83 |
``` |
| 84 |
|
| 85 |
### Run genbot(local mode) with docker |
| 86 |
|
| 87 |
```shell |
| 88 |
cd /path/to/internal/gapicgen |
| 89 |
docker build -t genbot -f cmd/genbot/Dockerfile . |
| 90 |
docker run --rm \ |
| 91 |
-v `pwd`/../..:/gapicgen \ |
| 92 |
-e GENBOT_LOCAL_MODE=true \ |
| 93 |
-e ONLY_GAPICS=true \ |
| 94 |
-e GOCLOUD_DIR=/gapicgen \ |
| 95 |
-e GAPIC_TO_GENERATE=cloud.google.com/go/foo/apiv1 \ |
| 96 |
genbot |
| 97 |
``` |
| 98 |
|
| 99 |
Note you can optionally mount in your Go module cache if you have Go installed. |
| 100 |
This will speed up the build a bit: |
| 101 |
|
| 102 |
```shell |
| 103 |
-v `go env GOMODCACHE`:/root/go/pkg/mod |
| 104 |
``` |
| 105 |
|
| 106 |
### Generating new stubs |
| 107 |
|
| 108 |
Flip status in aliasfix for gapics being migrated to in progress. |
| 109 |
|
| 110 |
```shell |
| 111 |
cd /path/to/internal/gapicgen |
| 112 |
go run cloud.google.com/go/internal/gapicgen/cmd/genbot \ |
| 113 |
-local \ |
| 114 |
-only-gapics \ |
| 115 |
-gocloud-dir=/path/to/google-cloud-go \ |
| 116 |
-gapic=cloud.google.com/go/foo/apiv1 |
| 117 |
``` |
| 118 |
|
| 119 |
## FAQ |
| 120 |
|
| 121 |
### How to bump to a later version of the microgenerator |
| 122 |
|
| 123 |
```shell |
| 124 |
cd /path/to/internal/gapicgen |
| 125 |
go get -d github.com/googleapis/gapic-generator-go/cmd/protoc-gen-go_gapic |
| 126 |
``` |
| 127 |
|
| 128 |
(it's just based on the go.mod entry) |