我有一个 C# 解决方案,其中包含使用 .Net 6 的单个项目和多个库。我正在使用常规提交(使用 husky 提交),并希望使用语义发布基于提交在 Github 上将最新构建部署为 ZIP 文件消息。
我为 C# 项目尝试的设置:
- 安装包
.
npm install semantic-release -D
npm install @semantic-release/changelog -D
npm install @semantic-release/npm -D
npm install @semantic-release/github -D
npm install @semantic-release/git -D
- 在根目录中创建一个.releaserc.json文件
.
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
[
"@semantic-release/github",
{
"assets": [
{
"path": "my-project.zip",
"label": "my-project-${nextRelease.gitTag}.zip",
"name": "my-project-${nextRelease.gitTag}.zip"
}
]
}
],
"@semantic-release/git"
]
}
- 在package.json文件中将密钥设置
version
为0.0.0-development
,将密钥设置private
为true
并添加存储库 url - 在工作流目录中创建一个release-on-push-on-main-branch.yml文件
.
name: Release on push on main branch
on:
push:
branches:
- main
jobs:
release-on-push-on-main-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 16.x
- name: Install Node dependencies
run: npm install
- name: Setup .Net
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
- name: Install .Net dependencies
run: dotnet restore ./SolutionDir
- name: Run build
run: dotnet build ./SolutionDir
- name: Run publish
run: dotnet publish ./SolutionDir
- name: Rename publish directory of MyProject to my-project and move it to root
run: mv ./SolutionDir/MyProject/bin/Debug/net6.0 ./my-project
- name: ZIP my-project directory
run: zip -r my-project.zip my-project
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release --branches main
它似乎有效,每当我推送到主分支时,它都会将最新版本的发行版(包含 DLL)部署到 Github 版本。
但是正如您所知,语义发布不会发布正确的包版本,因为它还不知道程序集版本。它从package.json文件中获取版本。
我想要达到的目标:
- 在解决方案中对库或应用程序进行更改时,它应该根据常规提交自动增加它们的程序集版本。但显然,如果该项目被修改。
- 运行发布过程时,semantic-release 应该发布项目
"name": "my-project-${assembly-version}.zip"
有什么我可以使用的吗?