From 567dae83cf49204f83a2bb74d454cc5bd80e6c51 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 15 Jul 2021 22:26:40 +0200 Subject: [PATCH 1/8] Parametrize the abra path --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d2e0bca..f0f217c 100644 --- a/Makefile +++ b/Makefile @@ -2,17 +2,18 @@ COMMIT := $(shell git rev-list -1 HEAD) VERSION := $(shell cat ./version) GOPATH := $(shell go env GOPATH) LDFLAGS := "-X 'main.Commit=$(COMMIT)' -X 'main.Version=$(VERSION)'" +ABRA := ./cmd/abra all: run install build clean run: - go run -ldflags=$(LDFLAGS) ./cmd/abra + go run -ldflags=$(LDFLAGS) $(ABRA) install: - go install -ldflags=$(LDFLAGS) ./cmd/abra + go install -ldflags=$(LDFLAGS) $(ABRA) build: - go build -ldflags=$(LDFLAGS) ./cmd/abra + go build -ldflags=$(LDFLAGS) $(ABRA) clean: rm '$(GOPATH)/bin/abra' From 0a6ffd48cb4513955552e415fbb69b28ecbc9075 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 15 Jul 2021 22:27:24 +0200 Subject: [PATCH 2/8] Sort vars --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f0f217c..ef5280b 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ +ABRA := ./cmd/abra COMMIT := $(shell git rev-list -1 HEAD) -VERSION := $(shell cat ./version) GOPATH := $(shell go env GOPATH) LDFLAGS := "-X 'main.Commit=$(COMMIT)' -X 'main.Version=$(VERSION)'" -ABRA := ./cmd/abra +VERSION := $(shell cat ./version) all: run install build clean From 3b1dfb756236a2ed9bce0d1d2d1b8db2c8056fda Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 15 Jul 2021 22:29:31 +0200 Subject: [PATCH 3/8] Wire up notifications for failures --- .drone.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.drone.yml b/.drone.yml index 71bf2bb..930334b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,3 +6,20 @@ steps: image: golang:1.16 commands: - make build + + - name: notify on failure + image: plugins/matrix + settings: + homeserver: https://matrix.autonomic.zone + roomid: "IFazIpLtxiScqbHqoa:autonomic.zone" + userid: "@autono-bot:autonomic.zone" + accesstoken: + from_secret: autono_bot_access_token + depends_on: + - make build + when: + status: + - failure +trigger: + branch: + - main From 980f2f7684220577a588490fd6dc4dbeaf3d4136 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 15 Jul 2021 23:00:33 +0200 Subject: [PATCH 4/8] Add format and check targets + integrate into CI --- .drone.yml | 6 ++++++ Makefile | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 930334b..6a1229f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -2,6 +2,11 @@ kind: pipeline name: coopcloud.tech/abra steps: + - name: make check + image: golang:1.16 + commands: + - make check + - name: make build image: golang:1.16 commands: @@ -16,6 +21,7 @@ steps: accesstoken: from_secret: autono_bot_access_token depends_on: + - make check - make build when: status: diff --git a/Makefile b/Makefile index ef5280b..7cd367d 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ GOPATH := $(shell go env GOPATH) LDFLAGS := "-X 'main.Commit=$(COMMIT)' -X 'main.Version=$(VERSION)'" VERSION := $(shell cat ./version) -all: run install build clean +all: run install build clean format check run: go run -ldflags=$(LDFLAGS) $(ABRA) @@ -17,3 +17,9 @@ build: clean: rm '$(GOPATH)/bin/abra' + +format: + gofmt -s -w . + +check: + test -z $$(gofmt -l .) || (echo "gofmt: formatting issue - run 'make format' to resolve" && exit 1) From a9d9d9de2fb1272a83d9f5e6b4c989d0739b7357 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 15 Jul 2021 23:01:31 +0200 Subject: [PATCH 5/8] Silence command echoing to focus output on errors --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 7cd367d..0b67f76 100644 --- a/Makefile +++ b/Makefile @@ -7,19 +7,19 @@ VERSION := $(shell cat ./version) all: run install build clean format check run: - go run -ldflags=$(LDFLAGS) $(ABRA) + @go run -ldflags=$(LDFLAGS) $(ABRA) install: - go install -ldflags=$(LDFLAGS) $(ABRA) + @go install -ldflags=$(LDFLAGS) $(ABRA) build: - go build -ldflags=$(LDFLAGS) $(ABRA) + @go build -ldflags=$(LDFLAGS) $(ABRA) clean: - rm '$(GOPATH)/bin/abra' + @rm '$(GOPATH)/bin/abra' format: - gofmt -s -w . + @gofmt -s -w . check: - test -z $$(gofmt -l .) || (echo "gofmt: formatting issue - run 'make format' to resolve" && exit 1) + @test -z $$(gofmt -l .) || (echo "gofmt: formatting issue - run 'make format' to resolve" && exit 1) From 4884c14ab3493679e25776a571b2e290c515081a Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 15 Jul 2021 23:26:47 +0200 Subject: [PATCH 6/8] Can't sort this as VERSION is not defined then --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0b67f76..f11f6bc 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ ABRA := ./cmd/abra COMMIT := $(shell git rev-list -1 HEAD) GOPATH := $(shell go env GOPATH) -LDFLAGS := "-X 'main.Commit=$(COMMIT)' -X 'main.Version=$(VERSION)'" VERSION := $(shell cat ./version) +LDFLAGS := "-X 'main.Commit=$(COMMIT)' -X 'main.Version=$(VERSION)'" all: run install build clean format check From 9b8f16345c4f2a68f92c4b7c8bde80e2ec17f38c Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 15 Jul 2021 23:35:43 +0200 Subject: [PATCH 7/8] Add a Go report card badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index af28a59..20cc3a3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # go-abra [![Build Status](https://drone.autonomic.zone/api/badges/coop-cloud/go-abra/status.svg?ref=refs/heads/main)](https://drone.autonomic.zone/coop-cloud/go-abra) +[![Go Report Card](https://goreportcard.com/badge/git.autonomic.zone/coop-cloud/go-abra)](https://goreportcard.com/report/git.autonomic.zone/coop-cloud/go-abra) WIP port of [abra](https://git.autonomic.zone/coop-cloud/abra) to Golang. From c65ae974dd92959b9a26e8e5dafc2ac4fc888dac Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 15 Jul 2021 23:49:58 +0200 Subject: [PATCH 8/8] Add experimental staticcheck into linting CI See https://staticcheck.io for more. This is set to be ignored on failure so that it doesn't disrupt current work flows but maybe it is nice to add. Just drop the `ignore: ...` line and it will fail builds. --- .drone.yml | 10 ++++++++++ Makefile | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 6a1229f..23159bc 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,6 +7,16 @@ steps: commands: - make check + - name: make static + image: golang:1.16 + ignore: true # until we decide we all want this check + environment: + STATIC_CHECK_URL: honnef.co/go/tools/cmd/staticcheck + STATIC_CHECK_VERSION: v0.2.0 + commands: + - go install $STATIC_CHECK_URL@$STATIC_CHECK_VERSION + - make static + - name: make build image: golang:1.16 commands: diff --git a/Makefile b/Makefile index f11f6bc..0f85de6 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ GOPATH := $(shell go env GOPATH) VERSION := $(shell cat ./version) LDFLAGS := "-X 'main.Commit=$(COMMIT)' -X 'main.Version=$(VERSION)'" -all: run install build clean format check +all: run install build clean format check static run: @go run -ldflags=$(LDFLAGS) $(ABRA) @@ -23,3 +23,6 @@ format: check: @test -z $$(gofmt -l .) || (echo "gofmt: formatting issue - run 'make format' to resolve" && exit 1) + +static: + @staticcheck $(ABRA)