dotnet语义版本控制和使用github动作发布
我有一个dotnet项目,并且正在尝试构建CI/CD管道,该管道使用GitHub操作进行以下操作:
- 在PR或主更改上构建项目。
- 测试项目对PR或主更改进行测试。
- 在主更改上,可以计算一个SEMVER(理想情况下,也是一个变形程序,但这并不重要)。
- 在主更改上,使用此SEMVER,构建Nuget软件包,然后将其发布到GitHub和Nuget。
到目前为止,我拥有建立和测试项目的工作流程。这似乎很好。但是,它也有一个发布步骤,似乎从未运行过(我想如果
是错误的(?)),我真的不确定从semver的semver部分从哪里开始想。
name: .NET Build, Test and Publish
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
env:
DISCOS_API_KEY: ${{ secrets.DISCOS_API_KEY }}
DISCOS_API_URL: http://localhost:3000/api/
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Build docker stack
run: docker-compose -f src/DISCOSweb-Sdk/DISCOSweb-Sdk.Tests/docker-compose.yml up -d --force-recreate --build
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore src/DISCOSweb-Sdk/DISCOSweb-Sdk.sln
- name: Build
run: dotnet build --no-restore src/DISCOSweb-Sdk/DISCOSweb-Sdk.sln
- name: Test
run: dotnet test --no-build --verbosity normal src/DISCOSweb-Sdk/DISCOSweb-Sdk.sln
publish: # This stage is never run
if: github.event.pull_request.merged == 'true'
needs: build
runs-on: ubuntu-latest
steps:
- name: Publish
id: publish_nuget
uses: brandedoutcast/publish-nuget@v2
with:
PACKAGE_NAME: DISCOSweb-Sdk
PROJECT_FILE_PATH: "**/DISCOSweb-Sdk.csproj"
BUILD_CONFIGURATION: Release
NUGET_KEY: ${{secrets.NUGET_KEY}}
VERSION_STATIC: 1.0.0 # Replace with something better
我觉得这应该是相对普遍且直接的事情,因此,任何帮助都将不胜感激。
I have a dotnet project and am trying to build a CI/CD pipeline that does the following using Github Actions:
- Builds the project on a PR or master change.
- Tests the project on a PR or master change.
- On a master change calculates a semver (ideally a changelog too but that's less important).
- On a master change uses this semver, builds a nuget package, and publishes it to GitHub and Nuget.
So far, I have this workflow that builds and tests my project. This seems to work nicely. However, it also has a publish step, which never seems to be run (I guess the if
is wrong(?)) and I'm really not sure where to start with the SemVer part of what I want.
name: .NET Build, Test and Publish
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
env:
DISCOS_API_KEY: ${{ secrets.DISCOS_API_KEY }}
DISCOS_API_URL: http://localhost:3000/api/
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Build docker stack
run: docker-compose -f src/DISCOSweb-Sdk/DISCOSweb-Sdk.Tests/docker-compose.yml up -d --force-recreate --build
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore src/DISCOSweb-Sdk/DISCOSweb-Sdk.sln
- name: Build
run: dotnet build --no-restore src/DISCOSweb-Sdk/DISCOSweb-Sdk.sln
- name: Test
run: dotnet test --no-build --verbosity normal src/DISCOSweb-Sdk/DISCOSweb-Sdk.sln
publish: # This stage is never run
if: github.event.pull_request.merged == 'true'
needs: build
runs-on: ubuntu-latest
steps:
- name: Publish
id: publish_nuget
uses: brandedoutcast/publish-nuget@v2
with:
PACKAGE_NAME: DISCOSweb-Sdk
PROJECT_FILE_PATH: "**/DISCOSweb-Sdk.csproj"
BUILD_CONFIGURATION: Release
NUGET_KEY: ${{secrets.NUGET_KEY}}
VERSION_STATIC: 1.0.0 # Replace with something better
I feel like this should be a relatively common and straightforward thing to do so any assistance would be really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法通过分配CI和CD工作流程并利用一些非常有用的软件包来实现这一目标。
CI工作流程
第一个工作流程在PR上运行,并推向掌握。值得注意的是,当分支保护开启时,推动掌握是合并PR的代名词。
CD工作流
CD工作流还有更多。它运行到主机上,但仅当对包含SDK的实际源代码的文件夹进行更改(这就是
paths
Block所做的)。然后,我使用
mathieudutour/ >用计算的语义版本(使用常规提交计算)来标记提交。
然后,使用
-p:packageversion = $ {{steps.tag_version.outputs.new_version}}
选项dotnet nuget pack
在此版本上标记软件包构建。ncipollo/Release-Action@v1
还在GitHub上创建了一个版本。最后,像往常一样,使用
dotnet nuget push
将发行版构建并将其推送到github和nuget。I managed to accomplish this by splitting my CI and CD workflows, and making use of some very helpful packages.
CI Workflow
This first workflow runs on PRs and pushes to master. It's worth noting that when branch protection is on, a push to master is synonymous with a merged PR.
CD Workflow
There's a bit more to the CD workflow. It runs on pushes to master but only when there are changes made to the folder containing the actual source code for the SDK (that's what the
paths
block does).I then used the
mathieudutour/[email protected]
action to tag the commit with a calculated semantic version (calculated using conventional commits).The package build is then tagged with this version using the
-p:PackageVersion=${{ steps.tag_version.outputs.new_version }}
option ondotnet nuget pack
.The
ncipollo/release-action@v1
also creates a release on Github.Finally, building and pushing the release to Github and Nuget is done using
dotnet nuget push
as usual.