Files
wangairnan ad4a87fc9f
Release / release (push) Failing after 8s
feat(ci): 基于 v* 标签的多架构自动发版
- 新增 .gitea/workflows/release.yml:推送 v* 标签触发,构建前端嵌入后
  交叉编译 linux/darwin(amd64+arm64),生成变更日志并创建 Gitea Release
- 新增 scripts/build-release.sh:make dist 与 CI 共用的产物构建脚本,
  tar.gz 打包 + SHA256SUMS;不含 windows(internal/store 依赖 Unix Umask)
- Makefile 增加 dist 目标;版本注入沿用 git describe + ldflags(pn version)
2026-09-09 22:46:12 +08:00

53 lines
1.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 发布产物构建:交叉编译全部目标平台 → dist/,打包并生成 SHA256SUMS。
# 本地 `make dist` 与 Gitea Actions 发版工作流共用本脚本,保证产物一致。
#
# 用法: scripts/build-release.sh [版本号]
# 版本号缺省取 `git describe --tags --always`(无 tag 时回退 dev)。
# 前置条件:internal/webui/dist 已就绪(make web sync-assets)。
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
VERSION="${1:-$(git describe --tags --always 2>/dev/null || echo dev)}"
COMMIT="$(git rev-parse --short HEAD 2>/dev/null || echo none)"
DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
LDFLAGS="-s -w -X main.version=$VERSION -X main.commit=$COMMIT -X main.buildDate=$DATE"
# 纯静态(CGO_ENABLED=0,见 Makefile),单机即可交叉编译全部目标。
# 不含 windows:internal/store 对 syscall.Umask 等 Unix API 有硬依赖(备份权限加固)。
TARGETS=(
linux/amd64
linux/arm64
darwin/amd64
darwin/arm64
)
rm -rf dist
mkdir -p dist
for t in "${TARGETS[@]}"; do
os="${t%/*}" arch="${t#*/}"
name="pn-${VERSION}-${os}-${arch}"
echo "==> 构建 $name"
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" \
go build -trimpath -ldflags="$LDFLAGS" -o "dist/$name" ./cmd/pn
# tar.gz 保留可执行位
(cd dist && tar czf "$name.tar.gz" "$name" && rm "$name")
done
# 生成校验和(Linux 为 sha256sum,macOS 回退 shasum)
echo "==> 生成 SHA256SUMS"
(
cd dist
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -- ./* > SHA256SUMS
else
shasum -a 256 -- ./* > SHA256SUMS
fi
)
echo "==> 完成:dist/"
ls -lh dist/