79 lines
1.8 KiB
YAML
79 lines
1.8 KiB
YAML
stages:
|
|
- build
|
|
- deploy
|
|
- push
|
|
|
|
variables:
|
|
ProjectPath: "mongo.games.com/game"
|
|
DeployPath: "mongo.games.com/deploy"
|
|
|
|
default:
|
|
tags:
|
|
- gitlab
|
|
|
|
build-job:
|
|
stage: build
|
|
script:
|
|
- git checkout $CI_COMMIT_REF_NAME
|
|
# 拷贝到GOPATH
|
|
- echo '拷贝到GOPATH'
|
|
- cp -rfp ./* $GOPATH/src/$ProjectPath
|
|
# 进入项目目录
|
|
- cd $GOPATH/src/$ProjectPath
|
|
# 编译
|
|
- echo '编译'
|
|
- go env -w GO111MODULE=off
|
|
- |
|
|
while IFS= read -r line
|
|
do
|
|
cd $line
|
|
echo "编译 $line"
|
|
go build -v
|
|
cd ..
|
|
done < shell/programs.txt
|
|
|
|
deploy-job:
|
|
stage: deploy
|
|
script:
|
|
# 拉取
|
|
- echo "拉取deploy"
|
|
- cd $GOPATH/src/$DeployPath
|
|
- git checkout $CI_COMMIT_REF_NAME
|
|
- git pull
|
|
|
|
# 拷贝data目录
|
|
- echo '拷贝data目录'
|
|
- cd $GOPATH/src/$ProjectPath
|
|
- cp -rfvp data/* $GOPATH/src/$DeployPath/data
|
|
|
|
# 删除自定义配置
|
|
- echo '删除自定义配置'
|
|
- |
|
|
while IFS= read -r line
|
|
do
|
|
echo "删除 $line 配置"
|
|
rm $GOPATH/src/$DeployPath/data/$line
|
|
done < shell/exclude.txt
|
|
|
|
# 拷贝可执行程序
|
|
- echo '拷贝可执行程序'
|
|
- |
|
|
while IFS= read -r line
|
|
do
|
|
echo "拷贝 $line"
|
|
cp -rf $line/$line $GOPATH/src/$DeployPath/
|
|
echo "删除 $line"
|
|
rm -rf $line/$line
|
|
done < shell/programs.txt
|
|
|
|
push_job:
|
|
stage: push
|
|
script:
|
|
# 提交代码
|
|
- echo '提交代码'
|
|
- cd $GOPATH/src/$DeployPath
|
|
- git config user.email "ci@example.com" # 设置提交者的 email
|
|
- git config user.name "GitLab CI" # 设置提交者的名称
|
|
- git add .
|
|
- git commit -m "auto commit pipelineId $CI_PIPELINE_ID"
|
|
- git push origin $CI_COMMIT_REF_NAME |