ci: add cross-platform release workflow with version injection
Build linux/darwin amd64 and arm64 artifacts on push, upload GitHub Release assets on v* tags, and expose version via agent-notify version. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ["v*"]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
GO_VERSION: "1.22.2"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
cache: true
|
||||
|
||||
- name: Test
|
||||
run: go test ./...
|
||||
|
||||
build:
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- goos: linux
|
||||
goarch: amd64
|
||||
- goos: linux
|
||||
goarch: arm64
|
||||
- goos: darwin
|
||||
goarch: amd64
|
||||
- goos: darwin
|
||||
goarch: arm64
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
cache: true
|
||||
|
||||
- name: Resolve version
|
||||
id: meta
|
||||
shell: bash
|
||||
run: |
|
||||
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
|
||||
VERSION="${GITHUB_REF#refs/tags/}"
|
||||
else
|
||||
VERSION="dev-$(git rev-parse --short HEAD)"
|
||||
fi
|
||||
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
||||
echo "Version: ${VERSION}"
|
||||
|
||||
- name: Build binary
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
VERSION: ${{ steps.meta.outputs.version }}
|
||||
run: |
|
||||
mkdir -p dist
|
||||
OUT="dist/agent-notify-${VERSION}_${GOOS}_${GOARCH}"
|
||||
CGO_ENABLED=0 go build -trimpath \
|
||||
-ldflags "-s -w \
|
||||
-X main.version=${VERSION} \
|
||||
-X main.commit=${GITHUB_SHA} \
|
||||
-X main.buildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||
-o "${OUT}" ./cmd/agent-notify
|
||||
chmod +x "${OUT}"
|
||||
sha256sum "${OUT}" > "${OUT}.sha256"
|
||||
tar -czf "${OUT}.tar.gz" -C dist "$(basename "${OUT}")" "$(basename "${OUT}").sha256"
|
||||
rm "${OUT}" "${OUT}.sha256"
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: agent-notify-${{ steps.meta.outputs.version }}-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: dist/agent-notify-${{ steps.meta.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
|
||||
if-no-files-found: error
|
||||
|
||||
release:
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: agent-notify-*
|
||||
merge-multiple: true
|
||||
path: dist
|
||||
|
||||
- name: Create GitHub Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: dist/*.tar.gz
|
||||
generate_release_notes: true
|
||||
@@ -1,2 +1,3 @@
|
||||
/bin/
|
||||
/dist/
|
||||
/.config/
|
||||
|
||||
@@ -1,11 +1,28 @@
|
||||
.PHONY: build test install
|
||||
.PHONY: build test install cross
|
||||
BINARY := agent-notify
|
||||
VERSION ?= dev
|
||||
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
|
||||
BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
LDFLAGS := -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildDate=$(BUILD_DATE)
|
||||
|
||||
build:
|
||||
go build -o bin/$(BINARY) ./cmd/agent-notify
|
||||
go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY) ./cmd/agent-notify
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
|
||||
install: build
|
||||
install -m 755 bin/$(BINARY) $(HOME)/.local/bin/$(BINARY)
|
||||
|
||||
cross:
|
||||
@mkdir -p dist
|
||||
@for target in \
|
||||
"linux amd64" \
|
||||
"linux arm64" \
|
||||
"darwin amd64" \
|
||||
"darwin arm64"; do \
|
||||
set -- $$target; \
|
||||
out=dist/$(BINARY)-$(VERSION)_$$1_$$2; \
|
||||
echo "building $$out"; \
|
||||
GOOS=$$1 GOARCH=$$2 CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o "$$out" ./cmd/agent-notify; \
|
||||
done
|
||||
|
||||
@@ -98,4 +98,20 @@ agent-notify test claude --apply
|
||||
```bash
|
||||
make test
|
||||
make build
|
||||
make cross VERSION=v0.1.0 # 本地交叉编译
|
||||
agent-notify version
|
||||
```
|
||||
|
||||
## CI / Release
|
||||
|
||||
推送 `main` 分支或 `v*` tag 时,GitHub Actions 会构建并上传以下产物:
|
||||
|
||||
- `agent-notify-<version>_linux_amd64.tar.gz`
|
||||
- `agent-notify-<version>_linux_arm64.tar.gz`
|
||||
- `agent-notify-<version>_darwin_amd64.tar.gz`
|
||||
- `agent-notify-<version>_darwin_arm64.tar.gz`
|
||||
|
||||
- **tag 发布**(如 `v0.1.0`):版本号为 tag 名,并自动创建 GitHub Release
|
||||
- **main 分支**:版本号为 `dev-<git-sha>`
|
||||
|
||||
每个压缩包内含二进制和 `.sha256` 校验文件。
|
||||
|
||||
@@ -39,6 +39,8 @@ func run(cmd string, args []string) error {
|
||||
return cmdDoctor()
|
||||
case "logs":
|
||||
return cmdLogs(args)
|
||||
case "version", "-V":
|
||||
return cmdVersion()
|
||||
case "help", "-h", "--help":
|
||||
printUsage()
|
||||
return nil
|
||||
@@ -200,6 +202,7 @@ Commands:
|
||||
test cursor [--try-all]
|
||||
test claude [--apply]
|
||||
logs [--tail 30]
|
||||
version
|
||||
doctor
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var (
|
||||
version = "dev"
|
||||
commit = "none"
|
||||
buildDate = "unknown"
|
||||
)
|
||||
|
||||
func cmdVersion() error {
|
||||
fmt.Printf("agent-notify %s\n", version)
|
||||
fmt.Printf("commit: %s\n", commit)
|
||||
fmt.Printf("built: %s\n", buildDate)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user