XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.XUnit

【DLL】提供方便快捷的测试,无需编写Main方法,可直接添加特性在类或方法上进行测试

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension.NetCore.XUnit

升级至 .NET 10.0 并引入自动化发布与验证流程

本次提交将目标框架升级为 .NET 10.0,NuGet 包版本提升至 3.0.0,并完善了发布说明。新增 PUBLISHING.md,详细说明自动化发布流程。引入 publish-packages.yml 和 validate.yml,分别实现包发布自动化及主分支/PR 的持续集成验证。

a9844e3
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

4 个文件 +221 -5
Added .github/PUBLISHING.md +45 -0
@@ -0,0 +1,45 @@
1 # Publishing Packages
2
3 This repository now includes two GitHub Actions workflows:
4
5 - `Validate`: runs on `push` and `pull_request` to ensure the solution restores and builds cleanly.
6 - `Publish Packages`: runs when you push a tag that starts with `v`, for example `v3.0.9`, or when you trigger it manually from the Actions page.
7
8 ## Required secrets
9
10 Add this repository secret before publishing to NuGet.org:
11
12 - `NUGET_API_KEY`: API key from NuGet.org with push permission for `XFEExtension.NetCore.XUnit`
13
14 No extra secret is required for GitHub Packages. The workflow uses the built-in `GITHUB_TOKEN` and requests `packages: write`.
15
16 The same built-in `GITHUB_TOKEN` is also used to create the GitHub Release and upload package assets.
17
18 ## Recommended release flow
19
20 1. Update the project and verify CI is green.
21 2. Push a version tag such as `v3.0.9`.
22 3. GitHub Actions will automatically do all of the following:
23 - build and pack the project
24 - upload the generated `.nupkg` as a workflow artifact
25 - publish the package to NuGet.org
26 - publish the package to GitHub Packages at `https://nuget.pkg.github.com/XFEstudio/index.json`
27 - create a GitHub Release for that tag
28 - attach the generated `.nupkg` files to the GitHub Release
29
30 ## Tag-triggered release behavior
31
32 When you push a new tag like `v3.0.9`, that single action is the release trigger for the entire pipeline. You do not need to manually start the workflow afterward.
33
34 The release workflow is tied to `push.tags: v*`, so each new version tag automatically runs the full publishing flow.
35
36 ## Manual publish
37
38 If you need to republish packages from the GitHub Actions UI:
39
40 1. Open `Publish Packages`.
41 2. Click `Run workflow`.
42 3. Fill in the `version` input.
43 4. Optionally set `skip_nuget_org` to `true` when you only want GitHub Packages.
44
45 Manual runs publish packages, but GitHub Release creation is only performed for real tag pushes so the release stays aligned with the repository tag history.
Added .github/workflows/publish-packages.yml +138 -0
@@ -0,0 +1,138 @@
1 name: Publish Packages
2
3 on:
4 push:
5 tags:
6 - "v*"
7 workflow_dispatch:
8 inputs:
9 version:
10 description: Package version to publish, for example 1.0.0
11 required: true
12 type: string
13 skip_nuget_org:
14 description: Skip publishing to NuGet.org
15 required: false
16 default: false
17 type: boolean
18
19 permissions:
20 contents: write
21 packages: write
22
23 env:
24 DOTNET_VERSION: 10.0.x
25 SOLUTION_PATH: XFEExtension.NetCore.XUnit.slnx
26 PROJECT_PATH: XFEExtension.NetCore.XUnit/XFEExtension.NetCore.XUnit.csproj
27 PACKAGE_OUTPUT_DIR: ${{ github.workspace }}/artifacts/packages
28
29 jobs:
30 publish:
31 runs-on: windows-latest
32
33 steps:
34 - name: Checkout
35 uses: actions/checkout@v4
36 with:
37 fetch-depth: 0
38
39 - name: Setup .NET
40 uses: actions/setup-dotnet@v4
41 with:
42 dotnet-version: ${{ env.DOTNET_VERSION }}
43
44 - name: Resolve version
45 id: version
46 shell: bash
47 run: |
48 if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
49 version="${{ inputs.version }}"
50 else
51 version="${GITHUB_REF_NAME#v}"
52 fi
53
54 if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?([-.][0-9A-Za-z.-]+)?$ ]]; then
55 echo "Invalid package version: $version"
56 exit 1
57 fi
58
59 echo "value=$version" >> "$GITHUB_OUTPUT"
60 echo "PACKAGE_VERSION=$version" >> "$GITHUB_ENV"
61
62 - name: Restore
63 run: dotnet restore ${{ env.PROJECT_PATH }}
64
65 - name: Build
66 run: dotnet build ${{ env.PROJECT_PATH }} --configuration Release --no-restore -p:GeneratePackageOnBuild=false -p:ContinuousIntegrationBuild=true -p:Version=${{ env.PACKAGE_VERSION }} -p:PackageVersion=${{ env.PACKAGE_VERSION }}
67
68 - name: Pack
69 run: dotnet pack ${{ env.PROJECT_PATH }} --configuration Release --no-build --no-restore --output ${{ env.PACKAGE_OUTPUT_DIR }} -p:GeneratePackageOnBuild=false -p:ContinuousIntegrationBuild=true -p:Version=${{ env.PACKAGE_VERSION }} -p:PackageVersion=${{ env.PACKAGE_VERSION }}
70
71 - name: Upload package artifacts
72 uses: actions/upload-artifact@v4
73 with:
74 name: packages-${{ env.PACKAGE_VERSION }}
75 path: ${{ env.PACKAGE_OUTPUT_DIR }}/*.nupkg
76 if-no-files-found: error
77
78 - name: Publish to GitHub Packages
79 shell: pwsh
80 run: |
81 $packages = Get-ChildItem -Path "${{ env.PACKAGE_OUTPUT_DIR }}" -Filter *.nupkg -File
82 if (-not $packages) {
83 throw "No .nupkg files found in ${{ env.PACKAGE_OUTPUT_DIR }}"
84 }
85
86 foreach ($package in $packages) {
87 dotnet nuget push $package.FullName --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --api-key "${{ secrets.GITHUB_TOKEN }}" --skip-duplicate
88 }
89
90 - name: Publish to NuGet.org
91 if: ${{ github.event_name != 'workflow_dispatch' || !inputs.skip_nuget_org }}
92 shell: pwsh
93 run: |
94 $packages = Get-ChildItem -Path "${{ env.PACKAGE_OUTPUT_DIR }}" -Filter *.nupkg -File
95 if (-not $packages) {
96 throw "No .nupkg files found in ${{ env.PACKAGE_OUTPUT_DIR }}"
97 }
98
99 foreach ($package in $packages) {
100 dotnet nuget push $package.FullName --source "https://api.nuget.org/v3/index.json" --api-key "${{ secrets.NUGET_API_KEY }}" --skip-duplicate
101 }
102
103 - name: Create GitHub Release
104 if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
105 uses: softprops/action-gh-release@v2
106 with:
107 tag_name: ${{ github.ref_name }}
108 name: XFEExtension.NetCore.XUnit ${{ github.ref_name }}
109 generate_release_notes: true
110 append_body: true
111 body: |
112 ## Package feeds
113
114 - NuGet.org
115 - GitHub Packages: `https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json`
116 files: ${{ env.PACKAGE_OUTPUT_DIR }}/*.nupkg
117 fail_on_unmatched_files: true
118 prerelease: ${{ contains(env.PACKAGE_VERSION, '-') }}
119
120 - name: Publish summary
121 shell: bash
122 run: |
123 {
124 echo "## Published packages"
125 echo ""
126 echo "- Version: \`${PACKAGE_VERSION}\`"
127 echo "- GitHub Packages: published"
128 if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.skip_nuget_org }}" == "true" ]]; then
129 echo "- NuGet.org: skipped"
130 else
131 echo "- NuGet.org: published"
132 fi
133 if [[ "${{ github.event_name }}" == "push" && "${GITHUB_REF_NAME}" == v* ]]; then
134 echo "- GitHub Release: created"
135 else
136 echo "- GitHub Release: skipped"
137 fi
138 } >> "$GITHUB_STEP_SUMMARY"
Added .github/workflows/validate.yml +35 -0
@@ -0,0 +1,35 @@
1 name: Validate
2
3 on:
4 push:
5 branches:
6 - master
7 - main
8 pull_request:
9
10 permissions:
11 contents: read
12
13 env:
14 DOTNET_VERSION: 10.0.x
15 SOLUTION_PATH: XFEExtension.NetCore.XUnit.slnx
16 PROJECT_PATH: XFEExtension.NetCore.XUnit/XFEExtension.NetCore.XUnit.csproj
17
18 jobs:
19 build:
20 runs-on: windows-latest
21
22 steps:
23 - name: Checkout
24 uses: actions/checkout@v4
25
26 - name: Setup .NET
27 uses: actions/setup-dotnet@v4
28 with:
29 dotnet-version: ${{ env.DOTNET_VERSION }}
30
31 - name: Restore
32 run: dotnet restore ${{ env.PROJECT_PATH }}
33
34 - name: Build
35 run: dotnet build ${{ env.PROJECT_PATH }} --configuration Release --no-restore -p:GeneratePackageOnBuild=false -p:ContinuousIntegrationBuild=true
Modified XFEExtension.NetCore.XUnit/XFEExtension.NetCore.XUnit.csproj +3 -5
@@ -1,7 +1,7 @@
1 1 <Project Sdk="Microsoft.NET.Sdk">
2 2
3 3 <PropertyGroup>
4 <TargetFramework>net8.0</TargetFramework>
4 <TargetFramework>net10.0</TargetFramework>
5 5 <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
6 6 <Title>XUnit</Title>
7 7 <Authors>XFEstudio</Authors>
@@ -13,13 +13,11 @@
13 13 <PackageReadmeFile>README.md</PackageReadmeFile>
14 14 <RepositoryUrl>https://github.com/XFEstudio/XFEExtension.NetCore.XUnit</RepositoryUrl>
15 15 <PackageTags>XFE;Test;XUnit;Unit</PackageTags>
16 <Version>2.1.1</Version>
16 <Version>3.0.0</Version>
17 17 <PackageLicenseFile>LICENSE</PackageLicenseFile>
18 18 <PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
19 19 <PackageReleaseNotes>
20 修复全局 using 拼写错误并升级版本至 2.1.1
21
22 修正了全局 using 语句中的命名空间拼写错误,避免因中文逗号导致的命名空间解析问题。同时将 NuGet 包版本号从 2.1.0 升级至 2.1.1。
20 版本更新至.NET 10.0,更新MD文档
23 21 </PackageReleaseNotes>
24 22 </PropertyGroup>
25 23