项目作者: the-gophers

项目描述 :
Template illustrating the use of matrix builds and Go's ability to easily target multiple arch / platforms
高级语言: Go
项目地址: git://github.com/the-gophers/matrix-builds.git
创建时间: 2020-11-08T02:28:00Z
项目社区:https://github.com/the-gophers/matrix-builds

开源协议:MIT License

下载


Building, Testing and Releasing for Multiple Platforms

Template illustrating the use of matrix builds and Go’s ability to easily target multiple arch / platforms.
In this example you will learn about resources for verifying your software across multiple platforms and
architectures concurrently, how to properly inject version information into Go binaries via a release
workflow, and how to create an automated release with artifacts spanning multiple platforms and architectures.

Getting Started

This is a GitHub template repo, so when you click “Use this template”, it will create a new copy of this
template in your org or personal repo of choice. Once you have created a repo from this template, you
should be able to clone and navigate to the root of the repository.

First Build

From the root of your repo, you should be able to run the following to build and test the Go action.
```shell script
$ make
$ ./bin/gophers version

  1. ### What's in Here?
  2. A command line application which we will add some functionality.
  3. ```shell script
  4. .
  5. ├── cmd
  6. │ ├── add.go
  7. │ ├── root.go
  8. │ └── version.go
  9. ├── .github
  10. │ └── workflows
  11. │ ├── ci.yml
  12. │ └── release.yml
  13. ├── .gitignore
  14. ├── go.mod
  15. ├── go.sum
  16. ├── LICENSE
  17. ├── main.go
  18. ├── Makefile
  19. ├── README.md
  20. ├── scripts
  21. │ └── go_install.sh
  22. └── xcobra
  23. ├── context.go
  24. ├── exit_handler.go
  25. └── noop_handler.go

cmd

Contains the commands for the CLI application.

.github/workflows/ci.yml

Contains a continuous integration workflow which targets multiple platforms and multiple versions of Go
to create a matrix of machines which will be used to verify the application.

We’ll also discuss how to optimize our builds through caching of module dependencies and other little
tricks.

.github/workflows/release.yml

Contains a release workflow which will show how to build release Go applications with a stamped version
for a variety of platforms and architectures. We’ll also show how to reference a step in a workflow
to add artifacts to a release.

main.go

It’s the entrypoint for the CLI application.

Makefile

Contains a lot of the build foo. Generally, you shouldn’t have to change this, but it wouldn’t hurt
to familiarize yourself with the contents.

scripts

Contains a helper to install Go build tools in a tmp dir with an ephemeral Go module. This is nice
for when you want to install a build tool, but you don’t want to dirty up your go.mod file.

xcobra

Contains some extra helpers Cobra helpers that make it easier to write responsive CLI applications and
easier to test too.

Lab Video

TODO: record and post the first lab walking through this example

Contributions

Always welcome! Please open a PR or an issue, and remember to follow the Gopher Code of Conduct.