-
Notifications
You must be signed in to change notification settings - Fork 556
/
Makefile
144 lines (115 loc) · 3.95 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
GO ?= $(shell command -v go 2> /dev/null)
BASH ?= $(shell command -v bash 2> /dev/null)
GOLANG_VERSION := $(shell head -n 4 go.mod | tail -n 1 | cut -d " " -f 2)
# Development
SHIORI_DIR ?= dev-data
SOURCE_FILES ?=./internal/...
# Build
CGO_ENABLED ?= 0
BUILD_TIME := $(shell date -u +%Y%m%d.%H%M%S)
BUILD_HASH := $(shell git describe --tags)
BUILD_TAGS ?= osusergo,netgo,fts5
LDFLAGS += -s -w -X main.version=$(BUILD_HASH) -X main.date=$(BUILD_TIME)
# Build (container)
CONTAINER_RUNTIME := docker
CONTAINERFILE_NAME := Dockerfile
CONTAINER_ALPINE_VERSION := 3.19
BUILDX_PLATFORMS := linux/amd64,linux/arm64,linux/arm/v7
# This is used for local development only, forcing linux to create linux only images but with the arch
# of the running machine. Far from perfect but works.
LOCAL_BUILD_PLATFORM = linux/$(shell go env GOARCH)
# Testing
GO_TEST_FLAGS ?= -v -race -count=1 -tags $(BUILD_TAGS) -covermode=atomic -coverprofile=coverage.out
GOTESTFMT_FLAGS ?=
# Development
GIN_MODE ?= debug
SHIORI_DEVELOPMENT ?= true
# Swagger
SWAG_VERSION := $(shell grep "swaggo/swag" go.mod | cut -d " " -f 2)
SWAGGER_DOCS_PATH ?= ./docs/swagger
# Frontend
CLEANCSS_OPTS ?= --with-rebase
# Common exports
export GOLANG_VERSION
export CONTAINER_RUNTIME
export CONTAINERFILE_NAME
export CONTAINER_ALPINE_VERSION
export BUILDX_PLATFORMS
export SOURCE_FILES
# Help documentatin à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help:
@cat Makefile | grep -v '\.PHONY' | grep -v '\help:' | grep -B1 -E '^[a-zA-Z0-9_.-]+:.*' | sed -e "s/:.*//" | sed -e "s/^## //" | grep -v '\-\-' | sed '1!G;h;$$!d' | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort
## Cleans up build artifacts
.PHONY: clean
clean:
rm -rf dist
## Runs the legacy http API for local development
.PHONY: serve
serve:
SHIORI_DEVELOPMENT=$(SHIORI_DEVELOPMENT) SHIORI_DIR=$(SHIORI_DIR) go run main.go serve
## Runs server for local development
.PHONY: run-server
run-server:
GIN_MODE=$(GIN_MODE) SHIORI_DEVELOPMENT=$(SHIORI_DEVELOPMENT) SHIORI_DIR=$(SHIORI_DIR) SHIORI_HTTP_SECRET_KEY=shiori go run main.go server --log-level debug
## Generate swagger docs
.PHONY: swagger
swagger:
SWAGGER_DOCS_PATH=$(SWAGGER_DOCS_PATH) $(BASH) ./scripts/swagger.sh
.PHONY: swag-check
swag-check:
REQUIRED_SWAG_VERSION=$(SWAG_VERSION) SWAGGER_DOCS_PATH=$(SWAGGER_DOCS_PATH) $(BASH) ./scripts/swagger_check.sh
.PHONY: swag-fmt
swag-fmt:
swag fmt --dir internal/http
go fmt ./internal/http/...
## Run linters
.PHONY: lint
lint: golangci-lint swag-check
## Run golangci-lint
.PHONY: golangci-lint
golangci-lint:
golangci-lint run
## Run unit tests
.PHONY: unittest
unittest:
GIN_MODE=$(GIN_MODE) GO_TEST_FLAGS="$(GO_TEST_FLAGS)" GOTESTFMT_FLAGS="$(GOTESTFMT_FLAGS)" $(BASH) -xe ./scripts/test.sh
## Run end to end tests
.PHONY: e2e
e2e:
$(BASH) -xe ./scripts/e2e.sh
## Build styles
.PHONY: styles
styles:
CLEANCSS_OPTS=$(CLEANCSS_OPTS) $(BASH) ./scripts/styles.sh
## Build styles
.PHONY: styles-check
styles-check:
CLEANCSS_OPTS=$(CLEANCSS_OPTS) $(BASH) ./scripts/styles_check.sh
## Build binary
.PHONY: build
build: clean
GIN_MODE=$(GIN_MODE) goreleaser build --clean --snapshot
## Build binary for current targer
build-local: clean
GIN_MODE=$(GIN_MODE) goreleaser build --clean --snapshot --single-target
## Build docker image using Buildx.
# used for multi-arch builds suing mainly the CI, that's why the task does not
# build the binaries using a dependency task.
.PHONY: buildx
buildx:
$(info: Make: Buildx)
@bash scripts/buildx.sh
## Build docker image for local development
buildx-local: build-local
$(info: Make: Build image locally)
CONTAINER_BUILDX_OPTIONS="-t shiori:localdev --output type=docker" BUILDX_PLATFORMS=$(LOCAL_BUILD_PLATFORM) scripts/buildx.sh
## Creates a coverage report
.PHONY: coverage
coverage:
$(GO) test $(GO_TEST_FLAGS) -coverprofile=coverage.txt $(SOURCE_FILES)
$(GO) tool cover -html=coverage.txt
## Run generate accross the project
.PHONY: generated
generate:
$(GO) generate ./...