diff --git a/.github/workflows/generic-tests.yml b/.github/workflows/generic-tests.yml new file mode 100644 index 0000000..ecdfac0 --- /dev/null +++ b/.github/workflows/generic-tests.yml @@ -0,0 +1,34 @@ +name: Tests + +on: push + +jobs: + unit-test: + runs-on: ubuntu-18.04 + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: recursive + - name: Run unit tests + run: make unit + + static: + runs-on: ubuntu-18.04 + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: recursive + - name: Run static linters + run: make static diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7725314 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +name: Release + +on: push + +jobs: + release: + runs-on: ubuntu-18.04 + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: recursive + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release + env: + GITHUB_TOKEN: ${{ secrets.COMMITER_TOKEN }} diff --git a/.gitignore b/.gitignore index 7791028..61c432c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /coverage.out /bin/ +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..09a683a --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,57 @@ +before: + hooks: + - go mod tidy +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + ldflags: + - -s -w + - -X github.com/little-angry-clouds/particle/cmd.Version={{.Version}} + - -X github.com/little-angry-clouds/particle/cmd.Commit={{.Commit}} + - -X github.com/little-angry-clouds/particle/cmd.Date={{.Date}} + goarch: + - amd64 + - arm + - arm64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - '^ci:' +release: + github: + owner: little-angry-clouds + name: particle + draft: true +brews: + - name: particle + tap: + owner: little-angry-clouds + name: homebrew-my-brews + url_template: "https://github.com/little-angry-clouds/homebrew-my-brews{{ .Tag }}/{{ .ArtifactName }}" + commit_author: + name: goreleaserbot + email: goreleaser@carlosbecker.com + folder: Formula + homepage: https://github.com/little-angry-clouds/particle/ + description: Particle is a project designed to aid in the development and testing of Helm charts and other kubernetes manifests. + license: "GPL3" + dependencies: + - name: go + - name: helm + type: optional + - name: kind + type: optional + install: | + ENV.prepend "CGO_ENABLED", "0" + system "go", "build", "-a", "-o", "particle.bin", "main.go" + bin.install "particle.bin" => "#{bin}/particle" diff --git a/Makefile b/Makefile index 43371bb..389660f 100644 --- a/Makefile +++ b/Makefile @@ -6,24 +6,27 @@ $(BIN)/golangci-lint: | $(BIN) curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.24.0 $(BIN)/gopherbadger: | $(BIN) GOBIN=$(BIN) go get github.com/jpoles1/gopherbadger +$(BIN)/goreleaser: | $(BIN) + curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh # Binaries to install GOLANGCI-LINT = $(BIN)/golangci-lint GOPHERBADGER = $(BIN)/gopherbadger +GORELEASER = $(BIN)/goreleaser ############################################################################### ############################################################################### ############################################################################### -all: clean static test build +all: clean static unit build # Build binaries -build: - go build -a -o bin/particle main.go; +build: | $(GORELEASER) + $(GORELEASER) build --rm-dist --skip-validate clean: - -rm -r bin/ - -rm -r releases/ + rm -r bin/ + rm -r dist/ static: | $(GOLANGCI-LINT) $(GOPHERBADGER) $(GOLANGCI-LINT) run ./... --fix @@ -32,12 +35,5 @@ static: | $(GOLANGCI-LINT) $(GOPHERBADGER) unit: go test ./... -cover -PLATFORMS := linux-amd64 linux-386 darwin-amd64 windows-amd64 windows-386 -temp = $(subst -, ,$@) -os = $(word 1, $(temp)) -arch = $(word 2, $(temp)) -releases: $(PLATFORMS) -$(PLATFORMS): - @mkdir -p releases; \ - CGO_ENABLED=0 GOOS=$(os) GOARCH=$(arch) go build -a -o bin/particle-$(os)-$(arch) main.go; \ - tar -C bin -cvzf releases/particle-$(os)-$(arch).tar.gz particle-$(os)-$(arch) particle-$(os)-$(arch); \ +releases: + $(GORELEASER) release diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..a4f7c9b --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + goVersion "go.hein.dev/go-version" +) + +var ( + Version = "dev" + Commit = "none" + Date = "unknown" + shortened = false + output = "json" + versionCmd = &cobra.Command{ + Use: "version", + Short: "Outputs the current build information", + Run: func(_ *cobra.Command, _ []string) { + resp := goVersion.FuncWithOutput(shortened, Version, Commit, Date, output) + fmt.Print(resp) + }, + } +) + +func init() { + versionCmd.Flags().BoolVar(&shortened, "short", false, "Print just the version number.") + versionCmd.Flags().StringVar(&output, "output", "yaml", "Output format. One of 'yaml' or 'json'.") + rootCmd.AddCommand(versionCmd) +}