From 3f673cbd7e20af7b851ac8fd816f0ec0274f99a7 Mon Sep 17 00:00:00 2001 From: Shen Junzheng Date: Tue, 25 Mar 2025 10:04:08 +0800 Subject: [PATCH] x --- .github/workflows/release.yml | 17 +++---- .gitignore | 3 +- .goreleaser.yaml | 90 +++++++++++++++++++++++++++++++++++ Makefile | 4 +- README.md | 2 +- 5 files changed, 101 insertions(+), 15 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 39c7589..c79e08d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,11 +12,14 @@ jobs: release: name: Release Binary runs-on: ubuntu-latest + container: + image: goreleaser/goreleaser-cross:v1.24 steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 + - run: git config --global --add safe.directory "$(pwd)" - name: Setup Go uses: actions/setup-go@v4 @@ -36,16 +39,8 @@ jobs: with: install-only: true - - name: Build Package - run: | - ./script/package.sh - - - name: Release - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') + - name: Run GoReleaser + run: goreleaser release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - files: packages/* - draft: true - prerelease: true + ENABLE_UPX: true diff --git a/.gitignore b/.gitignore index d4b8f7e..be910bc 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ go.work.sum .stfolder chatlog -chatlog.exe \ No newline at end of file +chatlog.exe# Added by goreleaser init: +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..8388526 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,90 @@ +# GoReleaser v2 配置 +version: 2 + +before: + hooks: + - go mod tidy + +builds: + - id: darwin-amd64 + binary: chatlog + env: + - CGO_ENABLED=1 + - CC=o64-clang + - CXX=o64-clang++ + goos: + - darwin + goarch: + - amd64 + ldflags: + - -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}} + + - id: darwin-arm64 + binary: chatlog + env: + - CGO_ENABLED=1 + - CC=oa64-clang + - CXX=oa64-clang++ + goos: + - darwin + goarch: + - arm64 + ldflags: + - -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}} + + - id: windows-amd64 + binary: chatlog + env: + - CGO_ENABLED=1 + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 + ldflags: + - -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}} + + - id: windows-arm64 + binary: chatlog + env: + - CGO_ENABLED=1 + - CC=/llvm-mingw/bin/aarch64-w64-mingw32-gcc + - CXX=/llvm-mingw/bin/aarch64-w64-mingw32-g++ + goos: + - windows + goarch: + - arm64 + ldflags: + - -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}} + +archives: + - id: default + format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{- .Version }}_ + {{- .Os }}_ + {{- .Arch }} + format_overrides: + - goos: windows + format: zip + files: + - LICENSE + - README.md + +upx: + - enabled: "{{ .Env.ENABLE_UPX }}" + goos: [darwin, windows] + goarch: [amd64] + compress: best + +checksum: + name_template: 'checksums.txt' + algorithm: sha256 + +# 配置 GitHub Release +release: + draft: true + prerelease: auto + mode: replace diff --git a/Makefile b/Makefile index e4da6e1..a5051c7 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ test: build: @echo "🔨 Building for current platform..." - $(GO) build -trimpath $(LDFLAGS) -o bin/$(BINARY_NAME) main.go + CGO_ENABLED=1 $(GO) build -trimpath $(LDFLAGS) -o bin/$(BINARY_NAME) main.go crossbuild: clean @echo "🌍 Building for multiple platforms..." @@ -50,7 +50,7 @@ crossbuild: clean [ "$$float" != "" ] && output_name=$$output_name_$$float; \ echo "🔨 Building for $$os/$$arch..."; \ echo "🔨 Building for $$output_name..."; \ - GOOS=$$os GOARCH=$$arch GOARM=$$float $(GO) build -trimpath $(LDFLAGS) -o $$output_name main.go ; \ + GOOS=$$os GOARCH=$$arch CGO_ENABLED=1 GOARM=$$float $(GO) build -trimpath $(LDFLAGS) -o $$output_name main.go ; \ if [ "$(ENABLE_UPX)" = "1" ] && echo "$(UPX_PLATFORMS)" | grep -q "$$os/$$arch"; then \ echo "⚙️ Compressing binary $$output_name..." && upx --best $$output_name; \ fi; \ diff --git a/README.md b/README.md index d8ad118..2bc3f26 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ go install github.com/sjzar/chatlog@latest 3. 下载 `chatlog` 预编译版本或从源码安装,推荐使用 go 进行安装。 -4. 运行 `chatlog`,按照提示进行操作,解密数据后开启 HTTP 服务后,即可通过浏览器或 AI 助手访问聊天记录。 +4. 运行 `chatlog`,按照提示进行操作,解密数据并开启 HTTP 服务后,即可通过浏览器或 AI 助手访问聊天记录。 ### macOS 版本提示