Add Makefile
This commit is contained in:
		
							parent
							
								
									25272afe15
								
							
						
					
					
						commit
						308fe5666b
					
				
							
								
								
									
										53
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,53 @@ | |||||||
|  | PROJECT_NAME := minitmpl | ||||||
|  | VERSION := $(shell cat VERSION) | ||||||
|  | BUILD_DIR := build | ||||||
|  | DIST_DIR := dist | ||||||
|  | LDFLAGS := "-w -s" | ||||||
|  | 
 | ||||||
|  | build: | ||||||
|  | 	@echo "Building for this platform ..." | ||||||
|  | 	@mkdir -p $(BUILD_DIR) | ||||||
|  | 	@CGO_ENABLED=0 go build -ldflags=$(LDFLAGS) -o $(BUILD_DIR)/$(PROJECT_NAME) main.go | ||||||
|  | 	@echo "Build complete!" | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | .PHONY: release | ||||||
|  | release: | ||||||
|  | 	# Check if the git working directory is clean | ||||||
|  | 	@if [ -n "$$(git status --porcelain)" ]; then \
 | ||||||
|  | 		echo "Error: The working directory is not clean. Please commit or stash your changes."; \
 | ||||||
|  | 		exit 1; \
 | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	VVERSION=v$(VERSION) | ||||||
|  | 
 | ||||||
|  | 	# Check if the version tag already exists and does not point to HEAD | ||||||
|  | 	@if git rev-parse $$VVERSION >/dev/null 2>&1; then \
 | ||||||
|  | 		if ! git describe --tags --exact-match HEAD >/dev/null 2>&1; then \
 | ||||||
|  | 			echo "Error: Version $$VVERSION is already tagged on a different commit."; \
 | ||||||
|  | 			exit 1; \
 | ||||||
|  | 		fi; \
 | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	# Tag the latest commit with the version from VERSION file if not already tagged | ||||||
|  | 	@if ! git describe --tags --exact-match HEAD >/dev/null 2>&1; then \
 | ||||||
|  | 		echo "Latest commit not tagged. Tagging with version from VERSION file..."; \
 | ||||||
|  | 		git tag -a $$VVERSION -m "Release $$VVERSION"; \
 | ||||||
|  | 		git push origin $$VVERSION; \
 | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	# Set GITEA_TOKEN variable and run goreleaser | ||||||
|  | 	@$(eval GITEA_TOKEN=$(shell pass www/behzadan.ir/git/reza/tokens/dt06-goreleaser)) | ||||||
|  | 	@goreleaser release | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | .PHONY: run | ||||||
|  | run: | ||||||
|  | 	go run main.go $(filter-out $@,$(MAKECMDGOALS)) | ||||||
|  | %: | ||||||
|  | 	@: | ||||||
|  | 
 | ||||||
|  | clean: | ||||||
|  | 	@echo "Cleaning up..." | ||||||
|  | 	@rm -rf ${BUILD_DIR} | ||||||
|  | 	@rm -rf ${DIST_DIR} | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user