Skip to content

Commit 19f0190

Browse files
committed
Updated Makefile to utilize goreleaser
1 parent 3972fd4 commit 19f0190

File tree

5 files changed

+57
-81
lines changed

5 files changed

+57
-81
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.so
66
*.dylib
77
bin/
8+
dist/
89
backplane-tools
910
# Test binary, built with `go test -c`
1011
*.test

Makefile

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,58 @@
1-
BUILD_DIR:=./bin
1+
BUILDFLAGS ?=
2+
unexport GOFLAGS
23

3-
build: clean
4-
mkdir -p ${BUILD_DIR}
5-
go build -o "${BUILD_DIR}/backplane-tools" main.go
4+
BASE_DIR=$(shell pwd)
5+
BIN_DIR=${BASE_DIR}/bin
66

7-
clean:
8-
rm -rf "${BUILD_DIR}"
7+
.DEFAULT_GOAL := all
8+
.PHONY: all
9+
all: vet fmt mod build test lint
910

11+
.PHONY: fmt
12+
fmt:
13+
@echo "gofmt"
14+
@gofmt -w -s .
15+
16+
OS := $(shell go env GOOS | sed 's/[a-z]/\U&/')
17+
ARCH := $(shell go env GOARCH)
18+
19+
GORELEASER_VERSION="v1.15.0"
20+
GOLANGCI_LINT_VERSION="v1.53.3"
21+
22+
.PHONY: download-goreleaser
23+
download-goreleaser:
24+
GOBIN=${BIN_DIR} go install github.com/goreleaser/goreleaser@${GORELEASER_VERSION}
25+
26+
.PHONY: download-golangci-lint
27+
download-golangci-lint:
28+
GOBIN=${BIN_DIR} go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
29+
30+
SINGLE_TARGET ?= false
31+
32+
# Need to use --snapshot here because the goReleaser
33+
# requires more git info that is provided in Prow's clone.
34+
# Snapshot allows the build without validation of the
35+
# repository itself
36+
.PHONY: build
37+
build: download-goreleaser
38+
${BIN_DIR}/goreleaser build --clean --snapshot --id linux_arm64,linux_amd64,darwin_arm64,darwin_amd64 --single-target=${SINGLE_TARGET}
39+
40+
.PHONY: release
41+
release:
42+
${BIN_DIR}/goreleaser release --clean
43+
44+
.PHONY: vet
45+
vet:
46+
go vet ${BUILDFLAGS} ./...
47+
48+
.PHONY: mod
49+
mod:
50+
go mod tidy
51+
52+
.PHONY: test
1053
test:
11-
echo "TODO"
54+
go test ${BUILDFLAGS} ./... -covermode=atomic -coverpkg=./...
55+
56+
.PHONY: lint
57+
lint: download-golangci-lint
58+
${BIN_DIR}/golangci-lint run

pkg/tool/aws-cli/aws-cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (t *Tool) Install(rootDir, latestDir string) error {
6060

6161
} else {
6262
// Handle unsupported operating systems
63-
return fmt.Errorf("Unsupported operating system:", runtime.GOOS)
63+
return fmt.Errorf("Unsupported operating system: %s", runtime.GOOS)
6464
}
6565

6666
err = os.RemoveAll(versionedDir)

pkg/tool/osdctl/osdctl.go

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package osdctl
22

33
import (
4-
"archive/tar"
5-
"compress/gzip"
64
"fmt"
7-
"io"
85
"os"
96
"path/filepath"
107
"runtime"
@@ -151,75 +148,6 @@ func (t *Tool) Remove(rootDir, latestDir string) error {
151148
return nil
152149
}
153150

154-
func unArchive(source string, destination string) error {
155-
src, err := os.Open(source)
156-
if err != nil {
157-
return fmt.Errorf("failed to open tarball '%s': %v", source, err)
158-
}
159-
defer func() {
160-
err = src.Close()
161-
if err != nil {
162-
fmt.Printf("WARNING: failed to close '%s': %v\n", src.Name(), err)
163-
}
164-
}()
165-
uncompressed, err := gzip.NewReader(src)
166-
if err != nil {
167-
return fmt.Errorf("failed to read the gzip file '%s': %v", source, err)
168-
}
169-
defer func() {
170-
err = uncompressed.Close()
171-
if err != nil {
172-
fmt.Printf("WARNING: failed to close gzip file '%s': %v", source, err)
173-
}
174-
}()
175-
arc := tar.NewReader(uncompressed)
176-
var f *tar.Header
177-
for {
178-
f, err = arc.Next()
179-
if err == io.EOF {
180-
break
181-
}
182-
if err != nil {
183-
return fmt.Errorf("failed to read from archive '%s': %v", source, err)
184-
}
185-
if f.FileInfo().IsDir() {
186-
err = os.MkdirAll(filepath.Join(destination, f.Name), 0755)
187-
if err != nil {
188-
return fmt.Errorf("failed to create a directory : %v", err)
189-
}
190-
} else {
191-
err = extractFile(destination, f, arc)
192-
if err != nil {
193-
return fmt.Errorf("failed to extract files: %v", err)
194-
}
195-
}
196-
}
197-
return nil
198-
}
199-
200151
func (t *Tool) Configure() error {
201152
return nil
202153
}
203-
204-
func extractFile(destination string, f *tar.Header, arc io.Reader) error {
205-
dst, err := os.Create(filepath.Join(destination, f.Name))
206-
if err != nil {
207-
return fmt.Errorf("failed to create file: %v", err)
208-
}
209-
defer func() {
210-
err = dst.Close()
211-
if err != nil {
212-
fmt.Printf("warning: failed to close '%s': %v\n", dst.Name(), err)
213-
}
214-
}()
215-
216-
err = dst.Chmod(os.FileMode(0755))
217-
if err != nil {
218-
return fmt.Errorf("failed to set permission on '%s': %v", dst.Name(), err)
219-
}
220-
_, err = dst.ReadFrom(arc)
221-
if err != nil {
222-
return fmt.Errorf("failed to read from archive %v", err)
223-
}
224-
return nil
225-
}

pkg/utils/unarchive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func Unzip(source string, destination string) error {
6767
defer func(reader *zip.ReadCloser) {
6868
err := reader.Close()
6969
if err != nil {
70-
70+
fmt.Fprintf(os.Stderr, "possible memory leak: failed to close %s", source)
7171
}
7272
}(reader)
7373

0 commit comments

Comments
 (0)