-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
81 lines (64 loc) · 2.67 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
VERSION := $(shell git describe --tags --abbrev=0)
REVISION := $(shell git rev-parse --short HEAD)
SRC_DIR := ./
BIN_NAME := tldr
BIN_DIR := bin
BINARY := $(BIN_DIR)/$(BIN_NAME)
ASSETS_DIR := assets
ASSETS := $(ASSETS_DIR)/* $(BINARY) README.md
ARTIFACT_DIR := .artifact
ARTIFACT_NAME := $(BIN_NAME).alfredworkflow
export LANGUAGE=en
CMD_PACKAGE_DIR := github.com/konoui/alfred-tldr/cmd
LDFLAGS := -X '$(CMD_PACKAGE_DIR).version=$(VERSION)' -X '$(CMD_PACKAGE_DIR).revision=$(REVISION)'
WORKFLOW_DIR := "$${HOME}/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.2569C1E1-8114-4B77-9506-52AA966313A9"
GOLANGCI_LINT_VERSION := v1.53.3
## Build binaries on your environment
build:
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BINARY) $(SRC_DIR)
## Lint
lint:
@(if ! type golangci-lint >/dev/null 2>&1; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_LINT_VERSION) ;fi)
$$(go env GOPATH)/bin/golangci-lint run ./...
## Build macos binaries
darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS) -s -w" -o $(BIN_DIR)/amd64 $(SRC_DIR)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "$(LDFLAGS) -s -w" -o $(BIN_DIR)/arm64 $(SRC_DIR)
lipo -create $(BIN_DIR)/amd64 $(BIN_DIR)/arm64 -output $(BINARY)
TEST_DIR := /tmp/tldrtest
setup-testdata:
if [ ! -e $(TEST_DIR)/tldr.zip ]; then mkdir -p $(TEST_DIR) && curl -s -o $(TEST_DIR)/tldr.zip https://tldr.sh/assets/tldr.zip ; fi
## Run tests for my project
test: setup-testdata
go test ./...
## Embed current version into workflow config
embed-version:
$(eval SEMVER := $(shell echo $(VERSION) | tr -cd '[0-9.]'))
@(plutil -replace version -string $(SEMVER) $(ASSETS_DIR)/info.plist)
## Install Binary and Assets to Workflow Directory
install: build embed-version
@(mkdir -p $(WORKFLOW_DIR))
@(cp $(ASSETS) $(WORKFLOW_DIR)/)
## Create workflow artifact
package: darwin embed-version
@(if [ ! -e $(ARTIFACT_DIR) ]; then mkdir $(ARTIFACT_DIR) ; fi)
@(cp $(ASSETS) $(ARTIFACT_DIR))
@(zip -j $(ARTIFACT_NAME) $(ARTIFACT_DIR)/*)
## GitHub Release and uploads artifacts
release: package
@(if ! type ghr >/dev/null 2>&1; then go install github.com/tcnksm/ghr ;fi)
@ghr -replace $(VERSION) $(ARTIFACT_NAME)
## Clean Binary
clean:
go clean -testcache
rm -f $(BIN_DIR)/*
rm -f $(ARTIFACT_DIR)/*
## Report coverage
cover:
go test -coverprofile=cover.out ./...
go tool cover -html=cover.out -o cover.html
## Show help
help:
@(if ! type make2help >/dev/null 2>&1; then go install github.com/Songmu/make2help/cmd/make2help ;fi)
@make2help $(MAKEFILE_LIST)
.PHONY: build test lint fmt darwin clean help