{"id":20355926,"url":"https://github.com/hedzr/bgo","last_synced_at":"2025-07-05T09:33:15.311Z","repository":{"id":57654154,"uuid":"453423597","full_name":"hedzr/bgo","owner":"hedzr","description":"make go building easier: an efficient and extensible tool for go apps","archived":false,"fork":false,"pushed_at":"2025-03-13T01:57:49.000Z","size":433,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T22:35:11.138Z","etag":null,"topics":["build-tool","cli","cmdr","cross-compile","go","golang"],"latest_commit_sha":null,"homepage":"https://hedzr.com/golang/ci/bgo-made-building-go-apps-easier/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hedzr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://paypal.me/hezr/5"}},"created_at":"2022-01-29T14:38:18.000Z","updated_at":"2025-01-23T02:17:44.000Z","dependencies_parsed_at":"2024-06-20T11:21:04.677Z","dependency_job_id":null,"html_url":"https://github.com/hedzr/bgo","commit_stats":{"total_commits":222,"total_committers":3,"mean_commits":74.0,"dds":"0.018018018018018056","last_synced_commit":"07764bbe46c55d79f7386927f6145732d29817b9"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":"hedzr/cmdr-go-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Fbgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Fbgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Fbgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedzr%2Fbgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hedzr","download_url":"https://codeload.github.com/hedzr/bgo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248509192,"owners_count":21115960,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build-tool","cli","cmdr","cross-compile","go","golang"],"created_at":"2024-11-14T23:14:30.249Z","updated_at":"2025-04-12T02:50:50.083Z","avatar_url":"https://github.com/hedzr.png","language":"Go","funding_links":["https://paypal.me/hezr/5"],"categories":[],"sub_categories":[],"readme":"# hedzr/bgo\n\n[![Go](https://github.com/hedzr/bgo/actions/workflows/go.yml/badge.svg)](https://github.com/hedzr/bgo/actions/workflows/go.yml)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/hedzr/bgo.svg?label=release)](https://github.com/hedzr/bgo/releases)\n[![go.dev](https://img.shields.io/badge/go-dev-green)](https://pkg.go.dev/github.com/hedzr/bgo)\n[![Docker Pulls](https://img.shields.io/docker/pulls/hedzr/bgo)](https://hub.docker.com/r/hedzr/bgo)\n![Docker Image Version (latest semver)](https://img.shields.io/docker/v/hedzr/bgo)\n![Docker Image Size (latest semver)](https://img.shields.io/docker/image-size/hedzr/bgo)\n\n`bgo` provides a super easy way to build your go apps.\nAll things you need to do is entering the golang project directory and entering `bgo` and pressing \u003ckbd\u003eEnter\u003c/kbd\u003e.\n\n\u003e powered by [cmdr](https://github.com/hedzr/cmdr).\n\n![tip-for-bgo](https://cdn.jsdelivr.net/gh/hzimg/blog-pics@master/uPic/image-20220202111546956.png)\n\n## Features\n\n`bgo` makes your golang building life easier, it's an efficient and extensible build tool.\n\n- `bgo` or `bgo build`: Run go building with or without a config file `.bgo.yml`\n- `bgo run -- ...`: Forward command-line to `go run` as is\n- `bgo test -- ...`: Forward command-line to `go test` as is\n- `bgo init`: Scan the directory to grab all main packages and initial `.bgo.yml`\n- `bgo list`: list managed projects in all of `.bgo.yaml`\n- `bgo sbom`: dump [#SBOM](#sbom) information itself or specified executables\n- More extensible commands\n  - pre-builtins (*bundled by [`80.aliases.yml`](https://github.com/hedzr/bgo/blob/master/ci/etc/bgo/conf.d/80.aliases.yml)*)\n    - `bgo chk|check-code-qualities`\n    - `bgo cov|coverage`\n\n    see also [#Extensible Commands](https://github.com/hedzr/bgo#extensible-commands)\n- While\n\n  - you have lots of small cli apps in many sub-directories\n  - one project wants go1.18beta1 and others stays in go1.17\n  - too much `-tags`, `-ldflags`, `-asmflags`, ...\n  - multiple targets, cross compiling\n  - etc.\n\n    have a try with `bgo`.\n\n## History\n\n- v0.5.25\n  - security patch: bump golang.org/x/crypto from 0.15.0 to 0.17.0, and more\n\n- v0.5.21/23\n  - removed sending to coverall since a unknown/untagged error when gh action triggering the release \n  - security patch: bump golang.org/x/net from 0.15.0 to 0.17.0, and more\n  - fixed a bug from errors.v3\n  - upgrade deps\n\n- v0.5.19\n  - upgrade deps\n  - fixed: `StripOrderPrefix`, ...\n\n- v0.5.18\n  - upgrade deps\n  - fixed: change `SaveAs`(`--output`) field from string slice to string\n\n- v0.5.16\n  - upgrade deps\n  - fixed a little\n\n- More in [CHANGELOG](https://github.com/hedzr/bgo/blob/master/CHANGELOG)\n\n## Getting Started\n\n### Install\n\nDownload the prebuilt binaries from Release page.\n\nOr Built from source code:\n\n```bash\ngo install github.com/hedzr/bgo@latest\nbgo --help         # -h\nbgo --version      # -V\nbgo --build-info   # -#\n```\n\nYou may clone and compile `bgo` from source code:\n\n```bash\ngit clone https://github.com/hedzr/bgo.git\ncd bgo\ngo run . -s\n```\n\n`go run . -s` will run bgo from source code and install itself to ~/go/bin/.\n\n![image-20220130101919648](https://cdn.jsdelivr.net/gh/hzimg/blog-pics@master/uPic/image-20220130101919648.png)\n\nYou could run bgo via docker way:\n\n```bash\ndocker pull hedzr/bgo\n# or\ndocker pull ghcr.io/hedzr/bgo:latest\n```\n\nAnd run it:\n\n```bash\ndocker run -it --rm -v $PWD:/app -v /tmp:/tmp -v /tmp/go-pkg:/go/pkg hedzr/bgo\n```\n\nFor macOS/Linux, there is a brew formula:\n\n```bash\nbrew install hedzr/brew/bgo\n```\n\n### Run directly\n\nTo work without `.bgo.yml`, simply go into a folder and run bgo, the cli apps under the folder will be found out and built.\n\n```bash\ncd my-projects\nbgo  # start `bgo` in auto mode, see Scopes chapter below\n```\n\n![image-20220128104835837](https://cdn.jsdelivr.net/gh/hzimg/blog-pics@master/uPic/image-20220128104835837.png)\n\nFilter the target systems by `-for OS/ARCH`, `-os OS` and `-arch ARCH`:\n\n```bash\nbgo --for linux/386 -for linux/amd64,darwin/arm64\nbgo -os linux -arch 386 -arch amd64 -arch arm64\n```\n\nBoth long and short options are available for `for`, `os` and `arch`.\nTheir values are stacked by specifying multiple times, so `-arch 386 -arch amd64 -arch arm64` is same with `--arch 386,amd64,arm64`.\n\n### Run with `.bgo.yml`\n\n#### Create `.bgo.yml` at first\n\n```bash\ncd my-projects\nbgo init  # create bgo.yml by scanning\nmv bgo.yml .bgo.yml # rename it\n```\n\n#### Tune `.bgo.yml`\n\nSee sample of `.bgo.yml`\n\n[.bgo.yml](https://github.com/hedzr/bgo/blob/master/.bgo.yaml)\n\n#### Run\n\n```bash\nbgo\n```\n\nbgo will load projects from `.bgo.yml` and build them\n\n### Scopes\n\n1. `bgo -s`: short mode - this will build first project with current GOOS/GOARCH.\n2. `bgo`|`bgo -a`: auto mode - build projects in `.bgo.yml`\n3. `bgo -f`: full mode - build by scanning current directory\n\n### Using shell auto-completion\n\nRun `bgo gen sh --zsh` to install auto-completion script to the proper location and enable the feature:\n\n![image-20220130092618399](https://cdn.jsdelivr.net/gh/hzimg/blog-pics@master/uPic/image-20220130092618399.png)\n\nFor macOS, you may install zsh completion script manually (not recommended, the better way is by HomeBrew):\n\n```bash\nbgo gen sh --zsh --output \"$(brew --prefix)/share/zsh/site-functions/_bgo\"\n```\n\nRun `bgo gen sh --bash -o=bgo.bash` to get bash completions script and put it to the right location. Generally it should be:\n\n```bash\nbgo generate shell --bash -o=bgo.bash\nmv bgo.bash /etc/bash-completion.d/bgo\n```\n\nNothing needs to do if installed via brew (since v0.3.3+).\n\n### Others Subcommands\n\n#### `run`\n\n`bgo run` can forward arguments to `go run`. For the command line\n\n```bash\nbgo run -- ./...\n```\n\nThe underlying real command will be run:\n\n```bash\ngo run ./...\n```\n\n#### `test`\n\n`bgo test` can forward arguments to `go test`. For the command line\n\n```bash\nbgo test -- ./...\n```\n\nThe underlying real command will be run:\n\n```bash\ngo test ./...\n```\n\n### `SBOM`\n\nChecking executable's [SBOM (`Software Bill Of Materials`)](ttps://www.argon.io/blog/guide-to-sbom/) without golang installed:\n\n```bash\nbgo sbom   # show sbom of bgo itself\n\n# Show these executables\nbgo sbom ~/go/bin/gopls ~/go/bin/golangci-lint\n```\n\n### Extensible Commands\n\nThe commands system of `bgo` can be extensible by editing `.bgo.yaml`.\n\n#### Config Files of `bgo`\n\n`bgo` loads all `bgo.yaml` as its configurations from these locations:\n\n1. _Main_ Config Files:\n   - `/etc/bgo/bgo.yml` and `conf.d/*.yml` in it\n   - `/usr/local/etc/bgo/bgo.yml` and `conf.d/*.yml` in it\n   Any of them will be loaded as default config set.\n2. _Secondary_ Config Files:\n   - `$HOME/.bgo/bgo.yml` and `conf.d/*.yml` in it\n   - `$HOME/.config/bgo/bgo.yml` and `conf.d/*.yml` in it\n   Any of them will be loaded as extensible config set.\n3. _Alternative_ Config File:\n   - `./.bgo.yaml`\n   This config file is used to current building project by `bgo`.\n   The scanning results of golang CLI apps from current directory will be written into this file.\n\n#### Customize the extensible commands in Main/Secondary Config Files\n\nThe extensible commands from config file is a feature of `hedzr/cmdr`. It generally looks like:\n\n\u003cdetails\u003e\n  \u003csummary\u003e Expand to source codes of `80.aliases.yml` \u003c/summary\u003e\n\n```yaml\n# ~/.config/bgo/conf.d/80.aliases.yml\napp:\n    aliases:\n        # group:                                  # group-name (optional). such as: \"别名\".\n        commands:\n            # - title: list\n            #   short-name: ls\n            #   # aliases: []\n            #   # name: \"\"\n            #   invoke-sh: ls -la -G                # for macOS, -G = --color; for linux: -G = --no-group\n            #   # invoke: \"another cmdr command\"\n            #   # invoke-proc: \"...\" # same with invoke-sh\n            #   desc: list the current directory\n\n            # - title: echo\n            #   invoke-sh: |\n            #     # pwd\n            #     echo \"{{$flg := index .Cmd.Flags 0}}{{$path :=$flg.GetDottedNamePath}} {{$fullpath := .Store.Wrap $path}} {{$fullpath}} | {{.Store.GetString $fullpath}}\"\n            #   desc: print the name\n            #   flags:\n            #     - title: name\n            #       default:              # default value\n            #       type: string          # bool, string, duration, int, uint, ...\n            #       group:\n            #       toggle-group:\n            #       desc: specify the name to be printed\n\n            - title: check-code-qualities\n              short-name: chk\n                # aliases: [check]\n                # name: \"\"\n              invoke-sh: |\n                  which golint || go install golang.org/x/lint/golint\n                  which gocyclo || go install github.com/fzipp/gocyclo\n                  echo\n                  echo\n                  echo \"Command hit: {{.Cmd.GetDottedNamePath}}\"\n                  echo \"fmt {{.ArgsString}} ...\"\n                  gofmt -l -s -w {{range .Args}}{{.}}{{end}}\n                  echo \"lint {{.ArgsString}} ...\"\n                  golint {{.ArgsString}}\n                  echo \"cyclo .\"\n                  gocyclo -top 13 .\n                # invoke: \"another cmdr command\"\n                # invoke-proc: \"...\" # same with invoke-sh\n              shell: /usr/bin/env bash # optional, default is /bin/bash\n              desc: pre-options before releasing. typically fmt,lint,cyclo,...\n\n            - title: coverage\n              short-name: cov\n              invoke-sh: |\n                  # pwd\n                  # echo \"{{$flg := index .Cmd.Flags 0}}{{$path := $flg.GetDottedNamePath}} {{$fullpath := .Store.Wrap $path}} {{$fullpath}} | {{.Store.GetString $fullpath}}\"\n                  # echo \"{{$flg = index .Cmd.Flags 1}}{{$path = $flg.GetDottedNamePath}} {{$fullpath2 := .Store.Wrap $path}} {{$fullpath2}} | {{.Store.GetString $fullpath2}}\"\n                  # echo \"{{$flg = index .Cmd.Flags 2}}{{$path = $flg.GetDottedNamePath}} {{$fullpath3 := .Store.Wrap $path}} {{$fullpath3}} | {{.Store.GetString $fullpath3}}\"\n                  go test -v -race \\\n                    -coverprofile={{.Store.GetString $fullpath2}} \\\n                    -covermode=atomic -timeout=20m \\\n                    {{if not .Args}}.{{else}}{{.ArgsString}}{{end}} \\\n                    | tee {{.Store.GetString $fullpath3}}\n                  go tool cover \\\n                    -html={{.Store.GetString $fullpath2}} \\\n                    -o={{.Store.GetString $fullpath}}\n              desc: run coverage, produce coverage.txt and cover.html\n              examples: bgo cov ./... or bgo cov\n              flags:\n                  - title: html\n                    default: cover.html # default value\n                    default-placeholder: FILE\n                    type: string # bool, string, duration, int, uint, ...\n                    group:\n                    toggle-group:\n                    desc: specify the html filename to be output\n                  - title: text\n                    default: coverage.txt # default value\n                    default-placeholder: FILE\n                    type: string # bool, string, duration, int, uint, ...\n                    group:\n                    toggle-group:\n                    desc: specify the coverprofile filename\n                  - title: log\n                    default: coverage.log # default value\n                    default-placeholder: FILE\n                    type: string # bool, string, duration, int, uint, ...\n                    group:\n                    toggle-group:\n                    desc: specify the name to be logged\n```\n\n\u003c/details\u003e\n\nThe config adds two top-level subcommands: `chk`(`check-code-qualities`) and `cov`(`coverage`)\n\nAnother sample is the bundled `91.more.aliases.yml`:\n\n\u003cdetails\u003e\n  \u003csummary\u003e Expand to source codes of `91.more.aliases.yml`\u003c/summary\u003e\n\n```yaml\napp:\n  aliases:\n    # group:                                  # group-name (optional). such as: \"别名\".\n    commands:\n      # - title: list\n      #   short-name: ls\n      #   # aliases: []\n      #   # name: \"\"\n      #   invoke-sh: ls -la -G                # for macOS, -G = --color; for linux: -G = --no-group\n      #   # invoke: \"another cmdr command\"\n      #   # invoke-proc: \"...\" # same with invoke-sh\n      #   desc: list the current directory\n\n      - title: yolo\n        short-name: y\n        invoke-sh: |\n          which yolo || { echo \"installing yolo...\" \u0026\u0026 go install -v github.com/azer/yolo; }\n          yolo -i *.go -c 'go build' -a localhost:8080 {{.ArgsString}}\n        desc: print the name\n\n      - title: echo\n        invoke-sh: |\n          # pwd\n          echo \"{{$flg := index .Cmd.Flags 0}}{{$path :=$flg.GetDottedNamePath}} {{$fullpath := .Store.Wrap $path}} {{$fullpath}} | {{.Store.GetString $fullpath}}\"\n        desc: print the name\n        flags:\n          - title: name\n            default: # default value\n            type: string # bool, string, duration, int, uint, ...\n            group:\n            toggle-group:\n            desc: specify the name to be printed\n```\n\n\u003c/details\u003e\n\n## Inspired By\n\n`bgo` building subcommand was inspired by many tools:\n\n- \u003chttps://github.com/mitchellh/gox\u003e\n- \u003chttps://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5\u003e\n- \u003chttps://github.com/davecheney/golang-crosscompile\u003e\n- \u003chttps://github.com/laher/goxc\u003e\n- Makefile\n\n## LICENSE\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedzr%2Fbgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhedzr%2Fbgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedzr%2Fbgo/lists"}