teldrive/Makefile

78 lines
2.1 KiB
Makefile
Raw Normal View History

2024-02-09 00:16:34 +08:00
FRONTEND_DIR := ui/teldrive-ui
BUILD_DIR := bin
APP_NAME := teldrive
2023-09-08 18:37:11 +08:00
2024-03-20 01:14:00 +08:00
GIT_TAG := $(shell git describe --tags --abbrev=0)
2024-02-09 00:16:34 +08:00
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_LINK := $(shell git remote get-url origin)
ENV_FILE := $(FRONTEND_DIR)/.env
MODULE_PATH := $(shell go list -m)
2024-02-09 00:16:34 +08:00
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
2024-02-09 01:31:13 +08:00
.PHONY: all build run clean frontend backend run sync-ui tag-and-push retag dev-tag dev-retag
2024-02-09 00:16:34 +08:00
all: build
ifdef ComSpec
SHELL := powershell.exe
BINARY_EXTENSION:=.exe
else
SHELL := /bin/bash
BINARY_EXTENSION:=
endif
frontend: $(ENV_FILE)
@echo "Building frontend..."
cd $(FRONTEND_DIR) ; pnpm install ; pnpm build
$(ENV_FILE): Makefile
ifdef ComSpec
2024-03-20 01:14:00 +08:00
@echo 'VITE_VERSION_INFO={"version": "$(GIT_TAG)", "commit": "$(GIT_COMMIT)", "link": "$(GIT_LINK)"}' | Out-File -encoding utf8 $(ENV_FILE)
2024-02-09 00:16:34 +08:00
else
2024-03-20 01:14:00 +08:00
@echo 'VITE_VERSION_INFO={"version": "$(GIT_TAG)", "commit": "$(GIT_COMMIT)", "link": "$(GIT_LINK)"}' > $(ENV_FILE)
2024-02-09 00:16:34 +08:00
endif
backend:
@echo "Building backend for $(GOOS)/$(GOARCH)..."
2024-03-20 01:14:00 +08:00
go build -trimpath -ldflags "-s -w -X $(MODULE_PATH)/internal/config.Version=$(GIT_TAG) -extldflags=-static" -o $(BUILD_DIR)/$(APP_NAME)$(BINARY_EXTENSION)
2024-02-09 00:16:34 +08:00
build: frontend backend
@echo "Building complete."
run:
@echo "Running $(APP_NAME)..."
$(BUILD_DIR)/$(APP_NAME) run
2024-02-09 00:16:34 +08:00
clean:
@echo "Cleaning up..."
rm -rf $(BUILD_DIR)
cd $(FRONTEND_DIR) && rm -rf dist node_modules
deps:
@echo "Installing Go dependencies..."
go mod download
@echo "Installing frontend dependencies..."
cd $(FRONTEND_DIR) && pnpm install
2023-09-08 18:37:11 +08:00
2023-09-08 21:15:47 +08:00
sync-ui:
2023-09-23 12:28:33 +08:00
git submodule update --init --recursive --remote
2023-09-08 21:15:47 +08:00
2024-02-09 00:16:34 +08:00
retag:
@echo "Retagging..."
2024-03-20 01:14:00 +08:00
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)
2024-02-09 00:16:34 +08:00
patch-version:
@echo "Patching version..."
2024-03-20 01:14:00 +08:00
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))
2023-09-08 21:15:47 +08:00
2024-02-09 00:16:34 +08:00
minor-version:
@echo "Minoring version..."
2024-03-20 01:14:00 +08:00
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))