使用Go Release Binaries Action构建Go项目并发布时失败求助
排查Go Release Binaries Action构建失败问题
可能的问题点及修复方案
1. 显式指定兼容的Go版本
默认情况下,wangyoucao577/go-release-action使用的Go版本可能和你的项目go.mod中声明的版本不兼容,这会导致构建失败。你可以在Action配置中明确指定Go版本:
- name: Build and release uses: wangyoucao577/go-release-action@v1.34 with: # 其他参数保持不变 go_version: "1.21" # 替换为你的go.mod中定义的Go版本
2. 验证目录结构与模块文件
添加步骤确认代码checkout后的目录结构是否符合预期,避免路径错误:
- name: Verify directory structure run: | ls -la ./api cat ./api/go.mod
这一步能帮你确认./api目录下确实存在main.go、go.mod和go.sum,且模块声明正确。
3. 显式指定构建命令
虽然你的main.go在project_path根目录,但显式声明构建命令可以避免Action默认逻辑的潜在问题:
- name: Build and release uses: wangyoucao577/go-release-action@v1.34 with: # 其他参数保持不变 build_command: go build -o {{.BinaryName}} main.go
4. 检查GITHUB_TOKEN权限
默认的GITHUB_TOKEN需要有读写仓库的权限才能创建Release:
- 进入你的仓库设置页面
- 导航到
Actions > General - 在
Workflow permissions区域,选择Read and write permissions并保存
5. 优化标签触发规则
将标签匹配规则从*改为v*,避免非版本标签误触发Action:
on: push: tags: - "v*"
修复后的完整配置示例
name: Release API binary on: push: tags: - "v*" jobs: build: name: GO API build runs-on: ubuntu-latest strategy: matrix: goos: [linux] goarch: [amd64, arm64] steps: - name: Check out code uses: actions/checkout@v3 - name: Verify directory structure run: | ls -la ./api cat ./api/go.mod - name: Build and release uses: wangyoucao577/go-release-action@v1.34 with: github_token: ${{ secrets.GITHUB_TOKEN }} goos: ${{ matrix.goos }} goarch: ${{ matrix.goarch }} go_version: "1.21" # 替换为你的项目Go版本 project_path: "./api" binary_name: "flying-server" build_command: go build -o {{.BinaryName}} main.go
额外检查点
- 确认
git push origin v0.0.13已成功执行,仓库的Tags页面能看到该版本标签 - 如果项目依赖私有模块,需要额外配置
GOPRIVATE环境变量及对应的访问凭证
内容的提问来源于stack exchange,提问作者Armin Azhdehnia
相关产品推荐
相关产品推荐

