From 696021a4774380f1ce43d3abfeb02ff1bbed023c Mon Sep 17 00:00:00 2001 From: till Date: Mon, 26 Dec 2022 15:38:16 +0100 Subject: [PATCH] Chore: switch to goreleaser for building --- .github/workflows/go.yml | 5 ++++- .github/workflows/main.yml | 5 +++++ .gitignore | 2 ++ .goreleaser.yaml | 26 ++++++++++++++++++++++++++ Makefile | 18 +++++------------- cmd/larry/main.go | 10 +++++++--- 6 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 4b0739c..be56b5f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -30,7 +30,10 @@ jobs: fi - name: Build - run: go build -v -o larry-build ./cmd/larry/. + uses: goreleaser/goreleaser-action@v4 + with: + version: latest + args: build --single-target --snapshot --rm-dist - name: Run golangci-lint uses: golangci/golangci-lint-action@v3.2.0 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 93da57a..bcf685a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,6 +14,11 @@ jobs: - name: Install dependencies run: | go mod download + - name: Lint build config + uses: goreleaser/goreleaser-action@v4 + with: + version: latest + args: check - name: Run Unit tests run: | go test -race -covermode atomic -coverprofile=covprofile ./... diff --git a/.gitignore b/.gitignore index cb686f3..d96d9ef 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ coverage.out .env .envrc larry-build + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..aa10ddf --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,26 @@ +--- +before: + hooks: + - go mod tidy +builds: + - id: larry + main: ./cmd/larry/main.go + env: + - CGO_ENABLED=0 + goos: + - darwin + - freebsd + - linux + - windows + goarch: + - "amd64" +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/Makefile b/Makefile index 9d02e66..f89a2ca 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -## build: build the application and place the built app in the bin folder +## build: build the application (for current GOOS/GOARCH) and place the built app in the dist folder build: - go build -o bin/larry ./cmd/larry/. + goreleaser build --single-target --snapshot --rm-dist ## start: start container start: @@ -14,17 +14,9 @@ run-dev: test: go test -v ./... --cover -## compile: compiles the application for multiple environments and place the output executables under the bin folder +## compile: compiles the application for multiple environments and place the output under the dist folder compile: - # 64-Bit - # FreeBDS - GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w" -o ./bin/larry-freebsd-64 ./cmd/larry/. - # MacOS - GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o ./bin/larry-macos-64 ./cmd/larry/. - # Linux - GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ./bin/larry-linux-64 ./cmd/larry/. - # Windows - GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o ./bin/larry-windows-64 ./cmd/larry/. + goreleaser release --snapshot --rm-dist lint: docker run --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.46.2 golangci-lint run @@ -32,4 +24,4 @@ lint: ## help: prints this help message help: @echo "Usage: \n" - @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' \ No newline at end of file + @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' diff --git a/cmd/larry/main.go b/cmd/larry/main.go index 613fd55..de529b5 100644 --- a/cmd/larry/main.go +++ b/cmd/larry/main.go @@ -43,15 +43,19 @@ var ( mastodonAccessToken = envString("MASTODON_ACCESS_TOKEN", "") mastodonAccount = envString("MASTODON_ACCOUNT", "") mastodonPassword = envString("MASTODON_PASSWORD", "") + + // injected via build/goreleaser + version = "" ) func main() { cfg := config.Config{} app := &cli.App{ - Name: "Larry", - Usage: "Bot that publishes information from providers to different publishers", - Flags: larry.GetFlags(&cfg), + Name: "Larry", + Version: version, + Usage: "Bot that publishes information from providers to different publishers", + Flags: larry.GetFlags(&cfg), Authors: []*cli.Author{ {Name: "@ezeoleaf", Email: "ezeoleaf@gmail.com"}, {Name: "@beesaferoot", Email: "hikenike6@gmail.com"},