在Debian上配置Go持续集成(CI)可参考以下步骤,以GitLab CI/CD为例:
安装Golang
sudo apt update && sudo apt install golang-go
设置环境变量(添加到~/.bashrc或~/.profile):
export GOROOT=/usr/lib/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
source ~/.bashrc
选择CI工具
以GitLab CI/CD为例,在项目根目录创建.gitlab-ci.yml文件。
配置CI流程
stages:
- build
- test
build:
stage: build
script:
- go build -o app .
test:
stage: test
script:
- go test -v ./...
golangci-lint):lint:
stage: test
script:
- golangci-lint run
docker-build:
stage: build
script:
- docker build -t my-app .
提交并触发CI
将配置文件提交到Git仓库,推送后CI工具会自动运行流程。
其他工具参考:
.github/workflows/go.yml,配置类似GitLab,使用actions/setup-go设置环境。根据项目需求可扩展部署、代码覆盖率等步骤,具体可参考工具官方文档。