├── LICENSE.txt ├── README.md ├── cmd └── cli.go ├── examples └── hello-world.pipeline.yml ├── go.mod ├── go.sum ├── main.go └── runner ├── agent.go ├── debug.go ├── emoji.go ├── pipeline.go ├── pipeline_test.go ├── plugins.go ├── run.go ├── server.go ├── server_test.go └── writer.go /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2014-2021 Buildkite Pty Ltd and Lachlan Donald 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bkl - Run Buildkite Pipelines locally 2 | 3 | Run buildkite pipelines locally (no buildkite.com required). 4 | 5 | ## Installing 6 | 7 | Either download a release binary or if you have golang: 8 | 9 | ```bash 10 | go install github.com/lox/bkl@latest 11 | ``` 12 | 13 | ## Running 14 | 15 | ```bash 16 | $ bkl 17 | 18 | >>> Starting local agent 🤖 19 | >>> Starting build 👟 20 | >>> Executing initial command: buildkite-agent pipeline upload "/Users/lachlan/Projects/lox/bkl/examples/hello-world.pipeline.yml" 21 | >>> Executing command step 22 | 23 | ~~~ Preparing plugins 24 | $ cd /Users/lachlan/Projects/lox/bkl 25 | 26 | ~~~ Running commands 27 | $ trap 'kill -- $$' INT TERM QUIT; echo hello world! 28 | hello world! 29 | 30 | >>> Command succeeded in 3.047168424s 31 | >>> Build finished in 3.051489877s 32 | ``` 33 | 34 | ## What is working 35 | 36 | * [x] Pipeline uploads (converting a pipeline.yml into steps) 37 | * [x] Artifact upload, download, exists 38 | * [x] Metadata set, get, exists 39 | * [x] Basic plugin support 40 | 41 | ## What isn't working 42 | 43 | * [ ] Input steps 44 | * [ ] `If` conditionals 45 | * [ ] Vendored plugins 46 | * Basically anything Buildkite has done since 2019. 47 | 48 | ## Credit 49 | 50 | Extracted from https://github.com/buildkite/cli. 51 | 52 | P.S. @toolmantim, you were right. This always should have been a standalone tool. Soz. 53 | -------------------------------------------------------------------------------- /cmd/cli.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "os" 8 | "os/exec" 9 | "os/signal" 10 | "path/filepath" 11 | "regexp" 12 | "strings" 13 | 14 | "github.com/alecthomas/kong" 15 | "github.com/lox/bkl/runner" 16 | ) 17 | 18 | type CLI struct { 19 | Debug bool `help:"Whether to show logging"` 20 | DebugHTTP bool `help:"Whether to show http logging"` 21 | File *os.File `help:"The buildkite pipeline file to read"` 22 | Env []string `help:"Environment variables to set for the build"` 23 | Metadata map[string]string `help:"Metadata to set for the build"` 24 | Command string `help:"A command to execute"` 25 | StepFilterRegex string `help:"A regex to filter which steps are run"` 26 | Prompt bool `help:"Prompt before running steps"` 27 | DryRun bool `help:"Dry run, don't actually run"` 28 | ListenPort int `help:"The port to run on"` 29 | } 30 | 31 | func (c *CLI) Run(ctx *kong.Context) error { 32 | quit := make(chan os.Signal, 1) 33 | signal.Notify(quit, os.Interrupt) 34 | 35 | cancelCtx, cancel := context.WithCancel(context.Background()) 36 | defer cancel() 37 | 38 | go func() { 39 | <-quit 40 | fmt.Printf("\n>>> Gracefully shutting down...\n") 41 | cancel() 42 | }() 43 | 44 | wd, err := os.Getwd() 45 | if err != nil { 46 | return err 47 | } 48 | 49 | commit, err := gitCommit() 50 | if err != nil { 51 | log.Printf("Error getting git commit: %v", err) 52 | commit = "no_commit_found" 53 | } 54 | 55 | branch, err := gitBranch() 56 | if err != nil { 57 | log.Printf("Error getting git branch: %v", err) 58 | branch = "master" 59 | } 60 | 61 | command := c.Command 62 | if c.File != nil { 63 | command = fmt.Sprintf("buildkite-agent pipeline upload %q", c.File.Name()) 64 | } 65 | 66 | stepFilterReg, err := regexp.Compile(c.StepFilterRegex) 67 | if err != nil { 68 | return err 69 | } 70 | 71 | return runner.Run(cancelCtx, runner.Params{ 72 | Debug: c.Debug, 73 | DebugHTTP: c.DebugHTTP, 74 | Env: c.Env, 75 | Metadata: c.Metadata, 76 | DryRun: c.DryRun, 77 | Command: command, 78 | Dir: wd, 79 | Prompt: c.Prompt, 80 | StepFilter: stepFilterReg, 81 | ListenPort: c.ListenPort, 82 | JobTemplate: runner.Job{ 83 | Commit: commit, 84 | Branch: branch, 85 | Repository: wd, 86 | OrganizationSlug: "local", 87 | PipelineSlug: filepath.Base(wd), 88 | }, 89 | }) 90 | } 91 | 92 | func gitBranch() (string, error) { 93 | out, err := exec.Command(`git`, `rev-parse`, `--abbrev-ref`, `HEAD`).Output() 94 | if err != nil { 95 | return "", err 96 | } 97 | return strings.TrimSpace(string(out)), nil 98 | } 99 | 100 | func gitCommit() (string, error) { 101 | out, err := exec.Command(`git`, `rev-parse`, `HEAD`).Output() 102 | if err != nil { 103 | return "", err 104 | } 105 | return strings.TrimSpace(string(out)), nil 106 | } 107 | -------------------------------------------------------------------------------- /examples/hello-world.pipeline.yml: -------------------------------------------------------------------------------- 1 | steps: 2 | - command: "echo hello world!" 3 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/lox/bkl 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/ahmetb/go-cursor v0.0.0-20131010032410-8136607ea412 7 | github.com/alecthomas/kong v0.2.18 8 | github.com/bmatcuk/doublestar v1.3.4 9 | github.com/briandowns/spinner v1.16.0 10 | github.com/buildkite/cli v1.2.0 11 | github.com/fatih/color v1.13.0 12 | github.com/go-test/deep v1.0.8 13 | github.com/google/go-github v17.0.0+incompatible 14 | github.com/manifoldco/promptui v0.9.0 15 | github.com/mitchellh/go-homedir v1.1.0 16 | github.com/sahilm/fuzzy v0.1.0 17 | github.com/satori/go.uuid v1.2.0 18 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 19 | golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 20 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 21 | ) 22 | 23 | require ( 24 | github.com/99designs/keyring v1.1.6 // indirect 25 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect 26 | github.com/danieljoos/wincred v1.0.2 // indirect 27 | github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b // indirect 28 | github.com/godbus/dbus v4.1.0+incompatible // indirect 29 | github.com/golang/protobuf v1.4.2 // indirect 30 | github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect 31 | github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect 32 | github.com/keybase/go-keychain v0.0.0-20191022214133-1c06e666bc46 // indirect 33 | github.com/mattn/go-colorable v0.1.9 // indirect 34 | github.com/mattn/go-isatty v0.0.14 // indirect 35 | github.com/mtibben/percent v0.2.1 // indirect 36 | github.com/pkg/errors v0.9.1 // indirect 37 | github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c // indirect 38 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect 39 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect 40 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect 41 | google.golang.org/appengine v1.6.6 // indirect 42 | google.golang.org/protobuf v1.25.0 // indirect 43 | ) 44 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= 4 | cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= 5 | cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= 6 | cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= 7 | cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= 8 | cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= 9 | cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= 10 | cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= 11 | cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= 12 | cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= 13 | cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= 14 | cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= 15 | cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= 16 | cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= 17 | cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= 18 | cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= 19 | cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= 20 | cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= 21 | cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= 22 | cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= 23 | cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= 24 | cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= 25 | cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= 26 | cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= 27 | cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= 28 | cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= 29 | cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= 30 | cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= 31 | cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= 32 | cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= 33 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 34 | github.com/99designs/keyring v1.1.6 h1:kVDC2uCgVwecxCk+9zoCt2uEL6dt+dfVzMvGgnVcIuM= 35 | github.com/99designs/keyring v1.1.6/go.mod h1:16e0ds7LGQQcT59QqkTg72Hh5ShM51Byv5PEmW6uoRU= 36 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 37 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 38 | github.com/ahmetb/go-cursor v0.0.0-20131010032410-8136607ea412 h1:mjEdk5IWaOUyDfmIScVahVtW56YQ1gBv8RMyHl69Z30= 39 | github.com/ahmetb/go-cursor v0.0.0-20131010032410-8136607ea412/go.mod h1:6/fH+MoHXlGOc3iy8TSNB4eM1oaBDMs1oxPVN40M3h0= 40 | github.com/alecthomas/kong v0.2.18 h1:H05f55eRO5f9gusObxgjpqKtozJNvniqMTuOPnf+2SQ= 41 | github.com/alecthomas/kong v0.2.18/go.mod h1:ka3VZ8GZNPXv9Ov+j4YNLkI8mTuhXyr/0ktSlqIydQQ= 42 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 43 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 44 | github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= 45 | github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0= 46 | github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= 47 | github.com/briandowns/spinner v0.0.0-20170614154858-48dbb65d7bd5/go.mod h1:hw/JEQBIE+c/BLI4aKM8UU8v+ZqrD3h7HC27kKt8JQU= 48 | github.com/briandowns/spinner v1.16.0 h1:DFmp6hEaIx2QXXuqSJmtfSBSAjRmpGiKG6ip2Wm/yOs= 49 | github.com/briandowns/spinner v1.16.0/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX3FScO+3/ZPQ= 50 | github.com/buildkite/cli v1.2.0 h1:Zm2/o5aUUl//KrtOgpvCes+EUVHQeyF2xvCLTivvTko= 51 | github.com/buildkite/cli v1.2.0/go.mod h1:xdGswkUVNqJe1T2n09i52lRnJX1HvAZwsgbRY5fhLKk= 52 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 53 | github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= 54 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= 55 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= 56 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= 57 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= 58 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= 59 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 60 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= 61 | github.com/danieljoos/wincred v1.0.2 h1:zf4bhty2iLuwgjgpraD2E9UbvO+fe54XXGJbOwe23fU= 62 | github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U= 63 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 64 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 65 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 66 | github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b h1:HBah4D48ypg3J7Np4N+HY/ZR76fx3HEUGxDU6Uk39oQ= 67 | github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM= 68 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 69 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 70 | github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 71 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 72 | github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= 73 | github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= 74 | github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= 75 | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= 76 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= 77 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= 78 | github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= 79 | github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= 80 | github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= 81 | github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= 82 | github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4= 83 | github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= 84 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 85 | github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 86 | github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 87 | github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 88 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 89 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 90 | github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= 91 | github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= 92 | github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= 93 | github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= 94 | github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= 95 | github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 96 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 97 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 98 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 99 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 100 | github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 101 | github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= 102 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 103 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 104 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 105 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 106 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 107 | github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= 108 | github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= 109 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 110 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 111 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 112 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 113 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 114 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 115 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 116 | github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 117 | github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 118 | github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k= 119 | github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 120 | github.com/google/go-github v15.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= 121 | github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= 122 | github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= 123 | github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 h1:zLTLjkaOFEFIOxY5BWLFLwh+cL8vOBW4XJ2aqLE/Tf0= 124 | github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= 125 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 126 | github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= 127 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 128 | github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 129 | github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 130 | github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 131 | github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 132 | github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 133 | github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 134 | github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 135 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 136 | github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= 137 | github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= 138 | github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= 139 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 140 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 141 | github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= 142 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 143 | github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= 144 | github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= 145 | github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= 146 | github.com/keybase/go-keychain v0.0.0-20191022214133-1c06e666bc46 h1:Sf/pnA7dyCXbGM4scY7MvmkRyHml+N35u7f9kx6+Wf0= 147 | github.com/keybase/go-keychain v0.0.0-20191022214133-1c06e666bc46/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= 148 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 149 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 150 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 151 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 152 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 153 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 154 | github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= 155 | github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= 156 | github.com/lunixbochs/vtclean v0.0.0-20170504063817-d14193dfc626/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= 157 | github.com/manifoldco/promptui v0.3.0/go.mod h1:zoCNXiJnyM03LlBgTsWv8mq28s7aTC71UgKasqRJHww= 158 | github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= 159 | github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= 160 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 161 | github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 162 | github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= 163 | github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 164 | github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 165 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 166 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 167 | github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= 168 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 169 | github.com/mattn/go-zglob v0.0.1/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo= 170 | github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= 171 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 172 | github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= 173 | github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= 174 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 175 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 176 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 177 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 178 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 179 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 180 | github.com/sahilm/fuzzy v0.0.5/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= 181 | github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI= 182 | github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= 183 | github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= 184 | github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= 185 | github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c h1:fyKiXKO1/I/B6Y2U8T7WdQGWzwehOuGIrljPtt7YTTI= 186 | github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= 187 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 188 | github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= 189 | github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= 190 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 191 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 192 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 193 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 194 | github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 195 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 196 | github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 197 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= 198 | go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= 199 | go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= 200 | go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= 201 | go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= 202 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 203 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 204 | golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 205 | golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 206 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 207 | golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 208 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 209 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= 210 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 211 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 212 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 213 | golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= 214 | golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= 215 | golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= 216 | golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= 217 | golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= 218 | golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= 219 | golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= 220 | golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= 221 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 222 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 223 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 224 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 225 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 226 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 227 | golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 228 | golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 229 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 230 | golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= 231 | golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= 232 | golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= 233 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= 234 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 235 | golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= 236 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 237 | golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 238 | golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 239 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 240 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 241 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 242 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 243 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 244 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 245 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 246 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 247 | golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 248 | golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 249 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 250 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 251 | golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 252 | golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 253 | golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 254 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 255 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 256 | golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 257 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 258 | golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 259 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 260 | golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 261 | golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 262 | golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 263 | golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 264 | golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 265 | golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 266 | golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 267 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= 268 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 269 | golang.org/x/oauth2 v0.0.0-20180529203656-ec22f46f877b/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 270 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 271 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 272 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 273 | golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 274 | golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 275 | golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 h1:RerP+noqYHUQ8CMRcPlC2nvTa4dcBIjegkuWdcUDuqg= 276 | golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= 277 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 278 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 279 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 280 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 281 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 282 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 283 | golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 284 | golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 285 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 286 | golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 287 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 288 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 289 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 290 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 291 | golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 292 | golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 293 | golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 294 | golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 295 | golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 296 | golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 297 | golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 298 | golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 299 | golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 300 | golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 301 | golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 302 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 303 | golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 304 | golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 305 | golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 306 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 307 | golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 308 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 309 | golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 310 | golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 311 | golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 312 | golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 313 | golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 314 | golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 315 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 316 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 317 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= 318 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 319 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= 320 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 321 | golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 322 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 323 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 324 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 325 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 326 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 327 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 328 | golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 329 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 330 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 331 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 332 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 333 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 334 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 335 | golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 336 | golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 337 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 338 | golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 339 | golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 340 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 341 | golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 342 | golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 343 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 344 | golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 345 | golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 346 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 347 | golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 348 | golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 349 | golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 350 | golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 351 | golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 352 | golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 353 | golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 354 | golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 355 | golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 356 | golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 357 | golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 358 | golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 359 | golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= 360 | golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= 361 | golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= 362 | golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 363 | golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 364 | golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 365 | golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 366 | golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= 367 | golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= 368 | golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= 369 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 370 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 371 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 372 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 373 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 374 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= 375 | google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= 376 | google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 377 | google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 378 | google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 379 | google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 380 | google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 381 | google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 382 | google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 383 | google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 384 | google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 385 | google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 386 | google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= 387 | google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= 388 | google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= 389 | google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= 390 | google.golang.org/appengine v1.0.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 391 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 392 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 393 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 394 | google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= 395 | google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 396 | google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc= 397 | google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 398 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 399 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 400 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 401 | google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 402 | google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 403 | google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 404 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 405 | google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= 406 | google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 407 | google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 408 | google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 409 | google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 410 | google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 411 | google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 412 | google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= 413 | google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 414 | google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 415 | google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 416 | google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 417 | google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 418 | google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 419 | google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 420 | google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 421 | google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= 422 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= 423 | google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= 424 | google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= 425 | google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= 426 | google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= 427 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 428 | google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= 429 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 430 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 431 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= 432 | google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 433 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 434 | google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 435 | google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= 436 | google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= 437 | google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= 438 | google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= 439 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 440 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 441 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 442 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 443 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 444 | google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 445 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 446 | google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 447 | google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= 448 | google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= 449 | google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= 450 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 451 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 452 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 453 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 454 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 455 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 456 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 457 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= 458 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 459 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 460 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 461 | honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 462 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 463 | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= 464 | honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= 465 | honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= 466 | rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= 467 | rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= 468 | rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= 469 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "os" 8 | "os/signal" 9 | "syscall" 10 | 11 | "github.com/alecthomas/kong" 12 | "github.com/lox/bkl/cmd" 13 | ) 14 | 15 | var ( 16 | version string // set by goreleaser 17 | ) 18 | 19 | func main() { 20 | ctx, cancel := context.WithCancel(context.Background()) 21 | c := make(chan os.Signal) 22 | signal.Notify(c, os.Interrupt, syscall.SIGTERM) 23 | go func() { 24 | <-c 25 | log.Println("Shutting down") 26 | signal.Stop(c) 27 | cancel() 28 | }() 29 | 30 | if err := run(ctx); err != nil { 31 | fmt.Printf("%+v\n", err) 32 | os.Exit(1) 33 | } 34 | } 35 | 36 | func run(ctx context.Context) error { 37 | cli := cmd.CLI{} 38 | 39 | k := kong.Parse(&cli, 40 | kong.Name("bkl"), 41 | kong.Description("Run your Buildkite pipelines locally (no buildkite.com interaction)"), 42 | kong.UsageOnError(), 43 | kong.ConfigureHelp(kong.HelpOptions{ 44 | Compact: true, 45 | }), 46 | kong.Vars{ 47 | "version": version, 48 | }) 49 | 50 | k.BindTo(ctx, (*context.Context)(nil)) 51 | return k.Run(&cli) 52 | } 53 | -------------------------------------------------------------------------------- /runner/agent.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | import ( 4 | "sync" 5 | 6 | "golang.org/x/xerrors" 7 | ) 8 | 9 | type agent struct { 10 | ID string 11 | AccessToken string 12 | Name string 13 | State string 14 | } 15 | 16 | type agentPool struct { 17 | sync.Mutex 18 | agents map[string]*agent 19 | } 20 | 21 | func newAgentPool() *agentPool { 22 | return &agentPool{ 23 | agents: map[string]*agent{}, 24 | } 25 | } 26 | 27 | func (ap *agentPool) Register(a agent) { 28 | ap.Lock() 29 | defer ap.Unlock() 30 | ap.agents[a.ID] = &a 31 | } 32 | 33 | func (ap *agentPool) Get(agentID string) (*agent, error) { 34 | ap.Lock() 35 | defer ap.Unlock() 36 | agent, ok := ap.agents[agentID] 37 | if !ok { 38 | return nil, xerrors.New("no agent found") 39 | } 40 | return agent, nil 41 | } 42 | 43 | func (ap *agentPool) Connect(agentID string) { 44 | ap.Lock() 45 | defer ap.Unlock() 46 | agent := ap.agents[agentID] 47 | agent.State = "connected" 48 | } 49 | 50 | func (ap *agentPool) Disconnect(agentID string) { 51 | ap.Lock() 52 | defer ap.Unlock() 53 | agent := ap.agents[agentID] 54 | agent.State = "disconnected" 55 | } 56 | 57 | func (ap *agentPool) Authenticate(accessToken string) (string, error) { 58 | ap.Lock() 59 | defer ap.Unlock() 60 | for _, agent := range ap.agents { 61 | if agent.AccessToken == accessToken { 62 | return agent.ID, nil 63 | } 64 | } 65 | return "", xerrors.New("no agent exists with that agent token") 66 | } 67 | -------------------------------------------------------------------------------- /runner/debug.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | import "log" 4 | 5 | var ( 6 | Debug bool 7 | ) 8 | 9 | func debugf(pattern string, args ...interface{}) { 10 | if Debug { 11 | log.Printf(pattern, args...) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runner/emoji.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | // This tool implements the iterm2 image support as described here: 4 | // http://iterm2.com/images.html 5 | 6 | import ( 7 | "encoding/base64" 8 | "encoding/json" 9 | "fmt" 10 | "io/ioutil" 11 | "log" 12 | "net/http" 13 | "os" 14 | "path/filepath" 15 | "regexp" 16 | "strconv" 17 | "strings" 18 | 19 | homedir "github.com/mitchellh/go-homedir" 20 | ) 21 | 22 | const ( 23 | appleEmojiMapping = `https://github.com/buildkite/emojis/raw/master/img-apple-64.json` 24 | buildkiteEmojiMapping = `https://github.com/buildkite/emojis/raw/master/img-buildkite-64.json` 25 | emojiCachePrefix = `https://github.com/buildkite/emojis/raw/master/` 26 | ) 27 | 28 | var emojiRegexp = regexp.MustCompile(`:\w+:`) 29 | 30 | func emojiCachePath() (string, error) { 31 | home, err := homedir.Dir() 32 | if err != nil { 33 | return "", err 34 | } 35 | return filepath.Join(home, ".buildkite", "emoji"), nil 36 | } 37 | 38 | type emojiLoader struct { 39 | cache *emojiCache 40 | } 41 | 42 | func newEmojiLoader() (*emojiLoader, error) { 43 | cachePath, err := emojiCachePath() 44 | if err != nil { 45 | return nil, err 46 | } 47 | return &emojiLoader{ 48 | cache: &emojiCache{Path: cachePath}, 49 | }, nil 50 | } 51 | 52 | func (e *emojiLoader) appleEmojis() (appleEmojis, error) { 53 | var result appleEmojis 54 | 55 | if err := e.cache.httpGetJSON(appleEmojiMapping, &result); err != nil { 56 | return result, err 57 | } 58 | 59 | return result, nil 60 | } 61 | 62 | func (e *emojiLoader) buildkiteEmojis() (buildkiteEmojis, error) { 63 | var result buildkiteEmojis 64 | 65 | if err := e.cache.httpGetJSON(buildkiteEmojiMapping, &result); err != nil { 66 | return result, err 67 | } 68 | 69 | return result, nil 70 | } 71 | 72 | func (el *emojiLoader) Render(line string) string { 73 | return emojiRegexp.ReplaceAllStringFunc(line, func(s string) string { 74 | bkEmojis, err := el.buildkiteEmojis() 75 | if err != nil { 76 | log.Printf("Err: %v", err) 77 | return s 78 | } 79 | 80 | if e, ok := bkEmojis.Match(s); ok { 81 | return e.Render(el.cache) 82 | } 83 | 84 | appleEmojis, err := el.appleEmojis() 85 | if err != nil { 86 | log.Printf("Err: %v", err) 87 | return s 88 | } 89 | 90 | if e, ok := appleEmojis.Match(s); ok { 91 | return e.Render() 92 | } 93 | 94 | return s 95 | }) 96 | } 97 | 98 | type emojiCache struct { 99 | Path string 100 | } 101 | 102 | func (e *emojiCache) httpGetJSON(u string, into interface{}) error { 103 | b, err := e.httpGet(u) 104 | if err != nil { 105 | return err 106 | } 107 | 108 | return json.Unmarshal(b, into) 109 | } 110 | 111 | func (e *emojiCache) httpGet(u string) ([]byte, error) { 112 | if !strings.HasPrefix(u, emojiCachePrefix) { 113 | return nil, fmt.Errorf("Url doesn't start with %s", emojiCachePrefix) 114 | } 115 | 116 | cacheFilePath := filepath.Join(e.Path, strings.TrimPrefix(u, emojiCachePrefix)) 117 | if _, err := os.Stat(cacheFilePath); err == nil { 118 | return ioutil.ReadFile(cacheFilePath) 119 | } 120 | 121 | res, err := http.Get(u) 122 | if err != nil { 123 | return nil, err 124 | } 125 | defer res.Body.Close() 126 | 127 | data, err := ioutil.ReadAll(res.Body) 128 | if err != nil { 129 | return nil, err 130 | } 131 | 132 | if err := os.MkdirAll(filepath.Dir(cacheFilePath), 0700); err != nil { 133 | log.Printf("Failed to Mkdir: %v", err) 134 | } 135 | 136 | if err = ioutil.WriteFile(cacheFilePath, data, 0600); err != nil { 137 | log.Printf("Failed to write %s: %v", cacheFilePath, err) 138 | } 139 | 140 | return data, nil 141 | } 142 | 143 | type buildkiteEmoji struct { 144 | Name string `json:"name"` 145 | Image string `json:"image"` 146 | Category string `json:"category"` 147 | Aliases []string `json:"aliases"` 148 | } 149 | 150 | func (e buildkiteEmoji) Render(cache *emojiCache) string { 151 | defaultReturn := ":" + e.Name + ":" 152 | 153 | if os.Getenv(`TERM_PROGRAM`) != `iTerm.app` { 154 | return defaultReturn 155 | } 156 | 157 | img, err := cache.httpGet(emojiCachePrefix + e.Image) 158 | if err != nil { 159 | log.Printf("Err: %v", err) 160 | return defaultReturn 161 | } 162 | 163 | return renderITerm2Image(img) 164 | } 165 | 166 | type buildkiteEmojis []buildkiteEmoji 167 | 168 | func (be buildkiteEmojis) Match(name string) (buildkiteEmoji, bool) { 169 | name = strings.Trim(name, ":") 170 | 171 | for _, m := range be { 172 | if m.Name == name { 173 | return m, true 174 | } 175 | for _, a := range m.Aliases { 176 | if a == name { 177 | return m, true 178 | } 179 | } 180 | } 181 | 182 | return buildkiteEmoji{}, false 183 | } 184 | 185 | type appleEmoji struct { 186 | Name string `json:"name"` 187 | Category string `json:"category"` 188 | Image string `json:"image"` 189 | Unicode string `json:"unicode"` 190 | Aliases []interface{} `json:"aliases"` 191 | Modifiers []interface{} `json:"modifiers"` 192 | } 193 | 194 | func (e appleEmoji) Render() string { 195 | b := strings.Builder{} 196 | 197 | for _, s := range strings.Split(e.Unicode, "-") { 198 | var err error 199 | var decoded string 200 | 201 | if len(s) > 4 { 202 | decoded, err = strconv.Unquote(fmt.Sprintf(`"\U%08s"`, s)) 203 | } else { 204 | decoded, err = strconv.Unquote(fmt.Sprintf(`"\u%04s"`, s)) 205 | } 206 | 207 | if err != nil { 208 | log.Printf("Error decoding %q: %v", e.Unicode, decoded) 209 | return e.Name 210 | } 211 | 212 | b.WriteString(decoded) 213 | } 214 | 215 | return b.String() 216 | } 217 | 218 | type appleEmojis []appleEmoji 219 | 220 | func (ae appleEmojis) Match(name string) (appleEmoji, bool) { 221 | name = strings.Trim(name, ":") 222 | 223 | for _, m := range ae { 224 | if m.Name == name { 225 | return m, true 226 | } 227 | for _, a := range m.Aliases { 228 | if a == name { 229 | return m, true 230 | } 231 | } 232 | } 233 | 234 | return appleEmoji{}, false 235 | } 236 | 237 | func renderITerm2Image(data []byte) string { 238 | var b strings.Builder 239 | 240 | b.WriteString("\033]1337;") 241 | b.WriteString("File=inline=1") 242 | b.WriteString(";height=1") 243 | b.WriteString(":") 244 | b.WriteString(base64.StdEncoding.EncodeToString(data)) 245 | b.WriteString("\a\b") 246 | 247 | return b.String() 248 | } 249 | -------------------------------------------------------------------------------- /runner/pipeline.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | "regexp" 8 | "sort" 9 | "strings" 10 | ) 11 | 12 | type step struct { 13 | Branches []string `json:"-"` 14 | Command *commandStep `json:"-"` 15 | Wait *waitStep `json:"-"` 16 | Block *blockStep `json:"-"` 17 | Trigger *triggerStep `json:"-"` 18 | } 19 | 20 | func (s *step) UnmarshalJSON(data []byte) error { 21 | var stringStep string 22 | 23 | // Handle steps that are just strings, e.g "wait" 24 | if err := json.Unmarshal(data, &stringStep); err == nil { 25 | switch stringStep { 26 | case "wait": 27 | s.Wait = &waitStep{} 28 | return nil 29 | default: 30 | return fmt.Errorf("Unknown step type %q", stringStep) 31 | } 32 | } 33 | 34 | var intermediate map[string]interface{} 35 | 36 | // Determine the type of step it is 37 | if err := json.Unmarshal(data, &intermediate); err != nil { 38 | return err 39 | } 40 | 41 | var branches = intermediate["branch"] 42 | if b, ok := intermediate["branches"]; ok { 43 | branches = b 44 | } 45 | 46 | if branches != nil { 47 | var err error 48 | s.Branches, err = ParseBranchPattern(branches) 49 | if err != nil { 50 | return err 51 | } 52 | } 53 | 54 | if _, ok := intermediate["wait"]; ok { 55 | return json.Unmarshal(data, &s.Wait) 56 | } 57 | 58 | if _, ok := intermediate["block"]; ok { 59 | return json.Unmarshal(data, &s.Block) 60 | } 61 | 62 | if _, ok := intermediate["trigger"]; ok { 63 | return json.Unmarshal(data, &s.Trigger) 64 | } 65 | 66 | return json.Unmarshal(data, &s.Command) 67 | } 68 | 69 | func ParseBranchPattern(branches interface{}) ([]string, error) { 70 | var result []string 71 | 72 | switch b := branches.(type) { 73 | case []interface{}: 74 | for _, bi := range b { 75 | result = append(result, strings.Fields(bi.(string))...) 76 | } 77 | case string: 78 | result = append(result, strings.Fields(b)...) 79 | default: 80 | return nil, fmt.Errorf("Branches is unhandled type %T", branches) 81 | } 82 | 83 | return result, nil 84 | } 85 | 86 | func MatchBranchPattern(branch string, pattern string) bool { 87 | expected := true 88 | 89 | // Handle negation at the start 90 | for strings.HasPrefix(pattern, `!`) { 91 | expected = !expected 92 | pattern = strings.TrimPrefix(pattern, `!`) 93 | } 94 | 95 | // Compile a regex for the rest 96 | re, err := regexp.Compile(`^` + strings.Replace(pattern, `*`, `.*?`, -1) + `$`) 97 | if err != nil { 98 | log.Printf("Failed to compile regex: %v", err) 99 | return false 100 | } 101 | 102 | // Test it against the branch 103 | if re.MatchString(branch) == expected { 104 | return true 105 | } 106 | 107 | return false 108 | } 109 | 110 | func (s step) MatchBranch(branch string) bool { 111 | if len(s.Branches) == 0 { 112 | return true 113 | } 114 | 115 | // Apply a heuristic, if we have multiple negatives it's AND-ed 116 | // otherwise it's OR-d. Gross, but we know what the user meant. 117 | 118 | var negationCount int 119 | for _, b := range s.Branches { 120 | if strings.HasPrefix(b, `!`) { 121 | negationCount += 1 122 | } 123 | } 124 | 125 | if negationCount > 1 { 126 | // Has multiple negatives, so the patterns are AND-ed 127 | for _, pattern := range s.Branches { 128 | if !MatchBranchPattern(branch, pattern) { 129 | return false 130 | } 131 | } 132 | return true 133 | } 134 | 135 | // Has zero of one negatives, so the patterns are OR-ed 136 | for _, pattern := range s.Branches { 137 | if MatchBranchPattern(branch, pattern) { 138 | return true 139 | } 140 | } 141 | 142 | return false 143 | } 144 | 145 | func (s step) Label() string { 146 | if s.Command != nil { 147 | return s.Command.Label 148 | } else if s.Block != nil { 149 | return "Block" 150 | } else if s.Wait != nil { 151 | return "Wait" 152 | } else if s.Trigger != nil { 153 | return "Trigger" 154 | } 155 | return "" 156 | } 157 | 158 | func (s step) String() string { 159 | if s.Command != nil { 160 | return fmt.Sprintf("{Command: %+v}", *s.Command) 161 | } else if s.Block != nil { 162 | return fmt.Sprintf("{Block: %+v}", *s.Block) 163 | } else if s.Wait != nil { 164 | return fmt.Sprintf("{Wait: %+v}", *s.Wait) 165 | } else if s.Trigger != nil { 166 | return fmt.Sprintf("{Trigger: %+v} ", *s.Trigger) 167 | } 168 | return "Unknown" 169 | } 170 | 171 | type blockField struct { 172 | Text string `json:"text"` 173 | Select string `json:"select"` 174 | Key string `json:"key"` 175 | Hint string `json:"hint"` 176 | Required bool `json:"required"` 177 | Default string `json:"default"` 178 | Options []blockSelectOption `json:"options"` 179 | } 180 | 181 | type blockSelectOption struct { 182 | Label string `json:"label"` 183 | Value string `json:"value"` 184 | } 185 | 186 | type blockStep struct { 187 | Block string `json:"block"` 188 | Fields []blockField `json:"fields"` 189 | } 190 | 191 | type waitStep struct { 192 | Wait string `json:"wait"` 193 | ContinueOnFailure bool `json:"continue_on_failure"` 194 | } 195 | 196 | type triggerStep struct { 197 | Trigger string `json:"trigger"` 198 | } 199 | 200 | type commandStep struct { 201 | Label string `json:"label"` 202 | Commands []string `json:"-"` 203 | Plugins []Plugin `json:"-"` 204 | Env []string `json:"-"` 205 | ArtifactPaths []string `json:"-"` 206 | Parallelism int `json:"parallelism"` 207 | } 208 | 209 | func (s *commandStep) UnmarshalJSON(data []byte) error { 210 | var intermediate struct { 211 | Label string `json:"label"` 212 | Name string `json:"name"` 213 | Commands stringOrSlice `json:"commands"` 214 | Command stringOrSlice `json:"command"` 215 | Env envMapOrSlice `json:"env"` 216 | Environment envMapOrSlice `json:"environment"` 217 | ArtifactPaths stringOrSlice `json:"artifact_paths"` 218 | Branch stringOrSlice `json:"branch"` 219 | Branches stringOrSlice `json:"branches"` 220 | Parallelism int `json:"parallelism"` 221 | } 222 | 223 | if err := json.Unmarshal(data, &intermediate); err != nil { 224 | return fmt.Errorf("invalid command step: %v", err) 225 | } 226 | 227 | s.Parallelism = intermediate.Parallelism 228 | s.ArtifactPaths = []string(intermediate.ArtifactPaths) 229 | 230 | // Normalize name vs label 231 | s.Label = intermediate.Label 232 | if intermediate.Name != "" { 233 | s.Label = intermediate.Name 234 | } 235 | 236 | // Normalize command vs commands (note plural) 237 | if len(intermediate.Command) > 0 { 238 | s.Commands = append(s.Commands, intermediate.Command...) 239 | } else { 240 | s.Commands = append(s.Commands, intermediate.Commands...) 241 | } 242 | 243 | // Normalize env vs environment 244 | s.Env = []string(intermediate.Env) 245 | if len(intermediate.Environment) > 0 { 246 | s.Env = []string(intermediate.Environment) 247 | } 248 | 249 | s.Plugins = nil 250 | 251 | var pluginSlice struct { 252 | Plugins []map[string]interface{} `json:"plugins"` 253 | } 254 | 255 | if err := json.Unmarshal(data, &pluginSlice); err == nil { 256 | for _, p := range pluginSlice.Plugins { 257 | for k, v := range p { 258 | switch vv := v.(type) { 259 | case map[string]interface{}: 260 | s.Plugins = append(s.Plugins, Plugin{Name: k, Params: vv}) 261 | case nil: 262 | s.Plugins = append(s.Plugins, Plugin{Name: k}) 263 | default: 264 | return fmt.Errorf("Unknown plugin value type %T", v) 265 | } 266 | } 267 | } 268 | } 269 | 270 | var pluginStringSlice struct { 271 | Plugins []string `json:"plugins"` 272 | } 273 | 274 | if err := json.Unmarshal(data, &pluginStringSlice); err == nil { 275 | for _, p := range pluginStringSlice.Plugins { 276 | s.Plugins = append(s.Plugins, Plugin{ 277 | Name: p, 278 | }) 279 | } 280 | } 281 | 282 | var pluginMap struct { 283 | Plugins map[string]interface{} `json:"plugins"` 284 | } 285 | 286 | if err := json.Unmarshal(data, &pluginMap); err == nil { 287 | for k, v := range pluginMap.Plugins { 288 | s.Plugins = append(s.Plugins, Plugin{ 289 | Name: k, 290 | Params: v, 291 | }) 292 | } 293 | } 294 | 295 | return nil 296 | } 297 | 298 | type pipelineUpload struct { 299 | Pipeline pipeline `json:"pipeline"` 300 | Replace bool `json:"replace"` 301 | } 302 | 303 | type pipeline struct { 304 | Steps []step `json:"steps"` 305 | Env envMapOrSlice `json:"env"` 306 | } 307 | 308 | func (p pipeline) Filter(f func(s step) bool) pipeline { 309 | filtered := p 310 | filtered.Steps = []step{} 311 | for _, s := range p.Steps { 312 | if f(s) { 313 | filtered.Steps = append(filtered.Steps, s) 314 | } 315 | } 316 | return filtered 317 | } 318 | 319 | type stringable string 320 | 321 | func (s *stringable) UnmarshalJSON(data []byte) error { 322 | var target interface{} 323 | 324 | if err := json.Unmarshal(data, &target); err != nil { 325 | return err 326 | } 327 | 328 | switch target.(type) { 329 | case string, int, int64, bool, float32, float64: 330 | *s = stringable(fmt.Sprintf("%v", target)) 331 | default: 332 | return fmt.Errorf("Unstringable type of %T", target) 333 | } 334 | 335 | return nil 336 | } 337 | 338 | type stringOrSlice []string 339 | 340 | func (s *stringOrSlice) UnmarshalJSON(data []byte) error { 341 | var str stringable 342 | *s = []string{} 343 | 344 | if err := json.Unmarshal(data, &str); err == nil { 345 | *s = []string{string(str)} 346 | return nil 347 | } 348 | 349 | var strSlice []stringable 350 | 351 | if err := json.Unmarshal(data, &strSlice); err != nil { 352 | return err 353 | } 354 | 355 | for _, str := range strSlice { 356 | *s = append(*s, string(str)) 357 | } 358 | 359 | return nil 360 | } 361 | 362 | type envMapOrSlice []string 363 | 364 | func (s *envMapOrSlice) UnmarshalJSON(data []byte) error { 365 | var m map[string]stringable 366 | *s = []string{} 367 | 368 | if err := json.Unmarshal(data, &m); err == nil { 369 | for k, v := range m { 370 | *s = append(*s, fmt.Sprintf("%s=%s", k, v)) 371 | } 372 | 373 | // maps are unordered, this makes them predictable 374 | sorted := sort.StringSlice(*s) 375 | sorted.Sort() 376 | 377 | return nil 378 | } 379 | 380 | var envSlice []string 381 | 382 | if err := json.Unmarshal(data, &envSlice); err != nil { 383 | return fmt.Errorf("env must be a slice or a map: %v", err) 384 | } 385 | 386 | *s = envSlice 387 | return nil 388 | } 389 | -------------------------------------------------------------------------------- /runner/pipeline_test.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | import ( 4 | "encoding/json" 5 | "testing" 6 | 7 | "github.com/go-test/deep" 8 | ) 9 | 10 | func TestParsingStringable(t *testing.T) { 11 | for _, tc := range []struct { 12 | JSON string 13 | Expected string 14 | }{ 15 | {`true`, `true`}, 16 | {`false`, `false`}, 17 | {`"true"`, `true`}, 18 | {`"true"`, `true`}, 19 | {`1`, `1`}, 20 | {`"1"`, `1`}, 21 | {`1.23`, `1.23`}, 22 | } { 23 | t.Run("", func(t *testing.T) { 24 | var target stringable 25 | 26 | if err := json.Unmarshal([]byte(tc.JSON), &target); err != nil { 27 | t.Fatalf("failed to parse json: %v", err) 28 | } 29 | 30 | if diff := deep.Equal(tc.Expected, string(target)); diff != nil { 31 | t.Error(diff) 32 | } 33 | }) 34 | } 35 | } 36 | 37 | func TestParsingEnvMapOrSlice(t *testing.T) { 38 | for _, tc := range []struct { 39 | JSON string 40 | Expected []string 41 | }{ 42 | { 43 | `{ "FOO": false, "BAR": "foo", "BAZ": 12 }`, 44 | []string{"BAR=foo", "BAZ=12", "FOO=false"}, 45 | }, 46 | { 47 | `[ "BAR=foo", "BAZ=12", "FOO=false" ]`, 48 | []string{"BAR=foo", "BAZ=12", "FOO=false"}, 49 | }, 50 | } { 51 | t.Run("", func(t *testing.T) { 52 | var target envMapOrSlice 53 | 54 | if err := json.Unmarshal([]byte(tc.JSON), &target); err != nil { 55 | t.Fatalf("failed to parse json: %v", err) 56 | } 57 | 58 | if diff := deep.Equal(tc.Expected, []string(target)); diff != nil { 59 | t.Error(diff) 60 | } 61 | }) 62 | } 63 | } 64 | 65 | func TestStepParsingCommandSteps(t *testing.T) { 66 | for _, tc := range []struct { 67 | JSON string 68 | Expected step 69 | }{ 70 | { 71 | `{ 72 | "label": "testing with env as a map", 73 | "command": "echo hi $$FOO", 74 | "env": { 75 | "FOO": false, 76 | "BAR": "foo", 77 | "BAZ": 12 78 | } 79 | }`, 80 | step{ 81 | Command: &commandStep{ 82 | Label: `testing with env as a map`, 83 | Commands: []string{`echo hi $$FOO`}, 84 | Env: envMapOrSlice{ 85 | "BAR=foo", 86 | "BAZ=12", 87 | "FOO=false", 88 | }, 89 | }, 90 | }, 91 | }, 92 | { 93 | `{ 94 | "label": "testing with boolean commands", 95 | "command": [ "echo llamas", false ] 96 | }`, 97 | step{ 98 | Command: &commandStep{ 99 | Label: `testing with boolean commands`, 100 | Commands: []string{`echo llamas`, `false`}, 101 | }, 102 | }, 103 | }, 104 | { 105 | `{ 106 | "command": "echo foo", 107 | "branches": "!foo" 108 | }`, 109 | step{ 110 | Command: &commandStep{ 111 | Commands: []string{`echo foo`}, 112 | }, 113 | Branches: []string{`!foo`}, 114 | }, 115 | }, 116 | { 117 | `{ 118 | "command": "echo foo", 119 | "branches": "master stable/*" 120 | }`, 121 | step{ 122 | Command: &commandStep{ 123 | Commands: []string{`echo foo`}, 124 | }, 125 | Branches: []string{`master`, `stable/*`}, 126 | }, 127 | }, 128 | } { 129 | t.Run("", func(t *testing.T) { 130 | var step step 131 | 132 | if err := json.Unmarshal([]byte(tc.JSON), &step); err != nil { 133 | t.Fatalf("failed to parse json: %v", err) 134 | } 135 | 136 | if diff := deep.Equal(tc.Expected, step); diff != nil { 137 | t.Error(diff) 138 | } 139 | }) 140 | } 141 | } 142 | 143 | func TestPipelineParsing(t *testing.T) { 144 | for _, tc := range []struct { 145 | JSON string 146 | Expected pipeline 147 | }{ 148 | { 149 | `{ 150 | "steps": [ 151 | { 152 | "command": "echo hello world" 153 | } 154 | ] 155 | }`, 156 | pipeline{ 157 | Steps: []step{ 158 | { 159 | Command: &commandStep{ 160 | Commands: []string{"echo hello world"}, 161 | }, 162 | }, 163 | }, 164 | }, 165 | }, 166 | { 167 | `{ 168 | "steps":[ 169 | { 170 | "commands": [ "echo hello world", "pwd" ] 171 | } 172 | ] 173 | }`, 174 | pipeline{ 175 | Steps: []step{ 176 | { 177 | Command: &commandStep{ 178 | Commands: []string{"echo hello world", "pwd"}, 179 | }, 180 | }, 181 | }, 182 | }, 183 | }, 184 | { 185 | `{ 186 | "steps": [ 187 | {"wait": ""}, 188 | {"label": "llamas"} 189 | ] 190 | }`, 191 | pipeline{ 192 | Steps: []step{ 193 | { 194 | Wait: &waitStep{}, 195 | }, 196 | { 197 | Command: &commandStep{ 198 | Label: "llamas", 199 | }, 200 | }, 201 | }, 202 | }, 203 | }, 204 | { 205 | `{ 206 | "steps": [ 207 | { 208 | "commands": [ 209 | "echo hello world", 210 | "pwd" 211 | ], 212 | "plugins": { 213 | "blah-blah/blah#v0.0.1": null, 214 | "blah-blah/another#v0.0.1": { 215 | "my_config":"totes" 216 | } 217 | } 218 | } 219 | ] 220 | }`, 221 | pipeline{ 222 | Steps: []step{ 223 | { 224 | Command: &commandStep{ 225 | Commands: []string{"echo hello world", "pwd"}, 226 | Plugins: []Plugin{ 227 | {Name: "blah-blah/blah#v0.0.1"}, 228 | {Name: "blah-blah/another#v0.0.1", Params: map[string]interface{}{ 229 | "my_config": "totes", 230 | }}, 231 | }, 232 | }, 233 | }, 234 | }, 235 | }, 236 | }, 237 | { 238 | `{ 239 | "steps": [ 240 | { 241 | "plugins": [ 242 | "blah-blah/blah#v0.0.1" 243 | ] 244 | } 245 | ] 246 | }`, 247 | pipeline{ 248 | Steps: []step{ 249 | { 250 | Command: &commandStep{ 251 | Plugins: []Plugin{ 252 | {Name: "blah-blah/blah#v0.0.1"}, 253 | }, 254 | }, 255 | }, 256 | }, 257 | }, 258 | }, 259 | { 260 | `{ 261 | "steps": [ 262 | {"wait": ""}, 263 | {"label": "llamas"} 264 | ] 265 | }`, 266 | pipeline{ 267 | Steps: []step{ 268 | { 269 | Wait: &waitStep{}, 270 | }, 271 | { 272 | Command: &commandStep{ 273 | Label: "llamas", 274 | }, 275 | }, 276 | }, 277 | }, 278 | }, 279 | { 280 | `{ 281 | "env": { 282 | "FOO": false, 283 | "BAR": "foo", 284 | "BAZ": 12 285 | }, 286 | "steps": [] 287 | }`, 288 | pipeline{ 289 | Env: envMapOrSlice{ 290 | "BAR=foo", 291 | "BAZ=12", 292 | "FOO=false", 293 | }, 294 | Steps: []step{}, 295 | }, 296 | }, 297 | } { 298 | t.Run("", func(t *testing.T) { 299 | var pipeline pipeline 300 | 301 | if err := json.Unmarshal([]byte(tc.JSON), &pipeline); err != nil { 302 | t.Fatal(err) 303 | } 304 | 305 | if diff := deep.Equal(tc.Expected, pipeline); diff != nil { 306 | t.Error(diff) 307 | } 308 | }) 309 | } 310 | } 311 | 312 | func TestMatchingBranches(t *testing.T) { 313 | for _, tc := range []struct { 314 | Pattern string 315 | Branch string 316 | }{ 317 | // empty branch patterns match all 318 | {"", "foo"}, 319 | {"", ""}, 320 | {"", " "}, 321 | 322 | // single name branch matches 323 | {"foo bar", "foo"}, 324 | {"foo bar", "bar"}, 325 | 326 | // with whitespace 327 | {" master ", "master"}, 328 | {"master ", "master"}, 329 | {" master", "master"}, 330 | 331 | // ones with a slash 332 | {"feature/authentication", "feature/authentication"}, 333 | 334 | // not-checking 335 | {"!foo", "master"}, 336 | {"!release/production !release/test", "master"}, 337 | 338 | // prefix wildcards 339 | {"*-do-the-thing", "can-you-do-the-thing"}, 340 | {"!*-do-the-thing", "can-you-do-the-thing-please"}, 341 | 342 | // wildcards 343 | {"release/*", "release/foo"}, 344 | {"release/*", "release/bar/bing"}, 345 | {"release-*", "release-thingy"}, 346 | {"release-* release/*", "release-thingy"}, 347 | {"release-* release/*", "release/thingy"}, 348 | {"this-*-thing-is-the-*", "this-ruby-thing-is-the-worst"}, 349 | {"this-*-thing-is-the-*", "this-regex-thing-is-the-best"}, 350 | {"this-*-thing-is-the-*", "this-*-thing-is-the-*"}, 351 | {"this-*-thing-is-the-*", "this--thing-is-the-best-"}, 352 | } { 353 | t.Run("", func(t *testing.T) { 354 | branches, err := ParseBranchPattern(tc.Pattern) 355 | if err != nil { 356 | t.Fatal(err) 357 | } 358 | 359 | s := step{ 360 | Branches: branches, 361 | } 362 | 363 | if !s.MatchBranch(tc.Branch) { 364 | t.Errorf("Expected pattern %q to match branch %q", tc.Pattern, tc.Branch) 365 | } 366 | }) 367 | } 368 | } 369 | 370 | func TestNotMatchingBranches(t *testing.T) { 371 | for _, tc := range []struct { 372 | Pattern string 373 | Branch string 374 | }{ 375 | // branch names 376 | {"foo bar", "bang"}, 377 | 378 | // not-matchers 379 | {"!foo bar", "foo"}, 380 | {"!release/*", "release/foo"}, 381 | {"!release/*", "release/bar"}, 382 | {"!refs/tags/*", "refs/tags/production"}, 383 | {"!release/production !release/test", "release/production"}, 384 | {"!release/production !release/test", "release/test"}, 385 | 386 | // ones with a slash 387 | {"feature/authentication", "update/deployment"}, 388 | 389 | // wildcards 390 | {"release-*", "release/thingy"}, 391 | {"release-*", "master"}, 392 | {"*-do-the-thing", "this-is-not-the-thing"}, 393 | } { 394 | t.Run("", func(t *testing.T) { 395 | branches, err := ParseBranchPattern(tc.Pattern) 396 | if err != nil { 397 | t.Fatal(err) 398 | } 399 | 400 | s := step{ 401 | Branches: branches, 402 | } 403 | 404 | if s.MatchBranch(tc.Branch) { 405 | t.Errorf("Expected pattern %q to NOT match branch %q", tc.Pattern, tc.Branch) 406 | } 407 | }) 408 | } 409 | } 410 | -------------------------------------------------------------------------------- /runner/plugins.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "regexp" 7 | ) 8 | 9 | var ( 10 | // 'official-plugin' and 'official-plugin#v2' 11 | officialPluginRegex = regexp.MustCompile(`^([A-Za-z0-9-]+)(#.+)?$`) 12 | 13 | // 'some-org/some-plugin' and 'some-org/some-plugin#v2' 14 | githubPluginRegex = regexp.MustCompile(`^([A-Za-z0-9-]+\/[A-Za-z0-9-]+)(#.+)?$`) 15 | ) 16 | 17 | type Plugin struct { 18 | Name string 19 | Params interface{} 20 | } 21 | 22 | func (p Plugin) Repository() string { 23 | if m := officialPluginRegex.FindStringSubmatch(p.Name); len(m) == 3 { 24 | return fmt.Sprintf(`github.com/buildkite-plugins/%s-buildkite-plugin%s`, m[1], m[2]) 25 | } 26 | 27 | if m := githubPluginRegex.FindStringSubmatch(p.Name); len(m) == 3 { 28 | return fmt.Sprintf(`github.com/%s-buildkite-plugin%s`, m[1], m[2]) 29 | } 30 | 31 | return p.Name 32 | } 33 | 34 | // The bootstrap expects an array of plugins like [{"plugin1#v1.0.0":{...}}, {"plugin2#v1.0.0":{...}}] 35 | func marshalPlugins(plugins []Plugin) (string, error) { 36 | var p []interface{} 37 | 38 | if len(plugins) == 0 { 39 | return "[]", nil 40 | } 41 | 42 | for _, plugin := range plugins { 43 | p = append(p, map[string]interface{}{ 44 | plugin.Repository(): plugin.Params, 45 | }) 46 | } 47 | b, err := json.Marshal(p) 48 | if err != nil { 49 | return "", nil 50 | } 51 | 52 | return string(b), nil 53 | } 54 | -------------------------------------------------------------------------------- /runner/run.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "fmt" 7 | "io" 8 | "io/ioutil" 9 | "log" 10 | "os" 11 | "os/exec" 12 | "regexp" 13 | "runtime" 14 | "strings" 15 | "sync" 16 | "time" 17 | 18 | "github.com/fatih/color" 19 | "github.com/manifoldco/promptui" 20 | uuid "github.com/satori/go.uuid" 21 | ) 22 | 23 | type Params struct { 24 | Debug bool 25 | DebugHTTP bool 26 | Env []string 27 | Metadata map[string]string 28 | Dir string 29 | Command string 30 | Prompt bool 31 | StepFilter *regexp.Regexp 32 | DryRun bool 33 | JobTemplate Job 34 | ListenPort int 35 | } 36 | 37 | // Run starts an API server and a `buildkite-agent` process that is 38 | // listening for jobs against that api. 39 | // 40 | // An initial command is used to upload some pipeline yaml to the 41 | // server, which is then broken up into steps and run through foreground 42 | // processing and filtering based on the runner params. 43 | // 44 | // Steps are then added as scheduled Jobs via the API server, where they 45 | // are processed by the waiting agent process. The API server handles 46 | // results and state change and finally updates the state of the job. 47 | func Run(ctx context.Context, params Params) error { 48 | agentPool := newAgentPool() 49 | server := newApiServer(agentPool, params.ListenPort) 50 | steps := newStepQueue() 51 | 52 | // Consume pipeline uploads from the server and apply any filters 53 | go func() { 54 | for p := range server.pipelineUploads { 55 | filtered := p.Pipeline.Filter(func(s step) bool { 56 | 57 | // Apply the step filter to the label 58 | if params.StepFilter != nil { 59 | return params.StepFilter.MatchString(s.Label()) 60 | } 61 | 62 | // Apply any branch filters 63 | if !s.MatchBranch(params.JobTemplate.Branch) { 64 | return false 65 | } 66 | 67 | return true 68 | }) 69 | if p.Replace { 70 | steps.Replace(filtered) 71 | } else { 72 | steps.Prepend(filtered) 73 | } 74 | } 75 | }() 76 | 77 | endpoint, err := server.ListenAndServe() 78 | if err != nil { 79 | return err 80 | } 81 | 82 | debugf("Serving API on %s", endpoint) 83 | 84 | agent := Agent{ 85 | Dir: params.Dir, 86 | Env: params.Env, 87 | Endpoint: endpoint, 88 | } 89 | if err := agent.Run(ctx); err != nil { 90 | return err 91 | } 92 | defer func() { 93 | // this ensures the agent always stops gracefully 94 | _ = agent.Stop() 95 | }() 96 | 97 | headerColor := color.New(color.FgWhite, color.Bold) 98 | headerColor.Printf(">>> Starting local agent 🕵️‍♂️\n") 99 | 100 | build := Build{ 101 | ID: uuid.NewV4().String(), 102 | Number: 1, 103 | } 104 | 105 | initialJob := params.JobTemplate 106 | initialJob.ID = uuid.NewV4().String() 107 | initialJob.Label = ":pipeline:" 108 | initialJob.Build = build 109 | initialJob.Command = params.Command 110 | 111 | ejl, err := newEmojiLoader() 112 | if err != nil { 113 | return err 114 | } 115 | 116 | w := newBuildLogFormatter(ejl) 117 | timer := time.Now() 118 | 119 | for mdKey, mdVal := range params.Metadata { 120 | server.SetMetadata(mdKey, mdVal) 121 | } 122 | 123 | headerColor.Printf(">>> Starting build 👟\n") 124 | headerColor.Printf(">>> Executing initial command: %s\n", params.Command) 125 | 126 | var initialJobWriter io.Writer 127 | initialJobWriter = w 128 | 129 | if !Debug { 130 | initialJobWriter = ioutil.Discard 131 | } 132 | 133 | err = executeJob(ctx, server, initialJobWriter, initialJob) 134 | if err != nil { 135 | return fmt.Errorf("Initial command failed: %v", err) 136 | } 137 | 138 | // Process each step that we receive 139 | for step := range processSteps(ctx, steps, server) { 140 | debugf("Processing step %s", step) 141 | 142 | if step.Wait != nil { 143 | continue 144 | } 145 | 146 | if params.Prompt { 147 | fmt.Println() 148 | prompt := promptui.Prompt{ 149 | Label: fmt.Sprintf("Run %s", ejl.Render(step.Label())), 150 | IsConfirm: true, 151 | Default: "y", 152 | } 153 | 154 | result, err := prompt.Run() 155 | if err != nil { 156 | return err 157 | } 158 | 159 | fmt.Println() 160 | 161 | if result == "n" { 162 | continue 163 | } 164 | } 165 | 166 | dryRunNote := "" 167 | if params.DryRun { 168 | dryRunNote = " (dry-run)" 169 | } 170 | 171 | if step.Command != nil { 172 | headerColor.Printf(">>> Executing command step %s%s\n", 173 | ejl.Render(step.Command.Label), 174 | dryRunNote) 175 | 176 | if !params.DryRun { 177 | // load the step into a job 178 | j := params.JobTemplate 179 | j.ID = uuid.NewV4().String() 180 | j.Build = build 181 | j.Command = strings.Join(step.Command.Commands, "\n") 182 | j.Label = step.Command.Label 183 | j.Plugins = step.Command.Plugins 184 | j.ArtifactPaths = step.Command.ArtifactPaths 185 | 186 | // append global env and then step env 187 | j.Env = []string{} 188 | j.Env = append(j.Env, step.Env...) 189 | j.Env = append(j.Env, step.Command.Env...) 190 | j.Env = append(j.Env, `BUILDKITE_CLI=true`) 191 | 192 | // force parallelism of 1 193 | if step.Command.Parallelism > 0 { 194 | j.Env = append(j.Env, 195 | `BUILDKITE_PARALLEL_JOB=0`, `BUILDKITE_PARALLEL_JOB_COUNT=1`) 196 | } 197 | 198 | if err = executeJob(ctx, server, w, j); err != nil { 199 | headerColor.Printf(">>> 🚨 Command failed in %v\n", time.Now().Sub(timer)) 200 | return err 201 | } else { 202 | headerColor.Printf(">>> Command succeeded in %v\n", time.Now().Sub(timer)) 203 | } 204 | } 205 | } else if step.Trigger != nil { 206 | headerColor.Printf(">>> Skipping trigger step\n") 207 | continue 208 | 209 | } else if step.Block != nil { 210 | headerColor.Printf(">>> Blocking on %q%s\n", step.Block.Block, dryRunNote) 211 | 212 | if !params.DryRun { 213 | for _, field := range step.Block.Fields { 214 | switch { 215 | case field.Text != "": 216 | fmt.Println() 217 | prompt := promptui.Prompt{ 218 | Label: field.Text, 219 | Default: field.Default, 220 | AllowEdit: true, 221 | } 222 | 223 | if field.Required { 224 | prompt.Label = fmt.Sprintf("%s%s", prompt.Label, " (required)") 225 | prompt.Validate = func(input string) error { 226 | if input == "" { 227 | return errors.New("Value required") 228 | } 229 | return nil 230 | } 231 | } 232 | 233 | result, err := prompt.Run() 234 | 235 | if err != nil { 236 | fmt.Printf("Prompt failed %v\n", err) 237 | } 238 | 239 | server.SetMetadata(field.Key, result) 240 | 241 | case field.Select != "": 242 | fmt.Println() 243 | templates := &promptui.SelectTemplates{ 244 | Inactive: " {{ .Label | cyan }}", 245 | Active: fmt.Sprintf("%s {{ .Label | underline }}", promptui.IconSelect), 246 | } 247 | 248 | items := field.Options 249 | 250 | prompt := promptui.Select{ 251 | Label: field.Select, 252 | Items: items, 253 | Templates: templates, 254 | } 255 | 256 | if field.Required { 257 | prompt.Label = fmt.Sprintf("%s%s", prompt.Label, " (required)") 258 | } else { 259 | items = append([]blockSelectOption{{Label: "Empty"}}, field.Options...) 260 | prompt.Items = items 261 | } 262 | 263 | i, _, err := prompt.Run() 264 | 265 | if err != nil { 266 | fmt.Printf("Prompt failed %v\n", err) 267 | return err 268 | } 269 | 270 | server.SetMetadata(field.Key, items[i].Value) 271 | } 272 | } 273 | 274 | fmt.Println() 275 | prompt := promptui.Prompt{ 276 | Label: fmt.Sprintf("Unblock %q", ejl.Render(step.Block.Block)), 277 | IsConfirm: true, 278 | Default: "y", 279 | } 280 | 281 | result, err := prompt.Run() 282 | if err != nil { 283 | return err 284 | } 285 | 286 | fmt.Println() 287 | 288 | if result == "n" { 289 | return fmt.Errorf("Unblock failed") 290 | } 291 | } 292 | 293 | continue 294 | 295 | } else { 296 | return fmt.Errorf("Unknown step type: %s", step) 297 | } 298 | } 299 | 300 | color.Green(">>> Build finished in %v\n", time.Now().Sub(timer)) 301 | return nil 302 | } 303 | 304 | var subtleHeaderRegexp = regexp.MustCompile(`^~~~`) 305 | var expandedHeaderRegexp = regexp.MustCompile(`^\+\+\+`) 306 | var minimizedHeaderRegexp = regexp.MustCompile(`^---`) 307 | var headerRegexp = regexp.MustCompile(`^(~~~|\+\+\+|---)`) 308 | 309 | func newBuildLogFormatter(ejl *emojiLoader) io.Writer { 310 | subtle := color.New(color.FgWhite) 311 | expanded := color.New(color.FgHiWhite, color.Underline) 312 | minimized := color.New(color.FgWhite, color.Faint) 313 | 314 | return newLineWriter(func(line string) { 315 | if headerRegexp.MatchString(line) { 316 | line = ejl.Render(line) 317 | } 318 | if subtleHeaderRegexp.MatchString(line) { 319 | subtle.Printf("\n%s\n", line) 320 | } else if expandedHeaderRegexp.MatchString(line) { 321 | expanded.Printf("\n%s\n", line) 322 | } else if minimizedHeaderRegexp.MatchString(line) { 323 | minimized.Printf("\n%s\n", line) 324 | } else if line == "^^^ +++" { 325 | // skip this one 326 | } else { 327 | fmt.Println(line) 328 | } 329 | }) 330 | } 331 | 332 | func processSteps(ctx context.Context, s *stepQueue, server *apiServer) chan stepWithEnv { 333 | ch := make(chan stepWithEnv) 334 | 335 | go func() { 336 | for { 337 | select { 338 | case <-ctx.Done(): 339 | debugf("Context done, stopping processing steps") 340 | close(ch) 341 | return 342 | 343 | case <-time.NewTimer(time.Millisecond * 5).C: 344 | step, ok := s.Next() 345 | if ok { 346 | ch <- step 347 | } else if !server.HasUnfinishedJobs() { 348 | debugf("Steps finished and server done, stopping processing step queue") 349 | close(ch) 350 | return 351 | } 352 | } 353 | } 354 | }() 355 | 356 | return ch 357 | } 358 | 359 | func executeJob(ctx context.Context, server *apiServer, w io.Writer, j Job) error { 360 | exitCh := server.Execute(j, w) 361 | 362 | // add some trailing whitespace 363 | defer func() { 364 | fmt.Fprintf(w, "\n") 365 | }() 366 | 367 | select { 368 | case <-ctx.Done(): 369 | return ctx.Err() 370 | case exitCode := <-exitCh: 371 | if exitCode != 0 { 372 | return fmt.Errorf("Job failed with code %d", exitCode) 373 | } 374 | } 375 | 376 | return nil 377 | } 378 | 379 | type Agent struct { 380 | Dir string 381 | Env []string 382 | Endpoint string 383 | 384 | sync.Mutex 385 | stopFunc func() error 386 | stopping bool 387 | stopped bool 388 | } 389 | 390 | func (a *Agent) Run(ctx context.Context) error { 391 | bootstrap, err := createAgentBootstrap(a.Dir) 392 | if err != nil { 393 | return err 394 | } 395 | 396 | args := []string{"start"} 397 | if Debug { 398 | args = append(args, "--debug") 399 | } 400 | 401 | cmd := exec.Command("buildkite-agent", args...) 402 | if Debug { 403 | cmd.Stdout = os.Stdout 404 | cmd.Stderr = os.Stderr 405 | } else { 406 | cmd.Stdout = ioutil.Discard 407 | cmd.Stderr = ioutil.Discard 408 | } 409 | 410 | buildDir, err := ioutil.TempDir(os.TempDir(), "buildkite-build-") 411 | if err != nil { 412 | return err 413 | } 414 | 415 | defer os.RemoveAll(buildDir) 416 | 417 | pluginsDir, err := ioutil.TempDir(os.TempDir(), "buildkite-plugins-") 418 | if err != nil { 419 | return err 420 | } 421 | 422 | defer os.RemoveAll(pluginsDir) 423 | 424 | cmd.Env = append(a.Env, 425 | `HOME=`+os.Getenv(`HOME`), 426 | `PATH=`+os.Getenv(`PATH`), 427 | `BUILDKITE_AGENT_ENDPOINT=`+a.Endpoint, 428 | `BUILDKITE_AGENT_TOKEN=llamas`, 429 | `BUILDKITE_AGENT_NAME=local`, 430 | `BUILDKITE_BOOTSTRAP_SCRIPT_PATH=`+bootstrap.Name(), 431 | `BUILDKITE_BUILD_PATH=`+buildDir, 432 | `BUILDKITE_PLUGINS_PATH=`+pluginsDir, 433 | ) 434 | 435 | // Windows requires certain env variables to be present 436 | if runtime.GOOS == "windows" { 437 | cmd.Env = append(cmd.Env, 438 | "APPDATA="+os.Getenv("APPDATA"), 439 | "LOCALAPPDATA="+os.Getenv("LOCALAPPDATA"), 440 | "HOMEPATH="+os.Getenv("HOMEPATH"), 441 | "USERPROFILE="+os.Getenv("USERPROFILE"), 442 | "PATH="+os.Getenv("PATH"), 443 | "SystemRoot="+os.Getenv("SystemRoot"), 444 | "WINDIR="+os.Getenv("WINDIR"), 445 | "COMSPEC="+os.Getenv("COMSPEC"), 446 | "PATHEXT="+os.Getenv("PATHEXT"), 447 | "TMP="+os.Getenv("TMP"), 448 | "TEMP="+os.Getenv("TEMP"), 449 | "SYSTEMDRIVE="+os.Getenv("SYSTEMDRIVE"), 450 | ) 451 | } 452 | 453 | // this function is called at the end of Run() 454 | // it kills the agent 455 | a.stopFunc = func() error { 456 | defer os.Remove(bootstrap.Name()) 457 | 458 | switch runtime.GOOS { 459 | case "windows": 460 | _ = cmd.Process.Kill() 461 | default: 462 | _ = cmd.Process.Signal(os.Interrupt) 463 | } 464 | return cmd.Wait() 465 | } 466 | 467 | // if the context is cancelled (from ctrl-c) 468 | // we need to lock so that the above stopFunc doesn't 469 | // send a signal, as the ctrl-c was sent to the process group 470 | // which would lead to a double signal 471 | go func() { 472 | <-ctx.Done() 473 | a.Lock() 474 | defer a.Unlock() 475 | _ = cmd.Wait() 476 | }() 477 | 478 | return cmd.Start() 479 | } 480 | 481 | func (a *Agent) Stop() error { 482 | a.Lock() 483 | defer a.Unlock() 484 | if a.stopping || a.stopped { 485 | log.Printf("Already stopped or stopping") 486 | return nil 487 | } 488 | a.stopping = true 489 | err := a.stopFunc() 490 | a.stopped = true 491 | return err 492 | } 493 | 494 | func createAgentBootstrap(checkoutPath string) (*os.File, error) { 495 | tempFileNamePattern := "bootstrap-" 496 | if runtime.GOOS == "windows" { 497 | tempFileNamePattern = "bootstrap-*.bat" 498 | } 499 | tmpFile, err := ioutil.TempFile(os.TempDir(), tempFileNamePattern) 500 | if err != nil { 501 | return nil, err 502 | } 503 | 504 | debugf("Creating bootrap script at %s", tmpFile.Name()) 505 | 506 | var text []byte 507 | if runtime.GOOS == "windows" { 508 | text = []byte(fmt.Sprintf(`@ECHO OFF 509 | SET "BUILDKITE_BUILD_CHECKOUT_PATH=%s" 510 | SET "BUILDKITE_BOOTSTRAP_PHASES=plugin,command" 511 | buildkite-agent bootstrap`, checkoutPath)) 512 | } else { 513 | text = []byte(fmt.Sprintf(`#!/bin/sh 514 | export BUILDKITE_BUILD_CHECKOUT_PATH=%s 515 | export BUILDKITE_BOOTSTRAP_PHASES=plugin,command 516 | buildkite-agent bootstrap`, checkoutPath)) 517 | } 518 | 519 | if _, err = tmpFile.Write(text); err != nil { 520 | return nil, err 521 | } 522 | 523 | if err := tmpFile.Close(); err != nil { 524 | return nil, err 525 | } 526 | 527 | if err = os.Chmod(tmpFile.Name(), 0700); err != nil { 528 | return nil, err 529 | } 530 | 531 | return tmpFile, nil 532 | } 533 | 534 | type stepWithEnv struct { 535 | step 536 | Env []string 537 | } 538 | 539 | type stepQueue struct { 540 | sync.Mutex 541 | steps []stepWithEnv 542 | } 543 | 544 | func newStepQueue() *stepQueue { 545 | return &stepQueue{ 546 | steps: []stepWithEnv{}, 547 | } 548 | } 549 | 550 | func (s *stepQueue) Len() int { 551 | s.Lock() 552 | defer s.Unlock() 553 | 554 | return len(s.steps) 555 | } 556 | 557 | func (s *stepQueue) Replace(p pipeline) { 558 | panic("Replace not implemented") 559 | } 560 | 561 | func (s *stepQueue) Prepend(p pipeline) { 562 | s.Lock() 563 | defer s.Unlock() 564 | 565 | var newSteps []stepWithEnv 566 | 567 | for _, step := range p.Steps { 568 | newSteps = append(newSteps, stepWithEnv{ 569 | step: step, 570 | Env: p.Env, 571 | }) 572 | } 573 | 574 | s.steps = append(newSteps, s.steps...) 575 | } 576 | 577 | func (s *stepQueue) Next() (stepWithEnv, bool) { 578 | s.Lock() 579 | defer s.Unlock() 580 | 581 | if len(s.steps) == 0 { 582 | return stepWithEnv{}, false 583 | } 584 | 585 | var next stepWithEnv 586 | next, s.steps = s.steps[0], s.steps[1:] 587 | 588 | return next, true 589 | } 590 | -------------------------------------------------------------------------------- /runner/server.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | import ( 4 | "compress/gzip" 5 | "crypto/sha1" 6 | "encoding/json" 7 | "fmt" 8 | "io" 9 | "io/ioutil" 10 | "log" 11 | "net" 12 | "net/http" 13 | "os" 14 | "path/filepath" 15 | "regexp" 16 | "strconv" 17 | "strings" 18 | "sync" 19 | 20 | "github.com/bmatcuk/doublestar" 21 | "github.com/fatih/color" 22 | homedir "github.com/mitchellh/go-homedir" 23 | uuid "github.com/satori/go.uuid" 24 | ) 25 | 26 | type Build struct { 27 | ID string 28 | Number int 29 | URL string 30 | } 31 | 32 | type Job struct { 33 | ID string 34 | Build Build 35 | State string 36 | ProjectSlug string 37 | PipelineSlug string 38 | OrganizationSlug string 39 | ArtifactPaths []string 40 | CreatorName string 41 | CreatorEmail string 42 | Command string 43 | Label string 44 | Timeout int 45 | Repository string 46 | Commit string 47 | Branch string 48 | Tag string 49 | Message string 50 | RetryCount int 51 | Plugins []Plugin 52 | Env []string 53 | Artifacts []Artifact 54 | } 55 | 56 | type Artifact struct { 57 | ID string `json:"-"` 58 | Path string `json:"path"` 59 | AbsolutePath string `json:"absolute_path"` 60 | GlobPath string `json:"glob_path"` 61 | FileSize int64 `json:"file_size"` 62 | Sha1Sum string `json:"sha1sum"` 63 | URL string `json:"url,omitempty"` 64 | UploadDestination string `json:"upload_destination,omitempty"` 65 | 66 | uploaded bool 67 | localPath string 68 | } 69 | 70 | type jobEnvelope struct { 71 | Job 72 | exitCh chan int 73 | writer io.Writer 74 | } 75 | 76 | var ( 77 | uuidRegexp = regexp.MustCompile( 78 | "([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})") 79 | ) 80 | 81 | type apiServer struct { 82 | agents *agentPool 83 | pipelineUploads chan pipelineUpload 84 | listener net.Listener 85 | listenPort int 86 | 87 | sync.Mutex 88 | jobs []*jobEnvelope 89 | artifacts *orderedMap 90 | metadata *orderedMap 91 | } 92 | 93 | func newApiServer(agentPool *agentPool, listenPort int) *apiServer { 94 | return &apiServer{ 95 | agents: agentPool, 96 | pipelineUploads: make(chan pipelineUpload), 97 | jobs: []*jobEnvelope{}, 98 | artifacts: newOrderedMap(), 99 | metadata: newOrderedMap(), 100 | listenPort: listenPort, 101 | } 102 | } 103 | 104 | func (s *apiServer) Execute(job Job, w io.Writer) chan int { 105 | js := &jobEnvelope{ 106 | Job: job, 107 | exitCh: make(chan int, 1), 108 | writer: w, 109 | } 110 | 111 | s.Lock() 112 | defer s.Unlock() 113 | s.jobs = append(s.jobs, js) 114 | 115 | return js.exitCh 116 | } 117 | 118 | func (s *apiServer) HasUnfinishedJobs() bool { 119 | s.Lock() 120 | defer s.Unlock() 121 | for _, j := range s.jobs { 122 | if j.State != "finished" { 123 | return true 124 | } 125 | } 126 | return false 127 | } 128 | 129 | func (s *apiServer) changeJobState(jobID string, from, to string) (*jobEnvelope, error) { 130 | j, err := s.getJobByID(jobID) 131 | if err != nil { 132 | return nil, err 133 | } 134 | 135 | if j.State != from { 136 | return nil, fmt.Errorf("Job state is %q, expected %q", j.State, from) 137 | } 138 | j.State = to 139 | return j, nil 140 | } 141 | 142 | func (s *apiServer) getJobByID(jobID string) (*jobEnvelope, error) { 143 | for idx, j := range s.jobs { 144 | if j.ID == jobID { 145 | return s.jobs[idx], nil 146 | } 147 | } 148 | 149 | return nil, fmt.Errorf("No job with id %q found", jobID) 150 | } 151 | 152 | func (s *apiServer) nextJob() (*jobEnvelope, bool) { 153 | for _, j := range s.jobs { 154 | if j.State == "" { 155 | j.State = "scheduled" 156 | return j, true 157 | } 158 | } 159 | return nil, false 160 | } 161 | 162 | func (a *apiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { 163 | debugf("[http] %s %s %s", r.Method, r.RequestURI, r.RemoteAddr) 164 | 165 | requestPath := uuidRegexp.ReplaceAllString(r.Method+" "+r.URL.Path, ":uuid") 166 | 167 | switch requestPath { 168 | case `POST /register`: 169 | a.handleRegister(w, r) 170 | case `POST /connect`: 171 | a.handleConnect(w, r) 172 | case `POST /disconnect`: 173 | a.handleDisconnect(w, r) 174 | case `POST /heartbeat`: 175 | a.handleHeartbeat(w, r) 176 | case `GET /ping`: 177 | a.handlePing(w, r) 178 | case `GET /jobs/:uuid`: 179 | a.handleGetJob(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 180 | case `PUT /jobs/:uuid/start`: 181 | a.handleStartJob(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 182 | case `PUT /jobs/:uuid/accept`: 183 | a.handleAcceptJob(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 184 | case `PUT /jobs/:uuid/finish`: 185 | a.handleFinishJob(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 186 | case `POST /jobs/:uuid/chunks`: 187 | a.handleLogChunks(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 188 | case `POST /jobs/:uuid/header_times`: 189 | a.handleHeaderTimes(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 190 | case `POST /jobs/:uuid/data/exists`: 191 | a.handleMetadataExists(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 192 | case `POST /jobs/:uuid/data/keys`: 193 | a.handleMetadataKeys(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 194 | case `POST /jobs/:uuid/data/set`: 195 | a.handleMetadataSet(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 196 | case `POST /jobs/:uuid/data/get`: 197 | a.handleMetadataGet(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 198 | case `POST /jobs/:uuid/pipelines`: 199 | a.handlePipelineUpload(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 200 | case `POST /jobs/:uuid/annotations`: 201 | a.handleAnnotations(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 202 | case `POST /jobs/:uuid/artifacts`: 203 | a.handleArtifactsUploadInstructions(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 204 | case `POST /jobs/:uuid/artifacts/upload`: 205 | a.handleArtifactsUpload(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 206 | case `PUT /jobs/:uuid/artifacts`: 207 | a.handleArtifactsUpdate(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 208 | case `GET /builds/:uuid/artifacts/search`: 209 | a.handleArtifactsSearch(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 210 | case `GET /artifacts/:uuid`: 211 | a.handleArtifactDownload(w, r, uuidRegexp.FindStringSubmatch(r.URL.Path)[1]) 212 | default: 213 | color.Red(">>> 😓 An unknown agent API endpoint was requested (%s).\n"+ 214 | "File an issue at https://github.com/buildkite/cli/issues and we'll see what we can do!\n", 215 | requestPath, 216 | ) 217 | http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) 218 | } 219 | } 220 | 221 | func (a *apiServer) handleRegister(w http.ResponseWriter, r *http.Request) { 222 | u := uuid.NewV4() 223 | 224 | agent := agent{ 225 | ID: u.String(), 226 | AccessToken: fmt.Sprintf("%x", sha1.Sum(u.Bytes())), 227 | Name: "local", 228 | } 229 | 230 | a.agents.Register(agent) 231 | 232 | w.Header().Set("Content-Type", "application/json") 233 | json.NewEncoder(w).Encode(struct { 234 | ID string `json:"id,omitempty"` 235 | Name string `json:"name,omitempty"` 236 | Endpoint interface{} `json:"endpoint,omitempty"` 237 | AccessToken string `json:"access_token,omitempty"` 238 | PingInterval int `json:"ping_interval,omitempty"` 239 | JobStatusInterval int `json:"job_status_interval,omitempty"` 240 | HeartbeatInterval int `json:"heartbeat_interval,omitempty"` 241 | MetaData []string `json:"meta_data,omitempty"` 242 | }{ 243 | ID: agent.ID, 244 | Name: agent.Name, 245 | AccessToken: agent.AccessToken, 246 | PingInterval: 1, 247 | JobStatusInterval: 1, 248 | HeartbeatInterval: 1, 249 | MetaData: []string{"queue=default"}, 250 | }) 251 | } 252 | 253 | func (a *apiServer) handleConnect(w http.ResponseWriter, r *http.Request) { 254 | agentID, err := a.authenticateAgentFromHeader(r.Header) 255 | if err != nil { 256 | http.Error(w, err.Error(), http.StatusUnauthorized) 257 | return 258 | } 259 | 260 | a.agents.Connect(agentID) 261 | 262 | w.Header().Set("Content-Type", "application/json") 263 | json.NewEncoder(w).Encode(struct { 264 | ID string `json:"id"` 265 | ConnectionState string `json:"connection_state"` 266 | }{ 267 | agentID, "connected", 268 | }) 269 | } 270 | 271 | func (a *apiServer) handleDisconnect(w http.ResponseWriter, r *http.Request) { 272 | agentID, err := a.authenticateAgentFromHeader(r.Header) 273 | if err != nil { 274 | http.Error(w, err.Error(), http.StatusUnauthorized) 275 | return 276 | } 277 | 278 | a.agents.Disconnect(agentID) 279 | 280 | w.Header().Set("Content-Type", "application/json") 281 | json.NewEncoder(w).Encode(struct { 282 | ConnectionState string `json:"connection_state"` 283 | }{ 284 | "disconnected", 285 | }) 286 | } 287 | 288 | func (a *apiServer) handlePing(w http.ResponseWriter, r *http.Request) { 289 | _, err := a.authenticateAgentFromHeader(r.Header) 290 | if err != nil { 291 | http.Error(w, err.Error(), http.StatusUnauthorized) 292 | return 293 | } 294 | 295 | w.Header().Set("Content-Type", "application/json") 296 | 297 | a.Lock() 298 | defer a.Unlock() 299 | 300 | j, ok := a.nextJob() 301 | if !ok { 302 | json.NewEncoder(w).Encode(struct{}{}) 303 | return 304 | } 305 | 306 | json.NewEncoder(w).Encode(map[string]map[string]string{ 307 | "job": map[string]string{ 308 | "id": j.ID, 309 | }, 310 | }) 311 | } 312 | 313 | func (a *apiServer) handleHeartbeat(w http.ResponseWriter, r *http.Request) { 314 | _, err := a.authenticateAgentFromHeader(r.Header) 315 | if err != nil { 316 | http.Error(w, err.Error(), http.StatusUnauthorized) 317 | return 318 | } 319 | 320 | w.Header().Set("Content-Type", "application/json") 321 | json.NewEncoder(w).Encode(struct{}{}) 322 | } 323 | 324 | func (a *apiServer) handleAcceptJob(w http.ResponseWriter, r *http.Request, jobID string) { 325 | agentID, err := a.authenticateAgentFromHeader(r.Header) 326 | if err != nil { 327 | http.Error(w, err.Error(), http.StatusUnauthorized) 328 | return 329 | } 330 | 331 | agent, err := a.agents.Get(agentID) 332 | if err != nil { 333 | http.Error(w, err.Error(), http.StatusUnauthorized) 334 | return 335 | } 336 | 337 | a.Lock() 338 | defer a.Unlock() 339 | 340 | job, err := a.changeJobState(jobID, "scheduled", "accepted") 341 | if err != nil { 342 | http.Error(w, err.Error(), http.StatusInternalServerError) 343 | return 344 | } 345 | 346 | pluginJSON := "[]" 347 | if len(job.Plugins) > 0 { 348 | var err error 349 | pluginJSON, err = marshalPlugins(job.Plugins) 350 | if err != nil { 351 | http.Error(w, err.Error(), http.StatusInternalServerError) 352 | return 353 | } 354 | } 355 | 356 | env := map[string]string{ 357 | `CI`: `true`, 358 | `BUILDKITE`: `true`, 359 | `BUILDKITE_TAG`: job.Tag, 360 | `BUILDKITE_REPO`: job.Repository, 361 | `BUILDKITE_LABEL`: job.Label, 362 | `BUILDKITE_BRANCH`: job.Branch, 363 | `BUILDKITE_COMMIT`: job.Commit, 364 | `BUILDKITE_JOB_ID`: job.ID, 365 | `BUILDKITE_SOURCE`: `local`, 366 | `BUILDKITE_COMMAND`: job.Command, 367 | `BUILDKITE_MESSAGE`: job.Message, 368 | `BUILDKITE_TIMEOUT`: fmt.Sprintf("%d", job.Timeout), 369 | `BUILDKITE_AGENT_ID`: agentID, 370 | `BUILDKITE_BUILD_ID`: job.Build.ID, 371 | `BUILDKITE_BUILD_URL`: job.Build.URL, 372 | `BUILDKITE_AGENT_NAME`: agent.Name, 373 | `BUILDKITE_RETRY_COUNT`: fmt.Sprintf("%d", job.RetryCount), 374 | `BUILDKITE_SCRIPT_PATH`: ``, 375 | `BUILDKITE_BUILD_NUMBER`: fmt.Sprintf("%d", job.Build.Number), 376 | `BUILDKITE_PROJECT_SLUG`: job.ProjectSlug, 377 | `BUILDKITE_PULL_REQUEST`: `false`, 378 | `BUILDKITE_PULL_REQUEST_REPO`: ``, 379 | `BUILDKITE_PULL_REQUEST_BASE_BRANCH`: ``, 380 | `BUILDKITE_BUILD_CREATOR`: job.CreatorName, 381 | `BUILDKITE_BUILD_CREATOR_EMAIL`: job.CreatorEmail, 382 | `BUILDKITE_PIPELINE_SLUG`: job.PipelineSlug, 383 | `BUILDKITE_ARTIFACT_PATHS`: strings.Join(job.ArtifactPaths, ","), 384 | `BUILDKITE_PROJECT_PROVIDER`: `local`, 385 | `BUILDKITE_ORGANIZATION_SLUG`: job.OrganizationSlug, 386 | `BUILDKITE_PIPELINE_PROVIDER`: `local`, 387 | `BUILDKITE_AGENT_META_DATA_QUEUE`: `default`, 388 | `BUILDKITE_REBUILT_FROM_BUILD_ID`: ``, 389 | `BUILDKITE_REBUILT_FROM_BUILD_NUMBER`: ``, 390 | `BUILDKITE_PIPELINE_DEFAULT_BRANCH`: `master`, 391 | `BUILDKITE_TRIGGERED_FROM_BUILD_ID`: ``, 392 | `BUILDKITE_PLUGINS`: pluginJSON, 393 | } 394 | 395 | jobEnv := map[string]string{} 396 | 397 | // append step environment, letting later ones 398 | // overwrite earlier ones 399 | for _, envLine := range job.Env { 400 | envFrags := strings.SplitN(envLine, "=", 2) 401 | jobEnv[envFrags[0]] = envFrags[1] 402 | } 403 | 404 | // append stepEnv to the job environment but 405 | // don't overwrite any already values 406 | for k, v := range jobEnv { 407 | if _, exists := env[k]; !exists { 408 | env[k] = v 409 | } 410 | } 411 | 412 | w.Header().Set("Content-Type", "application/json") 413 | json.NewEncoder(w).Encode(struct { 414 | ID string `json:"id"` 415 | State string `json:"state"` 416 | Env map[string]string `json:"env"` 417 | Endpoint string `json:"endpoint"` 418 | ChunksMaxSizeBytes int `json:"chunks_max_size_bytes"` 419 | }{ 420 | ID: job.ID, 421 | State: "accepted", 422 | Endpoint: fmt.Sprintf("http://%s", r.Host), 423 | ChunksMaxSizeBytes: 102400, 424 | Env: env, 425 | }) 426 | } 427 | 428 | func (a *apiServer) handleGetJob(w http.ResponseWriter, r *http.Request, jobID string) { 429 | a.Lock() 430 | defer a.Unlock() 431 | 432 | job, err := a.getJobByID(jobID) 433 | if err != nil { 434 | http.Error(w, err.Error(), http.StatusInternalServerError) 435 | return 436 | } 437 | 438 | w.Header().Set("Content-Type", "application/json") 439 | json.NewEncoder(w).Encode(struct { 440 | State string `json:"state"` 441 | }{ 442 | State: job.State, 443 | }) 444 | } 445 | 446 | func (a *apiServer) handleStartJob(w http.ResponseWriter, r *http.Request, jobID string) { 447 | _, err := a.authenticateAgentFromHeader(r.Header) 448 | if err != nil { 449 | http.Error(w, err.Error(), http.StatusUnauthorized) 450 | return 451 | } 452 | 453 | a.Lock() 454 | defer a.Unlock() 455 | 456 | job, err := a.changeJobState(jobID, "accepted", "started") 457 | if err != nil { 458 | http.Error(w, err.Error(), http.StatusInternalServerError) 459 | return 460 | } 461 | 462 | w.Header().Set("Content-Type", "application/json") 463 | json.NewEncoder(w).Encode(struct { 464 | State string `json:"state"` 465 | }{ 466 | State: job.State, 467 | }) 468 | } 469 | 470 | func (a *apiServer) handleFinishJob(w http.ResponseWriter, r *http.Request, jobID string) { 471 | _, err := a.authenticateAgentFromHeader(r.Header) 472 | if err != nil { 473 | http.Error(w, err.Error(), http.StatusUnauthorized) 474 | return 475 | } 476 | 477 | var rr struct { 478 | ExitStatus string `json:"exit_status"` 479 | } 480 | if err := readRequestInto(r, &rr); err != nil { 481 | http.Error(w, err.Error(), http.StatusInternalServerError) 482 | return 483 | } 484 | 485 | a.Lock() 486 | defer a.Unlock() 487 | 488 | job, err := a.changeJobState(jobID, "started", "finished") 489 | if err != nil { 490 | http.Error(w, err.Error(), http.StatusInternalServerError) 491 | return 492 | } 493 | 494 | exitCodeInt, err := strconv.Atoi(rr.ExitStatus) 495 | if err != nil { 496 | http.Error(w, err.Error(), http.StatusInternalServerError) 497 | return 498 | } 499 | 500 | job.exitCh <- exitCodeInt 501 | 502 | w.Header().Set("Content-Type", "application/json") 503 | json.NewEncoder(w).Encode(struct { 504 | State string `json:"state"` 505 | }{ 506 | State: job.State, 507 | }) 508 | } 509 | 510 | func (a *apiServer) handleMetadataKeys(w http.ResponseWriter, r *http.Request, jobID string) { 511 | w.Header().Set("Content-Type", "application/json") 512 | json.NewEncoder(w).Encode(a.metadata.Keys()) 513 | } 514 | 515 | func (a *apiServer) handleMetadataExists(w http.ResponseWriter, r *http.Request, jobID string) { 516 | w.Header().Set("Content-Type", "application/json") 517 | 518 | var parsed struct { 519 | Key string `json:"key"` 520 | } 521 | err := readRequestInto(r, &parsed) 522 | if err != nil { 523 | http.Error(w, err.Error(), http.StatusBadRequest) 524 | return 525 | } 526 | 527 | if !a.metadata.Contains(parsed.Key) { 528 | http.Error(w, "Not found", http.StatusNotFound) 529 | return 530 | } 531 | 532 | json.NewEncoder(w).Encode(&struct { 533 | Exists bool `json:"exists"` 534 | }{ 535 | Exists: true, 536 | }) 537 | } 538 | 539 | func (a *apiServer) SetMetadata(k, v string) { 540 | a.metadata.Store(k, v) 541 | } 542 | 543 | func (a *apiServer) handleMetadataSet(w http.ResponseWriter, r *http.Request, jobID string) { 544 | w.Header().Set("Content-Type", "application/json") 545 | 546 | var parsed struct { 547 | Key string `json:"key"` 548 | Value string `json:"value"` 549 | } 550 | err := readRequestInto(r, &parsed) 551 | if err != nil { 552 | http.Error(w, err.Error(), http.StatusBadRequest) 553 | return 554 | } 555 | 556 | a.metadata.Store(parsed.Key, parsed.Value) 557 | json.NewEncoder(w).Encode(&struct{}{}) 558 | } 559 | 560 | func (a *apiServer) handleMetadataGet(w http.ResponseWriter, r *http.Request, jobID string) { 561 | w.Header().Set("Content-Type", "application/json") 562 | 563 | var parsed struct { 564 | Key string `json:"key"` 565 | } 566 | err := readRequestInto(r, &parsed) 567 | if err != nil { 568 | http.Error(w, err.Error(), http.StatusBadRequest) 569 | return 570 | } 571 | 572 | val, ok := a.metadata.Load(parsed.Key) 573 | if !ok { 574 | http.Error(w, "Not found", http.StatusNotFound) 575 | return 576 | } 577 | 578 | json.NewEncoder(w).Encode(&struct { 579 | Key string `json:"key"` 580 | Value string `json:"value"` 581 | }{ 582 | parsed.Key, val.(string), 583 | }) 584 | } 585 | 586 | func (a *apiServer) handleHeaderTimes(w http.ResponseWriter, r *http.Request, jobID string) { 587 | w.Header().Set("Content-Type", "application/json") 588 | json.NewEncoder(w).Encode(&struct{}{}) 589 | } 590 | 591 | func (a *apiServer) handleAnnotations(w http.ResponseWriter, r *http.Request, jobID string) { 592 | w.Header().Set("Content-Type", "application/json") 593 | json.NewEncoder(w).Encode(&struct{}{}) 594 | } 595 | 596 | func (a *apiServer) handleLogChunks(w http.ResponseWriter, r *http.Request, jobID string) { 597 | gr, err := gzip.NewReader(r.Body) 598 | if err != nil { 599 | http.Error(w, err.Error(), http.StatusBadRequest) 600 | return 601 | } 602 | defer gr.Close() 603 | 604 | b, err := ioutil.ReadAll(gr) 605 | if err != nil { 606 | http.Error(w, err.Error(), http.StatusBadRequest) 607 | return 608 | } 609 | 610 | a.Lock() 611 | defer a.Unlock() 612 | 613 | job, err := a.getJobByID(jobID) 614 | if err != nil { 615 | http.Error(w, err.Error(), http.StatusInternalServerError) 616 | return 617 | } 618 | 619 | job.writer.Write(b) 620 | 621 | w.Header().Set("Content-Type", "application/json") 622 | json.NewEncoder(w).Encode(struct { 623 | ID string `json:"id"` 624 | }{ 625 | ID: uuid.NewV4().String(), 626 | }) 627 | } 628 | 629 | func (a *apiServer) handlePipelineUpload(w http.ResponseWriter, r *http.Request, jobID string) { 630 | var pur struct { 631 | UUID string `json:"uuid"` 632 | pipelineUpload 633 | } 634 | 635 | if err := readRequestInto(r, &pur); err != nil { 636 | log.Printf("Failed to parse pipeline upload: %v", err) 637 | http.Error(w, err.Error(), 422) 638 | return 639 | } 640 | 641 | a.pipelineUploads <- pur.pipelineUpload 642 | 643 | w.Header().Set("Content-Type", "application/json") 644 | json.NewEncoder(w).Encode(&struct{}{}) 645 | } 646 | 647 | type uploadAction struct { 648 | URL string `json:"url,omitempty"` 649 | Method string `json:"method"` 650 | Path string `json:"path"` 651 | FileInput string `json:"file_input"` 652 | } 653 | 654 | type uploadInstructions struct { 655 | Data map[string]string `json:"data"` 656 | Action uploadAction `json:"action"` 657 | } 658 | 659 | func (a *apiServer) handleArtifactsUploadInstructions(w http.ResponseWriter, r *http.Request, jobID string) { 660 | var artifactBatch struct { 661 | ID string `json:"id"` 662 | Artifacts []Artifact `json:"artifacts"` 663 | UploadDestination string `json:"upload_destination"` 664 | } 665 | 666 | if err := readRequestInto(r, &artifactBatch); err != nil { 667 | http.Error(w, err.Error(), http.StatusInternalServerError) 668 | return 669 | } 670 | 671 | a.Lock() 672 | defer a.Unlock() 673 | 674 | job, err := a.getJobByID(jobID) 675 | if err != nil { 676 | http.Error(w, err.Error(), http.StatusInternalServerError) 677 | return 678 | } 679 | 680 | var artifactIDs []string 681 | 682 | for idx := range artifactBatch.Artifacts { 683 | artifactID := uuid.NewV4().String() 684 | artifactIDs = append(artifactIDs, artifactID) 685 | artifactBatch.Artifacts[idx].ID = artifactID 686 | artifactBatch.Artifacts[idx].URL = fmt.Sprintf("http://%s/artifacts/%s", a.listener.Addr().String(), artifactID) 687 | } 688 | 689 | job.Artifacts = artifactBatch.Artifacts 690 | 691 | w.Header().Set("Content-Type", "application/json") 692 | json.NewEncoder(w).Encode(&struct { 693 | ID string `json:"id"` 694 | ArtifactIDs []string `json:"artifact_ids"` 695 | UploadInstructions uploadInstructions `json:"upload_instructions"` 696 | }{ 697 | uuid.NewV4().String(), 698 | artifactIDs, 699 | uploadInstructions{ 700 | Action: uploadAction{ 701 | fmt.Sprintf("http://%s", a.listener.Addr().String()), 702 | "POST", 703 | fmt.Sprintf("/jobs/%s/artifacts/upload", jobID), 704 | "file", 705 | }, 706 | }, 707 | }) 708 | } 709 | 710 | func (a *apiServer) handleArtifactsUpload(w http.ResponseWriter, r *http.Request, jobID string) { 711 | file, header, err := r.FormFile("file") 712 | if err != nil { 713 | fmt.Fprintln(w, err) 714 | return 715 | } 716 | defer file.Close() 717 | 718 | cacheDir, err := artifactCachePath() 719 | if err != nil { 720 | http.Error(w, err.Error(), http.StatusInternalServerError) 721 | return 722 | } 723 | 724 | path := filepath.Join(cacheDir, jobID, header.Filename) 725 | 726 | if err = os.MkdirAll(filepath.Dir(path), 0700); err != nil { 727 | http.Error(w, err.Error(), http.StatusInternalServerError) 728 | return 729 | } 730 | 731 | out, err := os.Create(path) 732 | if err != nil { 733 | log.Printf("Unable to create %s for writing. Check your write access privilege", path) 734 | return 735 | } 736 | 737 | defer out.Close() 738 | 739 | // write the content from POST to the file 740 | _, err = io.Copy(out, file) 741 | if err != nil { 742 | fmt.Fprintln(w, err) 743 | } 744 | 745 | a.Lock() 746 | defer a.Unlock() 747 | 748 | job, err := a.getJobByID(jobID) 749 | if err != nil { 750 | http.Error(w, err.Error(), http.StatusInternalServerError) 751 | return 752 | } 753 | 754 | for idx := range job.Artifacts { 755 | if header.Filename == job.Artifacts[idx].Path { 756 | job.Artifacts[idx].uploaded = true 757 | job.Artifacts[idx].localPath = path 758 | } 759 | } 760 | 761 | fmt.Fprintf(w, "File uploaded successfully: %s", header.Filename) 762 | } 763 | 764 | func (a *apiServer) handleArtifactsUpdate(w http.ResponseWriter, r *http.Request, jobID string) { 765 | var rr struct { 766 | Artifacts []struct { 767 | ID string `json:"id"` 768 | State string `json:"state"` 769 | } `json:"artifacts"` 770 | } 771 | 772 | if err := readRequestInto(r, &rr); err != nil { 773 | http.Error(w, err.Error(), http.StatusInternalServerError) 774 | return 775 | } 776 | 777 | a.Lock() 778 | defer a.Unlock() 779 | 780 | job, err := a.getJobByID(jobID) 781 | if err != nil { 782 | http.Error(w, err.Error(), http.StatusInternalServerError) 783 | return 784 | } 785 | 786 | for _, updatedArtifact := range rr.Artifacts { 787 | for _, jobArtifact := range job.Artifacts { 788 | if jobArtifact.ID == updatedArtifact.ID && updatedArtifact.State == `finished` { 789 | a.artifacts.Store(jobArtifact.ID, jobArtifact) 790 | } 791 | } 792 | } 793 | 794 | w.Header().Set("Content-Type", "application/json") 795 | json.NewEncoder(w).Encode(&struct{}{}) 796 | } 797 | 798 | func (a *apiServer) handleArtifactsSearch(w http.ResponseWriter, r *http.Request, buildID string) { 799 | query := r.URL.Query().Get("query") 800 | 801 | a.Lock() 802 | defer a.Unlock() 803 | 804 | var artifacts []Artifact 805 | 806 | for _, key := range a.artifacts.Keys() { 807 | value, ok := a.artifacts.Load(key) 808 | if !ok { 809 | continue 810 | } 811 | 812 | artifact := value.(Artifact) 813 | match, err := doublestar.PathMatch(query, artifact.Path) 814 | if err != nil { 815 | log.Printf("Err: %v", err) 816 | } 817 | 818 | if match { 819 | artifacts = append(artifacts, artifact) 820 | } 821 | } 822 | 823 | w.Header().Set("Content-Type", "application/json") 824 | json.NewEncoder(w).Encode(artifacts) 825 | } 826 | 827 | func (a *apiServer) handleArtifactDownload(w http.ResponseWriter, r *http.Request, artifactID string) { 828 | a.Lock() 829 | defer a.Unlock() 830 | 831 | artifact, ok := a.artifacts.Load(artifactID) 832 | if !ok { 833 | http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) 834 | } 835 | 836 | f, err := os.Open(artifact.(Artifact).localPath) 837 | if err != nil { 838 | http.Error(w, err.Error(), http.StatusInternalServerError) 839 | return 840 | } 841 | defer f.Close() 842 | 843 | _, err = io.Copy(w, f) 844 | if err != nil { 845 | http.Error(w, err.Error(), http.StatusInternalServerError) 846 | return 847 | } 848 | } 849 | 850 | func readRequestInto(r *http.Request, into interface{}) error { 851 | body, err := ioutil.ReadAll(r.Body) 852 | if err != nil { 853 | panic(err) 854 | } 855 | defer r.Body.Close() 856 | 857 | return json.Unmarshal(body, &into) 858 | } 859 | 860 | func (a *apiServer) ListenAndServe() (string, error) { 861 | var err error 862 | a.listener, err = net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", a.listenPort)) 863 | if err != nil { 864 | return "", err 865 | } 866 | 867 | go func() { 868 | _ = http.Serve(a.listener, a) 869 | }() 870 | 871 | return fmt.Sprintf("http://%s", a.listener.Addr().String()), nil 872 | } 873 | 874 | func (a *apiServer) authenticateAgentFromHeader(h http.Header) (string, error) { 875 | authToken := strings.TrimPrefix(h.Get(`Authorization`), `Token `) 876 | return a.agents.Authenticate(authToken) 877 | } 878 | 879 | func artifactCachePath() (string, error) { 880 | home, err := homedir.Dir() 881 | if err != nil { 882 | return "", err 883 | } 884 | return filepath.Join(home, ".buildkite", "local", "artifacts"), nil 885 | } 886 | 887 | type orderedMapValue struct { 888 | key string 889 | value interface{} 890 | } 891 | 892 | type orderedMap struct { 893 | idx map[string]int 894 | vals []orderedMapValue 895 | mu sync.RWMutex 896 | } 897 | 898 | func newOrderedMap() *orderedMap { 899 | return &orderedMap{ 900 | idx: map[string]int{}, 901 | vals: []orderedMapValue{}, 902 | } 903 | } 904 | 905 | func (o *orderedMap) Contains(key string) bool { 906 | o.mu.RLock() 907 | defer o.mu.RUnlock() 908 | _, ok := o.idx[key] 909 | return ok 910 | } 911 | 912 | func (o *orderedMap) Keys() []string { 913 | o.mu.RLock() 914 | defer o.mu.RUnlock() 915 | keys := []string{} 916 | for _, val := range o.vals { 917 | keys = append(keys, val.key) 918 | } 919 | return keys 920 | } 921 | 922 | func (o *orderedMap) Load(key string) (interface{}, bool) { 923 | o.mu.RLock() 924 | defer o.mu.RUnlock() 925 | idx, ok := o.idx[key] 926 | if !ok { 927 | return nil, false 928 | } 929 | return o.vals[idx].value, true 930 | } 931 | 932 | func (o *orderedMap) Store(key string, value interface{}) { 933 | o.mu.Lock() 934 | defer o.mu.Unlock() 935 | idx, ok := o.idx[key] 936 | if !ok { 937 | o.vals = append(o.vals, orderedMapValue{key, value}) 938 | o.idx[key] = len(o.vals) - 1 939 | } else { 940 | o.vals[idx] = orderedMapValue{key, value} 941 | } 942 | } 943 | -------------------------------------------------------------------------------- /runner/server_test.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | ) 7 | 8 | func TestOrderedMapStoreAndLoad(t *testing.T) { 9 | om := newOrderedMap() 10 | om.Store("a", true) 11 | om.Store("b", false) 12 | om.Store("c", 24) 13 | om.Store("a", 32) 14 | 15 | for _, val := range []string{"a", "b", "c"} { 16 | if om.Contains(val) == false { 17 | t.Fatalf("Expected to contain %s", val) 18 | } 19 | } 20 | 21 | if om.Contains("nope") == true { 22 | t.Fatalf("Unexpected to contain nope") 23 | } 24 | 25 | val, ok := om.Load("a") 26 | if !ok { 27 | t.Fatalf("Not ok") 28 | } 29 | if val != 32 { 30 | t.Fatalf("Bad %v (%T)", val, val) 31 | } 32 | 33 | val, ok = om.Load("b") 34 | if !ok { 35 | t.Fatalf("Not ok") 36 | } 37 | if val != false { 38 | t.Fatalf("Bad %v (%T)", val, val) 39 | } 40 | 41 | val, ok = om.Load("c") 42 | if !ok { 43 | t.Fatalf("Not ok") 44 | } 45 | if val != 24 { 46 | t.Fatalf("Bad %v (%T)", val, val) 47 | } 48 | } 49 | 50 | func TestOrderedMapKeys(t *testing.T) { 51 | om := newOrderedMap() 52 | om.Store("a", true) 53 | om.Store("b", false) 54 | om.Store("c", 24) 55 | om.Store("a", 32) 56 | 57 | keys := om.Keys() 58 | 59 | if !reflect.DeepEqual(keys, []string{"a", "b", "c"}) { 60 | t.Fatalf("Unexpected keys: %#v", keys) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /runner/writer.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | import ( 4 | "bytes" 5 | "regexp" 6 | ) 7 | 8 | type lineWriter struct { 9 | f func(line string) 10 | started bool 11 | buf *bytes.Buffer 12 | offset int 13 | } 14 | 15 | var lineRegexp = regexp.MustCompile(`(?m:^(.*)\r?\n)`) 16 | 17 | func newLineWriter(f func(line string)) *lineWriter { 18 | return &lineWriter{ 19 | f: f, 20 | buf: bytes.NewBuffer([]byte("")), 21 | } 22 | } 23 | 24 | func (l *lineWriter) Write(p []byte) (n int, err error) { 25 | if bytes.ContainsRune(p, '\n') { 26 | l.started = true 27 | } 28 | 29 | if n, err = l.buf.Write(p); err != nil { 30 | return 31 | } 32 | 33 | matches := lineRegexp.FindAllStringSubmatch(l.buf.String()[l.offset:], -1) 34 | 35 | for _, match := range matches { 36 | l.f(match[1]) 37 | l.offset += len(match[0]) 38 | } 39 | 40 | return 41 | } 42 | 43 | func (l *lineWriter) Close() error { 44 | if remaining := l.buf.String()[l.offset:]; len(remaining) > 0 { 45 | l.f(remaining) 46 | } 47 | l.buf = bytes.NewBuffer([]byte("")) 48 | return nil 49 | } 50 | --------------------------------------------------------------------------------