Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
99 lines (88 loc) 路 3.44 KB
/
Copy pathMakefile
File metadata and controls
99 lines (88 loc) 路 3.44 KB
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
# Makefile for the Guildmaster Go project
# Variables
BINARY_NAME=guildmaster
SRC=$(wildcard *.go)
GO_IMAGE=golang:1.26-alpine
GO_BIN=/usr/local/go/bin/go
GO_MIN_PREFIX=go1.26
# Default target
all: build
# Build the binary
build:
@go_version=$$(go env GOVERSION 2>/dev/null || go version 2>/dev/null | awk '{print $$3}'); \
case "$$go_version" in \
$(GO_MIN_PREFIX)* ) \
go build -o $(BINARY_NAME) $(SRC) ;; \
* ) \
echo "Local Go $$go_version is too old for this repo (needs Go 1.26+). Building in Docker..."; \
docker run --rm -v "$$PWD":/src -w /src --entrypoint /bin/sh $(GO_IMAGE) -lc 'apk add --no-cache git >/dev/null && $(GO_BIN) build -o $(BINARY_NAME) $(SRC)' ; \
;; \
esac
# Run the application
run:
@go_version=$$(go env GOVERSION 2>/dev/null || go version 2>/dev/null | awk '{print $$3}'); \
case "$$go_version" in \
$(GO_MIN_PREFIX)* ) \
go run . ;; \
* ) \
echo "Local Go $$go_version is too old for this repo (needs Go 1.26+). Running in Docker..."; \
docker run --rm -it -v "$$PWD":/src -w /src --entrypoint /bin/sh $(GO_IMAGE) -lc 'apk add --no-cache git >/dev/null && $(GO_BIN) run .' ; \
;; \
esac
tui:
@go_version=$$(go env GOVERSION 2>/dev/null || go version 2>/dev/null | awk '{print $$3}'); \
case "$$go_version" in \
$(GO_MIN_PREFIX)* ) \
go run . -tui ;; \
* ) \
echo "Local Go $$go_version is too old for this repo (needs Go 1.26+). TUI run requires a newer local Go toolchain."; \
exit 1 ;; \
esac
# Run the http server
server:
@go_version=$$(go env GOVERSION 2>/dev/null || go version 2>/dev/null | awk '{print $$3}'); \
case "$$go_version" in \
$(GO_MIN_PREFIX)* ) \
go run ./cmd/server ;; \
* ) \
echo "Local Go $$go_version is too old for this repo (needs Go 1.26+). Running server in Docker..."; \
docker run --rm -it -p 8080:8080 -v "$$PWD":/src -w /src --entrypoint /bin/sh $(GO_IMAGE) -lc 'apk add --no-cache git >/dev/null && $(GO_BIN) run ./cmd/server' ; \
;; \
esac
# Import games from Google Sheets into SQLite
import:
@go_version=$$(go env GOVERSION 2>/dev/null || go version 2>/dev/null | awk '{print $$3}'); \
case "$$go_version" in \
$(GO_MIN_PREFIX)* ) \
go run ./cmd/import ;; \
* ) \
echo "Local Go $$go_version is too old for this repo (needs Go 1.26+). Running import in Docker..."; \
docker run --rm -it -v "$$PWD":/src -w /src --entrypoint /bin/sh $(GO_IMAGE) -lc 'apk add --no-cache git >/dev/null && $(GO_BIN) run ./cmd/import' ; \
;; \
esac
# Format the code
fmt:
@go_version=$$(go env GOVERSION 2>/dev/null || go version 2>/dev/null | awk '{print $$3}'); \
case "$$go_version" in \
$(GO_MIN_PREFIX)* ) \
go fmt ./... ;; \
* ) \
echo "Local Go $$go_version is too old for this repo (needs Go 1.26+). Formatting in Docker..."; \
docker run --rm -v "$$PWD":/src -w /src --entrypoint /bin/sh $(GO_IMAGE) -lc 'apk add --no-cache git >/dev/null && $(GO_BIN) fmt ./...' ; \
;; \
esac
# Run tests
test:
@go_version=$$(go env GOVERSION 2>/dev/null || go version 2>/dev/null | awk '{print $$3}'); \
case "$$go_version" in \
$(GO_MIN_PREFIX)* ) \
go test ./... ;; \
* ) \
echo "Local Go $$go_version is too old for this repo (needs Go 1.26+). Running tests in Docker..."; \
docker run --rm -v "$$PWD":/src -w /src --entrypoint /bin/sh $(GO_IMAGE) -lc 'apk add --no-cache git >/dev/null && $(GO_BIN) test ./...' ; \
;; \
esac
# Clean up build artifacts
clean:
rm -f $(BINARY_NAME)
.PHONY: all build run fmt test clean server import tui