Skip to content

Commit ae05157

Browse files
committed
feat: 添加 GitHub Actions 工作流以发布 NuGet 包,并更新项目文件以支持符号包和源链接
1 parent 8ed5714 commit ae05157

File tree

2 files changed

+83
-4
lines changed

2 files changed

+83
-4
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish NuGet Package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
- '*.*.*'
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: '版本号 (例如: 1.0.0)'
12+
required: true
13+
type: string
14+
15+
jobs:
16+
publish:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Set version
24+
id: set_version
25+
run: |
26+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
27+
# 手动触发时使用输入的版本号
28+
VERSION="${{ github.event.inputs.version }}"
29+
echo "Using manual version: $VERSION"
30+
else
31+
# 标签触发时从标签提取版本号
32+
REF_NAME="${{ github.ref_name }}"
33+
echo "Tag name: $REF_NAME"
34+
35+
if [[ "$REF_NAME" == v* ]]; then
36+
VERSION=${REF_NAME#v}
37+
else
38+
VERSION=$REF_NAME
39+
fi
40+
echo "Extracted version from tag: $VERSION"
41+
fi
42+
43+
echo "version=$VERSION" >> $GITHUB_OUTPUT
44+
echo "Final version: $VERSION"
45+
46+
- name: Setup .NET
47+
uses: actions/setup-dotnet@v4
48+
with:
49+
dotnet-version: |
50+
8.0.x
51+
9.0.x
52+
10.0.x
53+
54+
- name: Restore dependencies
55+
run: dotnet restore
56+
57+
- name: Build
58+
run: dotnet build --configuration Release --no-restore
59+
60+
- name: Test
61+
run: dotnet test --configuration Release --no-build --verbosity normal
62+
63+
- name: Pack
64+
run: dotnet pack --configuration Release --no-build --output ./artifacts -p:PackageVersion=${{ github.event.inputs.version }}
65+
66+
- name: Publish to NuGet
67+
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET }} --source https://api.nuget.org/v3/index.json --skip-duplicate

src/Toon.NET/Toon.NET.csproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,35 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<LangVersion>latest</LangVersion>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
9-
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
109

1110
<!-- NuGet 元数据 -->
1211
<PackageId>Toon.NET</PackageId>
13-
<Version>0.1.0</Version>
14-
<Authors>Toon.NET Contributors</Authors>
12+
<Title>Toon.NET</Title>
1513
<Description>Token-Oriented Object Notation (TOON) - a token-efficient JSON alternative for LLM prompts, .NET implementation with System.Text.Json-style API.</Description>
1614
<PackageProjectUrl>https://token-ai.cn</PackageProjectUrl>
1715
<RepositoryUrl>https://github.com/AIDotNet/Toon.NET</RepositoryUrl>
16+
<RepositoryType>git</RepositoryType>
1817
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1918
<PackageReadmeFile>README.md</PackageReadmeFile>
20-
<IncludeSymbols>false</IncludeSymbols>
19+
<PackageTags>TOON;JSON;Serialization;System.Text.Json;LLM;Prompt;Encoding;CSharp;DotNet</PackageTags>
20+
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
21+
22+
<!-- 打包与可复现构建 -->
23+
<IncludeSymbols>true</IncludeSymbols>
24+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
25+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
26+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
27+
<Deterministic>true</Deterministic>
2128
</PropertyGroup>
2229

2330
<ItemGroup>
2431
<!-- 将 README 打包进入 NuGet,并作为包级 Readme 显示 -->
2532
<None Include="README.md" Pack="true" PackagePath="\" />
2633
</ItemGroup>
2734

35+
<!-- SourceLink 支持 -->
36+
<ItemGroup>
37+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
38+
</ItemGroup>
39+
2840
</Project>

0 commit comments

Comments
 (0)