SHELL=/usr/bin/env bash
date_dir_name = $(shell date +"%Y%m%d-%H%M%S")
dir_file_path=/disk
version=0.0.1
server_dir_path=/disk/huanmeng/
target_commitish=dev
backups_dir_path=/disk/Public/miaoyu/backups/${target_commitish}/${version}/
publish_dir_patg=/disk/Public/miaoyu/Public/${target_commitish}/${version}/
git_commit = ${version}-${target_commitish}-`git rev-parse --abbrev-ref HEAD | awk '{print $1}'`-`git rev-parse --short HEAD | awk '{print $1}'`
test:
	@echo $(date_dir_name)
	@echo $(dir_file)

# make public
# make public version=0.0.2 target_commitish=dev -f /disk/Public/miaoyu/makefile
public:
	cd HuanMengProject && git checkout ${target_commitish} && git pull && dotnet restore
	# 删除发布目录
	rm -rf  ${publish_dir_patg}
	mkdir -p ${backups_dir_path}
	mkdir -p ${publish_dir_patg}
	dotnet publish -c Release /p:InformationalVersion="$(git_commit)" -o "${publish_dir_patg}" "./HuanMengProject/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj"
	#删除配置文件
	rm -rf  ${publish_dir_patg}/appsettings.json
	rm -rf  ${publish_dir_patg}/appsettings.Development.json
	# 备份文件
	# 从服务器同步到本地,备份
	rsync -avz ubuntu@101.43.19.200:$(server_dir_path) $(backups_dir_path)
	# 从本地同步到服务器
	rsync -avz  --exclude='output' --exclude='NLog' $(publish_dir_patg) ubuntu@101.43.19.200:$(server_dir_path)
	# 重启服务
	ssh ubuntu@101.43.19.200 "sudo systemctl restart miaoyu"
	
	
	
