今天我们来讲的主要是如果对前端项目进行规范,主要是结合GitLab的CI/CD和semantic-release工具来进行自动进行
一,首先看一下git常用的大体目录,你看下自己在项目中用到了哪些呢?还是简单的仓库存储吗?

二,给项目安装runner

三,下载安装成功之后,注册启动即可,命令如下:
gitlab-runner install 安装
gitlab-runner register 注册
gitlab-runner start 启动
gitlab-runner stop 停止如果遇到install错误,打开config文件,将shell的值修改成powershell
如果报错 FATAL:Failed to install gitlab-runner:service gitlab-runner already exists
则:gitlab-runner uninstall 再 gitlab-runner install
注意此处的gitlab-runner是你下载的exe文件
四,接下来,git仓库会看到一个runner

五,项目中配置.gitlab-ci.yml和.releaserc文件(根目录下建立)
.gitlab-ci.yml
# The release pipeline will run only on the master branch a commit is triggered
stages:
- release
release:
stage: release
image: node:lts
script:
- npm run publishs
- export GITLAB_URL=${CI_PROJECT_URL%/$CI_PROJECT_PATH}
- export GITLAB_PREFIX=${CI_API_V4_URL#$GITLAB_URL}
- export GITLAB_TOKEN=${GITLAB_TOKEN}
- export GL_TOKEN=${GL_TOKEN}
- sudo GL_TOKEN=${GL_TOKEN} CI_API_V4_URL=${CI_API_V4_URL} GITLAB_URL=${GITLAB_URL} CI_PROJECT_PATH=${GITLAB_URL} npx semantic-release --no-ci --debug
dependencies: []
# 仅在中央仓库的分支发生提交时才触发 release 流程
only:
- master
# 指定注册的runner名称
tags:
- docker.releaserc
主要是引用配置semantic-release全家桶的相关插件,这里就需要你的node环境提前进行安装了。点击这里查看github官方的代码库
{
"branches": [
"master"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/git",
{
"assets": [
"package.json",
"CHANGELOG.md"
],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
}一定要注意,GL_TOKEN的配置

ps:
我这个的publishs里面是上传npm版本命令
--no-ci . 本地打包上传
--dry-run 调试模式,仅输出日志但不更改
六,触发与使用
在commit提交时需要规范行为即可出发runner
# 初始版本1.0.0
git commit -m 'feat: 提交了一个需求版本'
// V1.1.0
git commit -m 'fix: 提交了一个bug修复'
//V1.1.1
git commit -m 'perf(add): 提交了一个技术优化 '
//V1.1.1然后push仓库就能看到,runner任务正在执行,随后就有对应的changelog文件的生成,和gittag自动打的标签了


问题:
1.
error: insufficient permission for adding an object to repository database .git/objects
fatal: failed to write object
fatal: unpack-objects failed
ERROR: Job failed: exit status 1
# 打开项目.git目录,修改所属组为你当前用户所在组,修改所有文件写权限 cd /path/to/repo.git sudo chgrp -R groupname . sudo chmod -R g+rwX .
2.
✖ Failed step "publish" of plugin "@semantic-release/gitlab"
[10:56:31 AM] [semantic-release] › ✖ An error occurred while running semantic-release: HTTPError: Response code 400 (Bad Request)
https:///semantic-release/gitlab/issues/239
api中缺少name属性,我已经在改github中已经提交了一个issues,并在内网环境上进行修复
本文我们主要讲述了一个如何结合git的ci/cd来做自动化的job,下一文,我们具体讲述一下npm如何制定规范与自动化发布,包含(alpha、beta等环境)gitlab结合semantic-release自动化发布npm插件(二)
















