-
Notifications
You must be signed in to change notification settings - Fork 266
/
Makefile
79 lines (66 loc) · 2.39 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
ifdef ComSpec
SHELL := powershell.exe
else
SHELL := /bin/bash
endif
APP_NAME := teldrive
BUILD_DIR := bin
FRONTEND_DIR := ui/dist
FRONTEND_ASSET := https://github.com/tgdrive/teldrive-ui/releases/download/v1/teldrive-ui.zip
GIT_TAG := $(shell git describe --tags --abbrev=0)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_LINK := $(shell git remote get-url origin)
MODULE_PATH := $(shell go list -m)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
VERSION:= $(GIT_TAG)
BINARY_EXTENSION :=
.PHONY: all build run clean frontend backend run sync-ui retag patch-version minor-version
all: build
frontend:
@echo "Extract UI"
ifeq ($(OS),Windows_NT)
powershell -Command "Remove-Item -Path $(FRONTEND_DIR) -Recurse -Force"
powershell -Command "Invoke-WebRequest -Uri $(FRONTEND_ASSET) -OutFile teldrive-ui.zip"
powershell -Command "if (!(Test-Path -Path $(subst /,\\,$(FRONTEND_DIR)))) { New-Item -ItemType Directory -Force -Path $(subst /,\\,$(FRONTEND_DIR)) }"
powershell -Command "Expand-Archive -Path teldrive-ui.zip -DestinationPath $(FRONTEND_DIR) -Force"
powershell -Command "Remove-Item -Path teldrive-ui.zip -Force"
else
rm -rf $(FRONTEND_DIR)
curl -LO $(FRONTEND_ASSET) -o teldrive-ui.zip
mkdir -p $(FRONTEND_DIR)
unzip -d $(FRONTEND_DIR) teldrive-ui.zip
rm -rf teldrive-ui.zip
endif
ifeq ($(OS),Windows_NT)
BINARY_EXTENSION := .exe
endif
backend:
@echo "Building backend for $(GOOS)/$(GOARCH)..."
go build -trimpath -ldflags "-s -w -X $(MODULE_PATH)/internal/config.Version=$(VERSION) -extldflags=-static" -o $(BUILD_DIR)/$(APP_NAME)$(BINARY_EXTENSION)
build: frontend backend
@echo "Building complete."
run:
@echo "Running $(APP_NAME)..."
$(BUILD_DIR)/$(APP_NAME) run
clean:
@echo "Cleaning up..."
rm -rf $(BUILD_DIR)
cd $(FRONTEND_DIR) && rm -rf dist node_modules
deps:
@echo "Installing Go dependencies..."
go mod download
retag:
@echo "Retagging..."
git tag -d $(GIT_TAG)
git push --delete origin $(GIT_TAG)
git tag -a $(GIT_TAG) -m "Recreated tag $(GIT_TAG)"
git push origin $(GIT_TAG)
patch-version:
@echo "Patching version..."
git tag -a $(shell semver -i patch $(GIT_TAG)) -m "Release $(shell semver -i patch $(GIT_TAG))"
git push origin $(shell semver -i patch $(GIT_TAG))
minor-version:
@echo "Minoring version..."
git tag -a $(shell semver -i minor $(GIT_TAG)) -m "Release $(shell semver -i minor $(GIT_TAG))"
git push origin $(shell semver -i minor $(GIT_TAG))