diff --git a/.github/conf/.goreleaser.yml b/.github/conf/.goreleaser.yml index 3babf90..99cff05 100644 --- a/.github/conf/.goreleaser.yml +++ b/.github/conf/.goreleaser.yml @@ -1,64 +1,148 @@ -before: - hooks: - - go mod tidy -builds: - - - id: default - env: - - CGO_ENABLED=0 - goos: - - windows - - linux - - darwin - - freebsd - - solaris - goarch: - - amd64 - - "386" - - arm - - arm64 -# - mips -# - mipsle -# - mips64 - goarm: - - "6" - - "7" - flags: - - -trimpath - ldflags: - - -s -w -upx: - - - ids: [ default ] - enabled: true - goos: ["windows", "linux"] - goarch: ["amd64", "386"] - compress: best -# lzma: true -# brute: true -archives: - - - format: binary - allow_different_binary_count: true - name_template: >- - {{- .ProjectName }} - {{- if eq .Os "darwin"}}_mac - {{- else if eq .Os "linux"}} - {{- else if eq .Os "windows"}} - {{- else }}_{{ .Os }}{{ end }} - {{- if eq .Arch "amd64" }} - {{- else if eq .Arch "386" }}32 - {{- else }}_{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end -}} -checksum: - name_template: 'checksums.txt' -snapshot: - name_template: "{{ incpatch .Version }}-next" -changelog: - sort: asc - filters: - exclude: - - '^docs:' - - '^test:' - - "^*.md" - - "^*.ya?ml" +name: 发布构建 + +on: + push: + tags: + - 'v*' + branches: + - dev # 添加 dev 分支支持 + pull_request: + branches: + - main + - master + workflow_dispatch: + inputs: + tag: + description: '发布标签' + required: false + default: 'v1.0.0' + test_mode: + description: '测试模式 (不会发布)' + type: boolean + default: false + +permissions: + contents: write + issues: write + pull-requests: write + +jobs: + goreleaser: + name: 构建和发布 + runs-on: ubuntu-latest + timeout-minutes: 60 + + steps: + - name: 📥 检出代码 + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: 🔍 判断运行模式 + id: mode + run: | + if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]]; then + echo "mode=release" >> $GITHUB_OUTPUT + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + elif [[ "${{ github.event.inputs.test_mode }}" == "true" ]]; then + echo "mode=test" >> $GITHUB_OUTPUT + echo "version=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT + else + echo "mode=snapshot" >> $GITHUB_OUTPUT + echo "version=dev-${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT + fi + + echo "owner=${GITHUB_REPOSITORY_OWNER}" >> $GITHUB_OUTPUT + echo "repo=${GITHUB_REPOSITORY#*/}" >> $GITHUB_OUTPUT + + - name: 🐹 设置 Go 环境 + uses: actions/setup-go@v5 + with: + go-version: '1.21' + cache: true + + - name: 📦 下载依赖 + run: | + go mod download + go mod verify + + - name: 🗜️ 安装 UPX 压缩工具 + uses: crazy-max/ghaction-upx@v3 + with: + install-only: true + + - name: ℹ️ 显示构建环境信息 + run: | + echo "Go 版本: $(go version)" + echo "UPX 版本: $(upx --version)" + echo "运行模式: ${{ steps.mode.outputs.mode }}" + echo "版本: ${{ steps.mode.outputs.version }}" + echo "仓库: ${{ steps.mode.outputs.owner }}/${{ steps.mode.outputs.repo }}" + + - name: 🧪 运行测试 + run: | + go test -v ./... + + - name: 🔍 验证 GoReleaser 配置 + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: check -f .github/conf/.goreleaser.yml + + - name: 🚀 正式发布 + if: steps.mode.outputs.mode == 'release' + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean -f .github/conf/.goreleaser.yml + workdir: . + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_OWNER: ${{ steps.mode.outputs.owner }} + GITHUB_REPO: ${{ steps.mode.outputs.repo }} + PROJECT_NAME: ${{ steps.mode.outputs.repo }} + + - name: 🧪 测试构建 (Snapshot 模式) + if: steps.mode.outputs.mode != 'release' + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --snapshot --clean -f .github/conf/.goreleaser.yml + workdir: . + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_OWNER: ${{ steps.mode.outputs.owner }} + GITHUB_REPO: ${{ steps.mode.outputs.repo }} + PROJECT_NAME: ${{ steps.mode.outputs.repo }} + + - name: 📋 上传构建产物 + uses: actions/upload-artifact@v4 + with: + name: | + ${{ steps.mode.outputs.mode == 'release' && '正式发布' || '测试构建' }}-${{ steps.mode.outputs.version }} + path: | + dist/ + retention-days: ${{ steps.mode.outputs.mode == 'release' && 90 || 7 }} + + - name: 📊 生成构建报告 + if: always() + run: | + mode_emoji="${{ steps.mode.outputs.mode == 'release' && '🎉' || '🧪' }}" + echo "## ${mode_emoji} 构建完成报告" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- **模式**: ${{ steps.mode.outputs.mode }}" >> $GITHUB_STEP_SUMMARY + echo "- **版本**: ${{ steps.mode.outputs.version }}" >> $GITHUB_STEP_SUMMARY + echo "- **仓库**: ${{ steps.mode.outputs.owner }}/${{ steps.mode.outputs.repo }}" >> $GITHUB_STEP_SUMMARY + echo "- **构建时间**: $(date)" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + if [ -d "dist" ]; then + echo "### 📦 生成的文件:" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + ls -la dist/ >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + fi \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ff83ef..fb026d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,43 +1,171 @@ -name: goreleaser +name: 发布构建 on: push: tags: - - '*' + - 'v*' # 只响应以 v 开头的标签,如 v1.0.0 + workflow_dispatch: # 支持手动触发 + inputs: + tag: + description: '发布标签' + required: true + default: 'v1.0.0' permissions: contents: write + issues: write + pull-requests: write jobs: goreleaser: + name: 构建和发布 runs-on: ubuntu-latest timeout-minutes: 60 - steps: - - name: "Check out code" - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: "Set up Go" - uses: actions/setup-go@v4 + steps: + - name: 📥 检出代码 + uses: actions/checkout@v4 with: - go-version: 1.20.14 - - - name: Install UPX + fetch-depth: 0 # 获取完整的 git 历史,用于生成变更日志 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: 🔍 获取项目信息 + id: project + run: | + echo "owner=${GITHUB_REPOSITORY_OWNER}" >> $GITHUB_OUTPUT + echo "repo=${GITHUB_REPOSITORY#*/}" >> $GITHUB_OUTPUT + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + + - name: 🐹 设置 Go 环境 + uses: actions/setup-go@v5 + with: + go-version: '1.21' # 使用更新的 Go 版本 + cache: true # 启用 Go 模块缓存 + + - name: 📦 下载依赖 + run: | + go mod download + go mod verify + + - name: 🗜️ 安装 UPX 压缩工具 uses: crazy-max/ghaction-upx@v3 with: install-only: true - - name: UPX version - run: upx --version + - name: ℹ️ 显示构建环境信息 + run: | + echo "Go 版本: $(go version)" + echo "UPX 版本: $(upx --version)" + echo "Git 标签: ${{ steps.project.outputs.version }}" + echo "仓库: ${{ steps.project.outputs.owner }}/${{ steps.project.outputs.repo }}" - - - name: "Create release on GitHub" - uses: goreleaser/goreleaser-action@v4 + - name: 🧪 运行测试 + run: | + go test -v ./... + + - name: 🔍 验证 GoReleaser 配置 + uses: goreleaser/goreleaser-action@v5 with: distribution: goreleaser version: latest - args: "release --clean -f .github/conf/.goreleaser.yml" + args: check -f .github/conf/.goreleaser.yml + + - name: 🚀 构建和发布 + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean -f .github/conf/.goreleaser.yml workdir: . env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_OWNER: ${{ steps.project.outputs.owner }} + GITHUB_REPO: ${{ steps.project.outputs.repo }} + PROJECT_NAME: ${{ steps.project.outputs.repo }} + + - name: 📋 上传构建产物 + uses: actions/upload-artifact@v4 + if: always() + with: + name: 构建产物-${{ steps.project.outputs.version }} + path: | + dist/ + !dist/*.txt + retention-days: 30 + + - name: 📊 生成构建报告 + if: always() + run: | + echo "## 🎉 构建完成报告" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- **版本**: ${{ steps.project.outputs.version }}" >> $GITHUB_STEP_SUMMARY + echo "- **仓库**: ${{ steps.project.outputs.owner }}/${{ steps.project.outputs.repo }}" >> $GITHUB_STEP_SUMMARY + echo "- **Go 版本**: $(go version | cut -d' ' -f3)" >> $GITHUB_STEP_SUMMARY + echo "- **构建时间**: $(date)" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + if [ -d "dist" ]; then + echo "### 📦 生成的文件:" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + ls -la dist/ >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + fi + + # 可选:发布到 Docker Hub + docker: + name: 构建 Docker 镜像 + runs-on: ubuntu-latest + needs: goreleaser + if: success() + + steps: + - name: 📥 检出代码 + uses: actions/checkout@v4 + + - name: 🔍 获取元数据 + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ github.repository }} + tags: | + type=ref,event=tag + type=raw,value=latest,enable={{is_default_branch}} + + - name: 🐳 设置 Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: 🔐 登录 Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: 🚀 构建并推送 Docker 镜像 + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + # 可选:通知步骤 + notify: + name: 发送通知 + runs-on: ubuntu-latest + needs: [goreleaser] + if: always() + + steps: + - name: 📧 发送成功通知 + if: needs.goreleaser.result == 'success' + run: | + echo "✅ 发布成功完成!" + echo "版本: ${GITHUB_REF#refs/tags/}" + echo "查看发布: https://github.com/${{ github.repository }}/releases" + + - name: ⚠️ 发送失败通知 + if: needs.goreleaser.result == 'failure' + run: | + echo "❌ 发布失败!" + echo "请检查构建日志: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ No newline at end of file diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml new file mode 100644 index 0000000..8c46d32 --- /dev/null +++ b/.github/workflows/test-build.yml @@ -0,0 +1,183 @@ +name: 测试构建 + +on: + push: + branches: + - dev + - develop + - feature/* + pull_request: + branches: + - main + - master + - dev + workflow_dispatch: + inputs: + branch: + description: '测试分支' + required: false + default: 'dev' + skip_tests: + description: '跳过测试' + type: boolean + default: false + +permissions: + contents: read + +jobs: + test-build: + name: 测试构建 + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - name: 📥 检出代码 + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.inputs.branch || github.ref }} + + - name: 🔍 获取项目信息 + id: project + run: | + echo "owner=${GITHUB_REPOSITORY_OWNER}" >> $GITHUB_OUTPUT + echo "repo=${GITHUB_REPOSITORY#*/}" >> $GITHUB_OUTPUT + echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT + echo "short_sha=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT + + - name: 🐹 设置 Go 环境 + uses: actions/setup-go@v5 + with: + go-version: '1.21' + cache: true + + - name: 📦 下载依赖 + run: | + go mod download + go mod verify + + - name: 🗜️ 安装 UPX 压缩工具 + uses: crazy-max/ghaction-upx@v3 + with: + install-only: true + + - name: ℹ️ 显示构建环境信息 + run: | + echo "Go 版本: $(go version)" + echo "UPX 版本: $(upx --version)" + echo "分支: ${{ steps.project.outputs.branch }}" + echo "提交: ${{ steps.project.outputs.short_sha }}" + echo "仓库: ${{ steps.project.outputs.owner }}/${{ steps.project.outputs.repo }}" + + - name: 🧪 运行测试 + if: ${{ !inputs.skip_tests }} + run: | + go test -v ./... + + - name: 🔍 验证 GoReleaser 配置 + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: check -f .github/conf/.goreleaser.yml + + - name: 🚀 测试构建 (Snapshot 模式) + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --snapshot --clean -f .github/conf/.goreleaser.yml + workdir: . + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_OWNER: ${{ steps.project.outputs.owner }} + GITHUB_REPO: ${{ steps.project.outputs.repo }} + PROJECT_NAME: ${{ steps.project.outputs.repo }} + + - name: 📋 上传测试产物 + uses: actions/upload-artifact@v4 + with: + name: 测试构建-${{ steps.project.outputs.branch }}-${{ steps.project.outputs.short_sha }} + path: | + dist/ + retention-days: 7 + + - name: 🧪 测试生成的二进制文件 + run: | + echo "## 🧪 测试二进制文件" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + for binary in dist/*linux*amd64*; do + if [[ -f "$binary" && -x "$binary" ]]; then + echo "测试文件: $binary" + file_info=$(file "$binary") + echo "- **文件信息**: $file_info" >> $GITHUB_STEP_SUMMARY + + # 测试运行 + if timeout 10s "$binary" --help > /dev/null 2>&1; then + echo "- **运行测试**: ✅ 通过" >> $GITHUB_STEP_SUMMARY + else + echo "- **运行测试**: ❌ 失败" >> $GITHUB_STEP_SUMMARY + fi + break + fi + done + + - name: 📊 生成测试报告 + if: always() + run: | + echo "## 🎯 测试构建报告" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- **分支**: ${{ steps.project.outputs.branch }}" >> $GITHUB_STEP_SUMMARY + echo "- **提交**: ${{ steps.project.outputs.short_sha }}" >> $GITHUB_STEP_SUMMARY + echo "- **构建时间**: $(date)" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + if [ -d "dist" ]; then + echo "### 📦 生成的文件:" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + ls -la dist/ | head -20 >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + + echo "### 📏 文件大小统计:" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + du -h dist/* | sort -h | tail -10 >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + fi + + # 可选:代码质量检查 + quality: + name: 代码质量检查 + runs-on: ubuntu-latest + + steps: + - name: 📥 检出代码 + uses: actions/checkout@v4 + + - name: 🐹 设置 Go 环境 + uses: actions/setup-go@v5 + with: + go-version: '1.21' + cache: true + + - name: 🔍 代码格式检查 + run: | + if [ "$(gofmt -l . | wc -l)" -gt 0 ]; then + echo "❌ 代码格式不符合标准" + gofmt -l . + exit 1 + fi + echo "✅ 代码格式检查通过" + + - name: 🧹 代码静态分析 + uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: --timeout=5m + + - name: 🔒 安全检查 + uses: securecodewarrior/github-action-add-sarif@v1 + with: + sarif-file: 'gosec.sarif' + continue-on-error: true \ No newline at end of file diff --git a/image/2.0-1 2.png b/image/2.0-1 2.png new file mode 100644 index 0000000..e5a3e7b Binary files /dev/null and b/image/2.0-1 2.png differ diff --git a/image/2.0-2 2.png b/image/2.0-2 2.png new file mode 100644 index 0000000..17c4d86 Binary files /dev/null and b/image/2.0-2 2.png differ diff --git a/image/5 2.png b/image/5 2.png new file mode 100644 index 0000000..41cbd34 Binary files /dev/null and b/image/5 2.png differ diff --git a/image/gpt-4o/4o-1 2.png b/image/gpt-4o/4o-1 2.png new file mode 100644 index 0000000..84c2932 Binary files /dev/null and b/image/gpt-4o/4o-1 2.png differ diff --git a/image/gpt-4o/4o-2 2.png b/image/gpt-4o/4o-2 2.png new file mode 100644 index 0000000..ceb672f Binary files /dev/null and b/image/gpt-4o/4o-2 2.png differ diff --git a/image/gpt-4o/4o-3 2.png b/image/gpt-4o/4o-3 2.png new file mode 100644 index 0000000..db2cf49 Binary files /dev/null and b/image/gpt-4o/4o-3 2.png differ diff --git a/image/gpt-4o/4o-4 2.png b/image/gpt-4o/4o-4 2.png new file mode 100644 index 0000000..5667099 Binary files /dev/null and b/image/gpt-4o/4o-4 2.png differ diff --git a/image/gpt-4o/4o-5 2.png b/image/gpt-4o/4o-5 2.png new file mode 100644 index 0000000..46dd8e3 Binary files /dev/null and b/image/gpt-4o/4o-5 2.png differ diff --git a/image/gpt-4o/4o-6 2.png b/image/gpt-4o/4o-6 2.png new file mode 100644 index 0000000..0186d10 Binary files /dev/null and b/image/gpt-4o/4o-6 2.png differ diff --git a/image/gpt-4o/4o-7 2.png b/image/gpt-4o/4o-7 2.png new file mode 100644 index 0000000..7dca69f Binary files /dev/null and b/image/gpt-4o/4o-7 2.png differ diff --git a/image/gpt-4o/4o-8 2.png b/image/gpt-4o/4o-8 2.png new file mode 100644 index 0000000..ac1b5e6 Binary files /dev/null and b/image/gpt-4o/4o-8 2.png differ diff --git a/image/gpt-4o/final 2.png b/image/gpt-4o/final 2.png new file mode 100644 index 0000000..259e4fa Binary files /dev/null and b/image/gpt-4o/final 2.png differ