Skip to content

Commit 60706c5

Browse files
committed
feat(build): 更新Makefile以支持动态获取Git标签并优化打包流程
- 使用`git describe`命令动态获取最新的Git标签 - 在构建和打包过程中确保`dist`目录存在 - 优化打包逻辑,使用`case`语句处理不同文件类型 - 在CI流程中添加上传构建产物的步骤
1 parent 89f1b4f commit 60706c5

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ jobs:
7777
- name: Package binaries
7878
run: make package-binaries
7979

80+
- name: Upload Binaries
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: binaries
84+
path: |
85+
dist/*.tar.gz
86+
dist/*.zip
87+
8088
- name: Create GitHub Release
8189
uses: ncipollo/release-action@v1
8290
with:

Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
IMAGE_NAME = gitlens-patch
33
DIST_DIR = dist
44
PLATFORMS = linux/amd64 linux/arm64 windows/amd64 windows/arm64
5-
TAG ?= dev
6-
5+
GIT_TAG=$(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
6+
TAG ?= $(GIT_TAG)
77
.PHONY: test test-all build-local build-binaries package-binaries clean lint code-format
88

99
# 单元测试
@@ -27,6 +27,7 @@ build-local:
2727
# 多平台构建
2828
build-binaries:
2929
@echo "Building binaries for platforms: $(PLATFORMS)"
30+
@mkdir -p $(DIST_DIR)
3031
for platform in $(PLATFORMS); do \
3132
GOOS=$$(echo $$platform | cut -d/ -f1); \
3233
GOARCH=$$(echo $$platform | cut -d/ -f2); \
@@ -39,14 +40,17 @@ build-binaries:
3940
# 打包产物
4041
package-binaries:
4142
@echo "Packaging binaries into tar.gz/zip archives"
42-
for file in $(DIST_DIR)/$(IMAGE_NAME)-*; do \
43-
if [[ $$file == *.exe ]]; then \
44-
zip -j $(DIST_DIR)/$$(basename $$file)-$(TAG).zip $$file; \
45-
else \
46-
tar -czvf $(DIST_DIR)/$$(basename $$file)-$(TAG).tar.gz -C $(DIST_DIR) $$(basename $$file); \
47-
fi; \
43+
@mkdir -p $(DIST_DIR)
44+
@for file in $(DIST_DIR)/$(IMAGE_NAME)-*; do \
45+
case "$$file" in \
46+
*.exe) \
47+
zip -j $(DIST_DIR)/$$(basename $$file)-$(TAG).zip $$file ;; \
48+
*) \
49+
tar -czvf $(DIST_DIR)/$$(basename $$file)-$(TAG).tar.gz -C $(DIST_DIR) $$(basename $$file) ;; \
50+
esac; \
4851
done
4952

53+
5054
# Lint 检查
5155
.PHONY: lint
5256

0 commit comments

Comments
 (0)